1
1
/**
2
2
* WordPress dependencies
3
3
*/
4
- import {
5
- createNewPost ,
6
- getEditedPostContent ,
7
- pressKeyWithModifier ,
8
- activatePlugin ,
9
- deactivatePlugin ,
10
- } from '@wordpress/e2e-test-utils' ;
4
+ const { test, expect } = require ( '@wordpress/e2e-test-utils-playwright' ) ;
11
5
12
6
// Avoid using three, as it looks too much like two with some fonts.
13
7
const ARABIC_ZERO = '٠' ;
14
8
const ARABIC_ONE = '١' ;
15
9
const ARABIC_TWO = '٢' ;
16
10
17
- describe ( 'RTL' , ( ) => {
18
- beforeAll ( async ( ) => {
19
- await activatePlugin ( 'gutenberg-test-plugin-activate-rtl' ) ;
11
+ test . describe ( 'RTL' , ( ) => {
12
+ test . beforeAll ( async ( { requestUtils } ) => {
13
+ await requestUtils . activatePlugin (
14
+ 'gutenberg-test-plugin-activate-rtl'
15
+ ) ;
20
16
} ) ;
21
17
22
- beforeEach ( async ( ) => {
23
- await createNewPost ( ) ;
18
+ test . beforeEach ( async ( { admin } ) => {
19
+ await admin . createNewPost ( ) ;
24
20
} ) ;
25
21
26
- afterAll ( async ( ) => {
27
- await deactivatePlugin ( 'gutenberg-test-plugin-activate-rtl' ) ;
22
+ test . afterAll ( async ( { requestUtils } ) => {
23
+ await requestUtils . deactivatePlugin (
24
+ 'gutenberg-test-plugin-activate-rtl'
25
+ ) ;
28
26
} ) ;
29
27
30
- it ( 'should arrow navigate' , async ( ) => {
28
+ test ( 'should arrow navigate' , async ( { editor , page } ) => {
31
29
await page . keyboard . press ( 'Enter' ) ;
32
30
33
31
// We need at least three characters as arrow navigation *from* the
@@ -41,21 +39,38 @@ describe( 'RTL', () => {
41
39
42
40
// Expect: ARABIC_ZERO + ARABIC_ONE + ARABIC_TWO (<p>٠١٢</p>).
43
41
// N.b.: HTML is LTR, so direction will be reversed!
44
- expect ( await getEditedPostContent ( ) ) . toMatchSnapshot ( ) ;
42
+
43
+ // Check the content.
44
+ const content = await editor . getEditedPostContent ( ) ;
45
+ expect ( content ) . toBe (
46
+ `<!-- wp:paragraph -->
47
+ <p>٠١٢</p>
48
+ <!-- /wp:paragraph -->`
49
+ ) ;
45
50
} ) ;
46
51
47
- it ( 'should split' , async ( ) => {
52
+ test ( 'should split' , async ( { editor , page } ) => {
48
53
await page . keyboard . press ( 'Enter' ) ;
49
54
50
55
await page . keyboard . type ( ARABIC_ZERO ) ;
51
56
await page . keyboard . type ( ARABIC_ONE ) ;
52
57
await page . keyboard . press ( 'ArrowRight' ) ;
53
58
await page . keyboard . press ( 'Enter' ) ;
54
59
55
- expect ( await getEditedPostContent ( ) ) . toMatchSnapshot ( ) ;
60
+ // Check the content.
61
+ const content = await editor . getEditedPostContent ( ) ;
62
+ expect ( content ) . toBe (
63
+ `<!-- wp:paragraph -->
64
+ <p>٠</p>
65
+ <!-- /wp:paragraph -->
66
+
67
+ <!-- wp:paragraph -->
68
+ <p>١</p>
69
+ <!-- /wp:paragraph -->`
70
+ ) ;
56
71
} ) ;
57
72
58
- it ( 'should merge backward' , async ( ) => {
73
+ test ( 'should merge backward' , async ( { editor , page } ) => {
59
74
await page . keyboard . press ( 'Enter' ) ;
60
75
61
76
await page . keyboard . type ( ARABIC_ZERO ) ;
@@ -64,10 +79,16 @@ describe( 'RTL', () => {
64
79
await page . keyboard . press ( 'ArrowRight' ) ;
65
80
await page . keyboard . press ( 'Backspace' ) ;
66
81
67
- expect ( await getEditedPostContent ( ) ) . toMatchSnapshot ( ) ;
82
+ // Check the content.
83
+ const content = await editor . getEditedPostContent ( ) ;
84
+ expect ( content ) . toBe (
85
+ `<!-- wp:paragraph -->
86
+ <p>٠١</p>
87
+ <!-- /wp:paragraph -->`
88
+ ) ;
68
89
} ) ;
69
90
70
- it ( 'should merge forward' , async ( ) => {
91
+ test ( 'should merge forward' , async ( { editor , page } ) => {
71
92
await page . keyboard . press ( 'Enter' ) ;
72
93
73
94
await page . keyboard . type ( ARABIC_ZERO ) ;
@@ -77,51 +98,70 @@ describe( 'RTL', () => {
77
98
await page . keyboard . press ( 'ArrowRight' ) ;
78
99
await page . keyboard . press ( 'Delete' ) ;
79
100
80
- expect ( await getEditedPostContent ( ) ) . toMatchSnapshot ( ) ;
101
+ // Check the content.
102
+ const content = await editor . getEditedPostContent ( ) ;
103
+ expect ( content ) . toBe (
104
+ `<!-- wp:paragraph -->
105
+ <p>٠١</p>
106
+ <!-- /wp:paragraph -->`
107
+ ) ;
81
108
} ) ;
82
109
83
- it ( 'should arrow navigate between blocks' , async ( ) => {
110
+ test ( 'should arrow navigate between blocks' , async ( {
111
+ editor,
112
+ page,
113
+ } ) => {
84
114
await page . keyboard . press ( 'Enter' ) ;
85
115
86
116
await page . keyboard . type ( ARABIC_ZERO ) ;
87
117
await page . keyboard . press ( 'Enter' ) ;
88
118
await page . keyboard . type ( ARABIC_ONE ) ;
89
- await pressKeyWithModifier ( 'shift' , ' Enter' ) ;
119
+ await page . keyboard . press ( 'Shift+ Enter' ) ;
90
120
await page . keyboard . type ( ARABIC_TWO ) ;
91
121
await page . keyboard . press ( 'ArrowRight' ) ;
92
122
await page . keyboard . press ( 'ArrowRight' ) ;
93
123
await page . keyboard . press ( 'ArrowRight' ) ;
94
124
95
125
// Move to the previous block with two lines in the current block.
96
126
await page . keyboard . press ( 'ArrowRight' ) ;
97
- await pressKeyWithModifier ( 'shift' , ' Enter' ) ;
127
+ await page . keyboard . press ( 'Shift+ Enter' ) ;
98
128
await page . keyboard . type ( ARABIC_ONE ) ;
99
129
100
130
// Move to the next block with two lines in the current block.
101
131
await page . keyboard . press ( 'ArrowLeft' ) ;
102
132
await page . keyboard . type ( ARABIC_ZERO ) ;
103
- await pressKeyWithModifier ( 'shift' , 'Enter' ) ;
104
-
105
- expect ( await getEditedPostContent ( ) ) . toMatchSnapshot ( ) ;
133
+ await page . keyboard . press ( 'Shift+Enter' ) ;
134
+
135
+ // Check the content.
136
+ const content = await editor . getEditedPostContent ( ) ;
137
+ expect ( content ) . toBe (
138
+ `<!-- wp:paragraph -->
139
+ <p>٠<br>١</p>
140
+ <!-- /wp:paragraph -->
141
+
142
+ <!-- wp:paragraph -->
143
+ <p>٠<br>١<br>٢</p>
144
+ <!-- /wp:paragraph -->`
145
+ ) ;
106
146
} ) ;
107
147
108
- it ( 'should navigate inline boundaries' , async ( ) => {
109
- await page . keyboard . press ( 'Enter' ) ;
110
-
111
- // Wait for rich text editor to load.
112
- await page . waitForSelector ( '.block-editor-rich-text__editable' ) ;
113
-
114
- await pressKeyWithModifier ( 'primary' , 'b' ) ;
148
+ test ( 'should navigate inline boundaries' , async ( {
149
+ editor ,
150
+ page ,
151
+ pageUtils ,
152
+ } ) => {
153
+ await page . click ( 'role=button[name="Add default block"i]' ) ;
154
+ await pageUtils . pressKeyWithModifier ( 'primary' , 'b' ) ;
115
155
await page . keyboard . type ( ARABIC_ONE ) ;
116
- await pressKeyWithModifier ( 'primary' , 'b' ) ;
156
+ await pageUtils . pressKeyWithModifier ( 'primary' , 'b' ) ;
117
157
await page . keyboard . type ( ARABIC_TWO ) ;
118
158
119
159
// Insert a character at each boundary position.
120
160
for ( let i = 4 ; i > 0 ; i -- ) {
121
161
await page . keyboard . press ( 'ArrowRight' ) ;
122
162
await page . keyboard . type ( ARABIC_ZERO ) ;
123
163
124
- expect ( await getEditedPostContent ( ) ) . toMatchSnapshot ( ) ;
164
+ expect ( await editor . getEditedPostContent ( ) ) . toMatchSnapshot ( ) ;
125
165
126
166
await page . keyboard . press ( 'Backspace' ) ;
127
167
}
0 commit comments