forked from WordPress/gutenberg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
quote.spec.js
352 lines (325 loc) · 10.1 KB
/
quote.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
/**
* WordPress dependencies
*/
const { test, expect } = require( '@wordpress/e2e-test-utils-playwright' );
test.describe( 'Quote', () => {
test.beforeEach( async ( { admin } ) => {
await admin.createNewPost();
} );
test.afterEach( async ( { requestUtils } ) => {
await requestUtils.deleteAllPosts();
} );
test( 'should allow the user to type right away', async ( {
editor,
page,
} ) => {
await editor.insertBlock( { name: 'core/quote' } );
// Type content right after.
await page.keyboard.type( 'Quote content' );
expect( await editor.getEditedPostContent() ).toBe(
`<!-- wp:quote -->
<blockquote class="wp-block-quote"><!-- wp:paragraph -->
<p>Quote content</p>
<!-- /wp:paragraph --></blockquote>
<!-- /wp:quote -->`
);
} );
test( 'can be created by using > at the start of a paragraph block', async ( {
editor,
page,
} ) => {
// Create a block with some text that will trigger a paragraph creation.
await editor.canvas
.locator( 'role=button[name="Add default block"i]' )
.click();
await page.keyboard.type( '> A quote' );
// Create a second paragraph.
await page.keyboard.press( 'Enter' );
await page.keyboard.type( 'Another paragraph' );
expect( await editor.getEditedPostContent() ).toBe(
`<!-- wp:quote -->
<blockquote class="wp-block-quote"><!-- wp:paragraph -->
<p>A quote</p>
<!-- /wp:paragraph -->
<!-- wp:paragraph -->
<p>Another paragraph</p>
<!-- /wp:paragraph --></blockquote>
<!-- /wp:quote -->`
);
} );
test( 'can be created by typing > in front of text of a paragraph block', async ( {
editor,
page,
pageUtils,
} ) => {
await editor.canvas
.locator( 'role=button[name="Add default block"i]' )
.click();
await page.keyboard.type( 'test' );
await pageUtils.pressKeys( 'ArrowLeft', { times: 'test'.length } );
await page.keyboard.type( '> ' );
expect( await editor.getEditedPostContent() ).toBe(
`<!-- wp:quote -->
<blockquote class="wp-block-quote"><!-- wp:paragraph -->
<p>test</p>
<!-- /wp:paragraph --></blockquote>
<!-- /wp:quote -->`
);
} );
test( 'can be created by typing "/quote"', async ( { editor, page } ) => {
// Create a list with the slash block shortcut.
await editor.canvas
.locator( 'role=button[name="Add default block"i]' )
.click();
await page.keyboard.type( '/quote' );
await page.keyboard.press( 'Enter' );
await page.keyboard.type( 'I’m a quote' );
expect( await editor.getEditedPostContent() ).toBe(
`<!-- wp:quote -->
<blockquote class="wp-block-quote"><!-- wp:paragraph -->
<p>I’m a quote</p>
<!-- /wp:paragraph --></blockquote>
<!-- /wp:quote -->`
);
} );
test( 'can be created by converting a paragraph', async ( {
editor,
page,
} ) => {
await editor.canvas
.locator( 'role=button[name="Add default block"i]' )
.click();
await page.keyboard.type( 'test' );
await editor.transformBlockTo( 'core/quote' );
expect( await editor.getEditedPostContent() ).toBe(
`<!-- wp:quote -->
<blockquote class="wp-block-quote"><!-- wp:paragraph -->
<p>test</p>
<!-- /wp:paragraph --></blockquote>
<!-- /wp:quote -->`
);
} );
test( 'can be created by converting multiple paragraphs', async ( {
editor,
page,
} ) => {
await editor.canvas
.locator( 'role=button[name="Add default block"i]' )
.click();
await page.keyboard.type( 'one' );
await page.keyboard.press( 'Enter' );
await page.keyboard.type( 'two' );
await page.keyboard.down( 'Shift' );
await editor.canvas
.locator( 'role=document[name="Block: Paragraph"i] >> text=one' )
.click();
await page.keyboard.up( 'Shift' );
await editor.transformBlockTo( 'core/quote' );
expect( await editor.getEditedPostContent() ).toBe(
`<!-- wp:quote -->
<blockquote class="wp-block-quote"><!-- wp:paragraph -->
<p>one</p>
<!-- /wp:paragraph -->
<!-- wp:paragraph -->
<p>two</p>
<!-- /wp:paragraph --></blockquote>
<!-- /wp:quote -->`
);
} );
test.describe( 'can be converted to paragraphs', () => {
test( 'and renders one paragraph block per <p> within quote', async ( {
editor,
page,
} ) => {
await editor.insertBlock( { name: 'core/quote' } );
await page.keyboard.type( 'one' );
await page.keyboard.press( 'Enter' );
await page.keyboard.type( 'two' );
await editor.clickBlockToolbarButton(
'Select parent block: Quote'
);
await editor.clickBlockOptionsMenuItem( 'Ungroup' );
expect( await editor.getEditedPostContent() ).toBe(
`<!-- wp:paragraph -->
<p>one</p>
<!-- /wp:paragraph -->
<!-- wp:paragraph -->
<p>two</p>
<!-- /wp:paragraph -->`
);
} );
test( 'and renders a paragraph for the cite, if it exists', async ( {
editor,
page,
} ) => {
await editor.insertBlock( { name: 'core/quote' } );
await page.keyboard.type( 'one' );
await page.keyboard.press( 'Enter' );
await page.keyboard.type( 'two' );
await editor.clickBlockToolbarButton(
'Select parent block: Quote'
);
await editor.clickBlockToolbarButton( 'Add citation' );
await page.keyboard.type( 'cite' );
await editor.clickBlockOptionsMenuItem( 'Ungroup' );
expect( await editor.getEditedPostContent() ).toBe(
`<!-- wp:paragraph -->
<p>one</p>
<!-- /wp:paragraph -->
<!-- wp:paragraph -->
<p>two</p>
<!-- /wp:paragraph -->
<!-- wp:paragraph -->
<p>cite</p>
<!-- /wp:paragraph -->`
);
} );
test( 'and renders only one paragraph for the cite, if the quote is void', async ( {
editor,
page,
} ) => {
await editor.insertBlock( { name: 'core/quote' } );
await page.keyboard.press( 'ArrowUp' );
await editor.clickBlockToolbarButton( 'Add citation' );
await page.keyboard.type( 'cite' );
await editor.clickBlockOptionsMenuItem( 'Ungroup' );
expect( await editor.getEditedPostContent() ).toBe(
`<!-- wp:paragraph -->
<p></p>
<!-- /wp:paragraph -->
<!-- wp:paragraph -->
<p>cite</p>
<!-- /wp:paragraph -->`
);
} );
test( 'and renders a void paragraph if both the cite and quote are void', async ( {
editor,
page,
} ) => {
await editor.insertBlock( { name: 'core/quote' } );
// Select the quote
await page.keyboard.press( 'ArrowUp' );
await editor.clickBlockOptionsMenuItem( 'Ungroup' );
expect( await editor.getEditedPostContent() ).toBe( '' );
} );
} );
test( 'can be created by converting a heading', async ( {
editor,
page,
} ) => {
await editor.insertBlock( { name: 'core/heading' } );
await page.keyboard.type( 'test' );
await editor.transformBlockTo( 'core/quote' );
expect( await editor.getEditedPostContent() ).toBe(
`<!-- wp:quote -->
<blockquote class="wp-block-quote"><!-- wp:heading -->
<h2 class="wp-block-heading">test</h2>
<!-- /wp:heading --></blockquote>
<!-- /wp:quote -->`
);
} );
test( 'can be converted to a pullquote', async ( { editor, page } ) => {
await editor.insertBlock( { name: 'core/quote' } );
await page.keyboard.type( 'one' );
await page.keyboard.press( 'Enter' );
await page.keyboard.type( 'two' );
await editor.clickBlockToolbarButton( 'Select parent block: Quote' );
await editor.clickBlockToolbarButton( 'Add citation' );
await page.keyboard.type( 'cite' );
await editor.transformBlockTo( 'core/pullquote' );
expect( await editor.getEditedPostContent() ).toBe(
`<!-- wp:pullquote -->
<figure class="wp-block-pullquote"><blockquote><p>one<br>two</p><cite>cite</cite></blockquote></figure>
<!-- /wp:pullquote -->`
);
} );
test( 'can be split at the end', async ( { editor, page } ) => {
await editor.insertBlock( { name: 'core/quote' } );
await page.keyboard.type( '1' );
await page.keyboard.press( 'Enter' );
await page.keyboard.press( 'Enter' );
// Expect empty paragraph outside quote block.
expect( await editor.getEditedPostContent() ).toBe(
`<!-- wp:quote -->
<blockquote class="wp-block-quote"><!-- wp:paragraph -->
<p>1</p>
<!-- /wp:paragraph --></blockquote>
<!-- /wp:quote -->
<!-- wp:paragraph -->
<p></p>
<!-- /wp:paragraph -->`
);
await page.keyboard.press( 'Backspace' );
await page.keyboard.type( '2' );
// Expect the paragraph to be merged into the quote block.
expect( await editor.getEditedPostContent() ).toBe(
`<!-- wp:quote -->
<blockquote class="wp-block-quote"><!-- wp:paragraph -->
<p>1</p>
<!-- /wp:paragraph -->
<!-- wp:paragraph -->
<p>2</p>
<!-- /wp:paragraph --></blockquote>
<!-- /wp:quote -->`
);
} );
test( 'can be unwrapped on Backspace', async ( { editor, page } ) => {
await editor.insertBlock( { name: 'core/quote' } );
expect( await editor.getEditedPostContent() ).toBe(
`<!-- wp:quote -->
<blockquote class="wp-block-quote"><!-- wp:paragraph -->
<p></p>
<!-- /wp:paragraph --></blockquote>
<!-- /wp:quote -->`
);
await page.keyboard.press( 'Backspace' );
expect( await editor.getEditedPostContent() ).toBe( '' );
} );
test( 'can be unwrapped with content on Backspace', async ( {
editor,
page,
pageUtils,
} ) => {
await editor.insertBlock( { name: 'core/quote' } );
await page.keyboard.type( '1' );
await page.keyboard.press( 'ArrowUp' );
await editor.clickBlockToolbarButton( 'Add citation' );
await page.keyboard.type( '2' );
expect( await editor.getEditedPostContent() ).toBe(
`<!-- wp:quote -->
<blockquote class="wp-block-quote"><!-- wp:paragraph -->
<p>1</p>
<!-- /wp:paragraph --><cite>2</cite></blockquote>
<!-- /wp:quote -->`
);
// Move the cursor to the start of the first paragraph of the quoted block.
await pageUtils.pressKeys( 'ArrowLeft', { times: 3 } );
await page.keyboard.press( 'Backspace' );
expect( await editor.getEditedPostContent() ).toBe(
`<!-- wp:paragraph -->
<p>1</p>
<!-- /wp:paragraph -->
<!-- wp:quote -->
<blockquote class="wp-block-quote"><cite>2</cite></blockquote>
<!-- /wp:quote -->`
);
} );
test( `shouldn't crash selecting content + cite and pressing backspace.`, async ( {
editor,
page,
pageUtils,
} ) => {
await editor.insertBlock( { name: 'core/quote' } );
await page.keyboard.type( '1' );
await page.keyboard.press( 'ArrowUp' );
await editor.clickBlockToolbarButton( 'Add citation' );
await page.keyboard.type( '2' );
await pageUtils.pressKeys( 'Shift+ArrowUp' );
let error;
page.on( 'console', ( msg ) => {
if ( msg.type() === 'error' ) error = msg.text();
} );
await page.keyboard.press( 'Backspace' );
expect( error ).toBeUndefined();
} );
} );