@wordpress/e2e-tests 5.0.0 → 5.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (30) hide show
  1. package/assets/large-post.html +1478 -96
  2. package/package.json +5 -5
  3. package/specs/editor/blocks/navigation.test.js +4 -6
  4. package/specs/editor/plugins/__snapshots__/cpt-locking.test.js.snap +3 -1
  5. package/specs/editor/plugins/__snapshots__/plugins-api.test.js.snap +2 -2
  6. package/specs/editor/plugins/cpt-locking.test.js +15 -15
  7. package/specs/editor/plugins/iframed-block.test.js +2 -12
  8. package/specs/editor/plugins/iframed-inline-styles.test.js +3 -12
  9. package/specs/editor/plugins/iframed-masonry-block.test.js +2 -12
  10. package/specs/editor/plugins/iframed-multiple-block-stylesheets.test.js +3 -12
  11. package/specs/editor/plugins/inner-blocks-allowed-blocks.test.js +3 -0
  12. package/specs/editor/various/__snapshots__/block-deletion.test.js.snap +3 -1
  13. package/specs/editor/various/__snapshots__/keep-styles-on-block-transforms.test.js.snap +0 -6
  14. package/specs/editor/various/__snapshots__/multi-block-selection.test.js.snap +25 -1
  15. package/specs/editor/various/__snapshots__/rich-text.test.js.snap +19 -5
  16. package/specs/editor/various/block-switcher.test.js +11 -3
  17. package/specs/editor/various/font-size-picker.test.js +1 -3
  18. package/specs/editor/various/inserting-blocks.test.js +4 -0
  19. package/specs/editor/various/keep-styles-on-block-transforms.test.js +0 -17
  20. package/specs/editor/various/multi-block-selection.test.js +8 -0
  21. package/specs/editor/various/rich-text.test.js +9 -6
  22. package/specs/editor/various/splitting-merging.test.js +7 -2
  23. package/specs/editor/various/toolbar-roving-tabindex.test.js +2 -1
  24. package/specs/editor/plugins/register-block-type-hooks.test.js +0 -32
  25. package/specs/editor/various/__snapshots__/draggable-block.test.js.snap +0 -41
  26. package/specs/editor/various/__snapshots__/duplicating-blocks.test.js.snap +0 -21
  27. package/specs/editor/various/__snapshots__/writing-flow.test.js.snap +0 -305
  28. package/specs/editor/various/draggable-block.test.js +0 -127
  29. package/specs/editor/various/duplicating-blocks.test.js +0 -47
  30. package/specs/editor/various/writing-flow.test.js +0 -829
@@ -1,829 +0,0 @@
1
- /**
2
- * WordPress dependencies
3
- */
4
- import {
5
- clickBlockAppender,
6
- getEditedPostContent,
7
- createNewPost,
8
- pressKeyTimes,
9
- pressKeyWithModifier,
10
- insertBlock,
11
- clickBlockToolbarButton,
12
- openDocumentSettingsSidebar,
13
- } from '@wordpress/e2e-test-utils';
14
-
15
- const getActiveBlockName = async () =>
16
- page.evaluate(
17
- () => wp.data.select( 'core/block-editor' ).getSelectedBlock()?.name
18
- );
19
-
20
- const addParagraphsAndColumnsDemo = async () => {
21
- // Add demo content.
22
- await clickBlockAppender();
23
- await page.keyboard.type( 'First paragraph' );
24
- await page.keyboard.press( 'Enter' );
25
- await page.keyboard.type( '/columns' );
26
- await page.waitForXPath(
27
- `//*[contains(@class, "components-autocomplete__result") and contains(@class, "is-selected") and contains(text(), 'Columns')]`
28
- );
29
- await page.keyboard.press( 'Enter' );
30
- await page.click( 'button[aria-label="Two columns; equal split"]' );
31
- await page.click( '.block-editor-button-block-appender' );
32
- await page.waitForSelector( '.block-editor-inserter__search input:focus' );
33
- await page.keyboard.type( 'Paragraph' );
34
- await pressKeyTimes( 'Tab', 2 ); // Tab to paragraph result.
35
- await page.keyboard.press( 'Enter' ); // Insert paragraph.
36
- await page.keyboard.type( '1st col' ); // If this text is too long, it may wrap to a new line and cause test failure. That's why we're using "1st" instead of "First" here.
37
-
38
- // TODO: ArrowDown should traverse into the second column. In slower
39
- // CPUs, it can sometimes remain in the first column paragraph. This
40
- // is a temporary solution.
41
- await page.focus( '.wp-block[data-type="core/column"]:nth-child(2)' );
42
- await page.click( ':focus .block-editor-button-block-appender' );
43
- await page.waitForSelector( '.block-editor-inserter__search input:focus' );
44
- await page.keyboard.type( 'Paragraph' );
45
- await pressKeyTimes( 'Tab', 2 ); // Tab to paragraph result.
46
- await page.keyboard.press( 'Enter' ); // Insert paragraph.
47
- await page.keyboard.type( '2nd col' ); // If this text is too long, it may wrap to a new line and cause test failure. That's why we're using "2nd" instead of "Second" here.
48
-
49
- await page.keyboard.press( 'Escape' ); // Enter navigation mode.
50
- await page.keyboard.press( 'ArrowLeft' ); // Move to the column block.
51
- await page.keyboard.press( 'ArrowLeft' ); // Move to the columns block.
52
- await page.keyboard.press( 'Enter' ); // Enter edit mode with the columns block selected.
53
- await page.keyboard.press( 'Enter' ); // Creates a paragraph after the columns block.
54
- await page.keyboard.type( 'Second paragraph' );
55
- };
56
-
57
- describe( 'Writing Flow', () => {
58
- beforeEach( async () => {
59
- await createNewPost();
60
- } );
61
-
62
- it( 'Should navigate inner blocks with arrow keys', async () => {
63
- // TODO: The `waitForSelector` calls in this function should ultimately
64
- // not be necessary for interactions, and exist as a stop-gap solution
65
- // where rendering delays in slower CPU can cause intermittent failure.
66
-
67
- // Assertions are made both against the active DOM element and the
68
- // editor state, in order to protect against potential disparities.
69
- //
70
- // See: https://github.com/WordPress/gutenberg/issues/18928
71
- let activeElementText, activeBlockName;
72
-
73
- // Add demo content.
74
- await addParagraphsAndColumnsDemo();
75
-
76
- // Arrow up into nested context focuses last text input.
77
- await page.keyboard.press( 'ArrowUp' );
78
- activeBlockName = await getActiveBlockName();
79
- expect( activeBlockName ).toBe( 'core/paragraph' );
80
- activeElementText = await page.evaluate(
81
- () => document.activeElement.textContent
82
- );
83
- expect( activeElementText ).toBe( '2nd col' );
84
-
85
- // Arrow up in inner blocks should navigate through (1) column wrapper,
86
- // (2) text fields.
87
- await page.keyboard.press( 'ArrowUp' );
88
- activeBlockName = await getActiveBlockName();
89
- expect( activeBlockName ).toBe( 'core/column' );
90
- await page.keyboard.press( 'ArrowUp' );
91
- const activeElementBlockType = await page.evaluate( () =>
92
- document.activeElement.getAttribute( 'data-type' )
93
- );
94
- expect( activeElementBlockType ).toBe( 'core/columns' );
95
- activeBlockName = await getActiveBlockName();
96
- expect( activeBlockName ).toBe( 'core/columns' );
97
-
98
- // Arrow up from focused (columns) block wrapper exits nested context
99
- // to prior text input.
100
- await page.keyboard.press( 'ArrowUp' );
101
- activeBlockName = await getActiveBlockName();
102
- expect( activeBlockName ).toBe( 'core/paragraph' );
103
- activeElementText = await page.evaluate(
104
- () => document.activeElement.textContent
105
- );
106
- expect( activeElementText ).toBe( 'First paragraph' );
107
-
108
- expect( await getEditedPostContent() ).toMatchSnapshot();
109
- } );
110
-
111
- it( 'Should navigate between inner and root blocks in navigation mode', async () => {
112
- // In navigation mode the active element is the block name button, so we can't easily check the block content.
113
- let activeBlockName;
114
-
115
- // Add demo content.
116
- await addParagraphsAndColumnsDemo();
117
-
118
- // Switch to navigation mode.
119
- await page.keyboard.press( 'Escape' );
120
- // Arrow up to Columns block.
121
- await page.keyboard.press( 'ArrowUp' );
122
- activeBlockName = await getActiveBlockName();
123
- expect( activeBlockName ).toBe( 'core/columns' );
124
- // Arrow right into Column block.
125
- await page.keyboard.press( 'ArrowRight' );
126
- activeBlockName = await getActiveBlockName();
127
- expect( activeBlockName ).toBe( 'core/column' );
128
- // Arrow down to reach second Column block.
129
- await page.keyboard.press( 'ArrowDown' );
130
- // Arrow right again into Paragraph block.
131
- await page.keyboard.press( 'ArrowRight' );
132
- activeBlockName = await getActiveBlockName();
133
- expect( activeBlockName ).toBe( 'core/paragraph' );
134
- // Arrow left back to Column block.
135
- await page.keyboard.press( 'ArrowLeft' );
136
- activeBlockName = await getActiveBlockName();
137
- expect( activeBlockName ).toBe( 'core/column' );
138
- // Arrow left back to Columns block.
139
- await page.keyboard.press( 'ArrowLeft' );
140
- activeBlockName = await getActiveBlockName();
141
- expect( activeBlockName ).toBe( 'core/columns' );
142
- // Arrow up to first paragraph.
143
- await page.keyboard.press( 'ArrowUp' );
144
- activeBlockName = await getActiveBlockName();
145
- expect( activeBlockName ).toBe( 'core/paragraph' );
146
- } );
147
-
148
- it( 'should navigate around inline boundaries', async () => {
149
- // Add demo content.
150
- await clickBlockAppender();
151
- await page.keyboard.type( 'First' );
152
- await page.keyboard.press( 'Enter' );
153
- await page.keyboard.type( 'Second' );
154
- await page.keyboard.press( 'Enter' );
155
- await page.keyboard.type( 'Third' );
156
-
157
- // Navigate to second paragraph.
158
- await pressKeyTimes( 'ArrowLeft', 6 );
159
-
160
- // Bold second paragraph text.
161
- await page.keyboard.down( 'Shift' );
162
- await pressKeyTimes( 'ArrowLeft', 6 );
163
- await page.keyboard.up( 'Shift' );
164
- await pressKeyWithModifier( 'primary', 'b' );
165
-
166
- // Arrow left from selected bold should collapse to before the inline
167
- // boundary. Arrow once more to traverse into first paragraph.
168
- await page.keyboard.press( 'ArrowLeft' );
169
- await page.keyboard.press( 'ArrowLeft' );
170
- await page.keyboard.type( 'After' );
171
-
172
- // Arrow right from end of first should traverse to second, *BEFORE*
173
- // the bolded text. Another press should move within inline boundary.
174
- await pressKeyTimes( 'ArrowRight', 2 );
175
- await page.keyboard.type( 'Inside' );
176
-
177
- // Arrow left from end of beginning of inline boundary should move to
178
- // the outside of the inline boundary.
179
- await pressKeyTimes( 'ArrowLeft', 6 );
180
- await page.keyboard.press( 'ArrowLeft' ); // Separate for emphasis.
181
- await page.keyboard.type( 'Before' );
182
-
183
- // Likewise, test at the end of the inline boundary for same effect.
184
- await page.keyboard.press( 'ArrowRight' ); // Move inside
185
- await pressKeyTimes( 'ArrowRight', 12 );
186
- await page.keyboard.type( 'Inside' );
187
- await page.keyboard.press( 'ArrowRight' );
188
-
189
- // Edge case: Verify that workaround to test for ZWSP at beginning of
190
- // focus node does not take effect when on the right edge of inline
191
- // boundary (thus preventing traversing to the next block by arrow).
192
- await page.keyboard.press( 'ArrowRight' );
193
- await page.keyboard.press( 'ArrowLeft' );
194
-
195
- // Should be after the inline boundary again.
196
- await page.keyboard.type( 'After' );
197
-
198
- // Finally, ensure that ArrowRight from end of unbolded text moves to
199
- // the last paragraph.
200
- await page.keyboard.press( 'ArrowRight' );
201
- await page.keyboard.type( 'Before' );
202
-
203
- expect( await getEditedPostContent() ).toMatchSnapshot();
204
- } );
205
-
206
- it( 'should navigate around nested inline boundaries', async () => {
207
- await clickBlockAppender();
208
- await pressKeyWithModifier( 'primary', 'b' );
209
- await page.keyboard.type( '1 2' );
210
- await page.keyboard.down( 'Shift' );
211
- await page.keyboard.press( 'ArrowLeft' );
212
- await page.keyboard.up( 'Shift' );
213
- await pressKeyWithModifier( 'primary', 'i' );
214
- await page.keyboard.press( 'ArrowLeft' );
215
- await page.keyboard.press( 'ArrowLeft' );
216
- await page.keyboard.down( 'Shift' );
217
- await page.keyboard.press( 'ArrowLeft' );
218
- await page.keyboard.up( 'Shift' );
219
- await pressKeyWithModifier( 'primary', 'i' );
220
- await page.keyboard.press( 'ArrowLeft' );
221
-
222
- expect( await getEditedPostContent() ).toMatchSnapshot();
223
-
224
- await page.keyboard.type( 'a' );
225
- await page.keyboard.press( 'ArrowRight' );
226
- await page.keyboard.type( 'b' );
227
- await page.keyboard.press( 'ArrowRight' );
228
- await page.keyboard.type( 'c' );
229
- await page.keyboard.press( 'ArrowRight' );
230
- await page.keyboard.type( 'd' );
231
- await page.keyboard.press( 'ArrowRight' );
232
- await page.keyboard.type( 'e' );
233
- await page.keyboard.press( 'ArrowRight' );
234
- await page.keyboard.type( 'f' );
235
- await page.keyboard.press( 'ArrowRight' );
236
- await page.keyboard.type( 'g' );
237
- await page.keyboard.press( 'ArrowRight' );
238
- await page.keyboard.type( 'h' );
239
- await page.keyboard.press( 'ArrowRight' );
240
- await page.keyboard.type( 'i' );
241
- await page.keyboard.press( 'ArrowRight' );
242
- await page.keyboard.type( 'j' );
243
-
244
- expect( await getEditedPostContent() ).toMatchSnapshot();
245
- } );
246
-
247
- it( 'should insert line break at end', async () => {
248
- await clickBlockAppender();
249
- await page.keyboard.type( 'a' );
250
- await pressKeyWithModifier( 'shift', 'Enter' );
251
- expect( await getEditedPostContent() ).toMatchSnapshot();
252
- } );
253
-
254
- it( 'should insert line break at end and continue writing', async () => {
255
- await clickBlockAppender();
256
- await page.keyboard.type( 'a' );
257
- await pressKeyWithModifier( 'shift', 'Enter' );
258
- await page.keyboard.type( 'b' );
259
- expect( await getEditedPostContent() ).toMatchSnapshot();
260
- } );
261
-
262
- it( 'should insert line break mid text', async () => {
263
- await clickBlockAppender();
264
- await page.keyboard.type( 'ab' );
265
- await page.keyboard.press( 'ArrowLeft' );
266
- await pressKeyWithModifier( 'shift', 'Enter' );
267
- expect( await getEditedPostContent() ).toMatchSnapshot();
268
- } );
269
-
270
- it( 'should insert line break at start', async () => {
271
- await clickBlockAppender();
272
- await page.keyboard.type( 'a' );
273
- await page.keyboard.press( 'ArrowLeft' );
274
- await pressKeyWithModifier( 'shift', 'Enter' );
275
- expect( await getEditedPostContent() ).toMatchSnapshot();
276
- } );
277
-
278
- it( 'should insert line break in empty container', async () => {
279
- await clickBlockAppender();
280
- await pressKeyWithModifier( 'shift', 'Enter' );
281
- expect( await getEditedPostContent() ).toMatchSnapshot();
282
- } );
283
-
284
- it( 'should not create extra line breaks in multiline value', async () => {
285
- await insertBlock( 'List' );
286
- await page.keyboard.type( 'a' );
287
- await page.keyboard.press( 'Backspace' );
288
- expect( await getEditedPostContent() ).toMatchSnapshot();
289
- } );
290
-
291
- it( 'should navigate native inputs vertically, not horizontally', async () => {
292
- // See: https://github.com/WordPress/gutenberg/issues/9626
293
-
294
- await insertBlock( 'Shortcode' );
295
- await insertBlock( 'Paragraph' );
296
- await await page.click( '.wp-block-shortcode' );
297
-
298
- // Should remain in title upon ArrowRight:
299
- await page.keyboard.press( 'ArrowRight' );
300
- let isInShortcodeBlock = await page.evaluate(
301
- () => !! document.activeElement.closest( '.wp-block-shortcode' )
302
- );
303
- expect( isInShortcodeBlock ).toBe( true );
304
-
305
- // Should remain in title upon modifier + ArrowDown:
306
- await pressKeyWithModifier( 'primary', 'ArrowDown' );
307
- isInShortcodeBlock = await page.evaluate(
308
- () => !! document.activeElement.closest( '.wp-block-shortcode' )
309
- );
310
- expect( isInShortcodeBlock ).toBe( true );
311
-
312
- // Should navigate to the next block.
313
- await page.keyboard.press( 'ArrowDown' );
314
- const isInParagraphBlock = await page.evaluate(
315
- () => !! document.activeElement.closest( '.wp-block-paragraph' )
316
- );
317
- expect( isInParagraphBlock ).toBe( true );
318
- } );
319
-
320
- it( 'should not delete surrounding space when deleting a word with Backspace', async () => {
321
- await clickBlockAppender();
322
- await page.keyboard.type( '1 2 3' );
323
- await pressKeyTimes( 'ArrowLeft', ' 3'.length );
324
- await page.keyboard.press( 'Backspace' );
325
-
326
- expect( await getEditedPostContent() ).toMatchSnapshot();
327
-
328
- await page.keyboard.type( '2' );
329
-
330
- expect( await getEditedPostContent() ).toMatchSnapshot();
331
- } );
332
-
333
- it( 'should not delete surrounding space when deleting a word with Alt+Backspace', async () => {
334
- await clickBlockAppender();
335
- await page.keyboard.type( 'alpha beta gamma' );
336
- await pressKeyTimes( 'ArrowLeft', ' gamma'.length );
337
-
338
- if ( process.platform === 'darwin' ) {
339
- await pressKeyWithModifier( 'alt', 'Backspace' );
340
- } else {
341
- await pressKeyWithModifier( 'primary', 'Backspace' );
342
- }
343
-
344
- expect( await getEditedPostContent() ).toMatchSnapshot();
345
-
346
- await page.keyboard.type( 'beta' );
347
-
348
- expect( await getEditedPostContent() ).toMatchSnapshot();
349
- } );
350
-
351
- it( 'should not delete surrounding space when deleting a selected word', async () => {
352
- await clickBlockAppender();
353
- await page.keyboard.type( 'alpha beta gamma' );
354
- await pressKeyTimes( 'ArrowLeft', ' gamma'.length );
355
- await page.keyboard.down( 'Shift' );
356
- await pressKeyTimes( 'ArrowLeft', 'beta'.length );
357
- await page.keyboard.up( 'Shift' );
358
- await page.keyboard.press( 'Backspace' );
359
-
360
- expect( await getEditedPostContent() ).toMatchSnapshot();
361
-
362
- await page.keyboard.type( 'beta' );
363
-
364
- expect( await getEditedPostContent() ).toMatchSnapshot();
365
- } );
366
-
367
- it( 'should create valid paragraph blocks when rapidly pressing Enter', async () => {
368
- await clickBlockAppender();
369
- await pressKeyTimes( 'Enter', 10 );
370
-
371
- // Check that none of the paragraph blocks have <br> in them.
372
- expect( await getEditedPostContent() ).toMatchSnapshot();
373
- } );
374
-
375
- it( 'should navigate empty paragraph', async () => {
376
- await clickBlockAppender();
377
- await page.keyboard.press( 'Enter' );
378
- await page.keyboard.press( 'ArrowLeft' );
379
- await page.keyboard.type( '1' );
380
- await page.keyboard.press( 'ArrowRight' );
381
- await page.keyboard.type( '2' );
382
-
383
- expect( await getEditedPostContent() ).toMatchSnapshot();
384
- } );
385
-
386
- it( 'should navigate contenteditable with padding', async () => {
387
- await clickBlockAppender();
388
- await page.keyboard.press( 'Enter' );
389
- await page.evaluate( () => {
390
- document.activeElement.style.paddingTop = '100px';
391
- } );
392
- await page.keyboard.press( 'ArrowUp' );
393
- await page.keyboard.type( '1' );
394
- await page.evaluate( () => {
395
- document.activeElement.style.paddingBottom = '100px';
396
- } );
397
- await page.keyboard.press( 'ArrowDown' );
398
- await page.keyboard.type( '2' );
399
-
400
- expect( await getEditedPostContent() ).toMatchSnapshot();
401
- } );
402
-
403
- it( 'should navigate contenteditable with normal line height', async () => {
404
- await clickBlockAppender();
405
- await page.keyboard.press( 'Enter' );
406
- await page.evaluate( () => {
407
- document.activeElement.style.lineHeight = 'normal';
408
- } );
409
- await page.keyboard.press( 'ArrowUp' );
410
- await page.keyboard.type( '1' );
411
-
412
- expect( await getEditedPostContent() ).toMatchSnapshot();
413
- } );
414
-
415
- it( 'should not prematurely multi-select', async () => {
416
- await clickBlockAppender();
417
- await page.keyboard.type( '1' );
418
- await page.keyboard.press( 'Enter' );
419
- await page.keyboard.type( '><<' );
420
- await pressKeyWithModifier( 'shift', 'Enter' );
421
- await page.keyboard.type( '<<<' );
422
- await page.keyboard.down( 'Shift' );
423
- await pressKeyTimes( 'ArrowLeft', '<<\n<<<'.length );
424
- await page.keyboard.up( 'Shift' );
425
- await page.keyboard.press( 'Backspace' );
426
-
427
- expect( await getEditedPostContent() ).toMatchSnapshot();
428
- } );
429
-
430
- it( 'should merge paragraphs', async () => {
431
- await page.keyboard.press( 'Enter' );
432
- await page.keyboard.type( '1' );
433
- await page.keyboard.press( 'Enter' );
434
- await page.keyboard.type( '2' );
435
- await page.keyboard.press( 'ArrowLeft' );
436
- await page.keyboard.press( 'Backspace' );
437
-
438
- expect( await getEditedPostContent() ).toMatchSnapshot();
439
- } );
440
-
441
- it( 'should merge and then split paragraphs', async () => {
442
- await page.keyboard.press( 'Enter' );
443
- await page.keyboard.type( 'abc' );
444
- await page.keyboard.press( 'Enter' );
445
- await page.keyboard.type( '123' );
446
- await page.keyboard.press( 'ArrowUp' );
447
- await page.keyboard.press( 'Delete' );
448
- await page.keyboard.press( 'Enter' );
449
-
450
- expect( await getEditedPostContent() ).toMatchInlineSnapshot( `
451
- "<!-- wp:paragraph -->
452
- <p>abc</p>
453
- <!-- /wp:paragraph -->
454
-
455
- <!-- wp:paragraph -->
456
- <p>123</p>
457
- <!-- /wp:paragraph -->"
458
- ` );
459
- } );
460
-
461
- it( 'should merge and then soft line break', async () => {
462
- await page.keyboard.press( 'Enter' );
463
- await page.keyboard.type( '1' );
464
- await page.keyboard.press( 'Enter' );
465
- await page.keyboard.type( '2' );
466
- await page.keyboard.press( 'ArrowUp' );
467
- await page.keyboard.press( 'Delete' );
468
- await page.keyboard.down( 'Shift' );
469
- await page.keyboard.press( 'Enter' );
470
- await page.keyboard.up( 'Shift' );
471
-
472
- expect( await getEditedPostContent() ).toMatchInlineSnapshot( `
473
- "<!-- wp:paragraph -->
474
- <p>1<br>2</p>
475
- <!-- /wp:paragraph -->"
476
- ` );
477
- } );
478
-
479
- it( 'should merge forwards', async () => {
480
- await page.keyboard.press( 'Enter' );
481
- await page.keyboard.type( '1' );
482
- await page.keyboard.press( 'Enter' );
483
- await page.keyboard.type( '3' );
484
- await page.keyboard.press( 'ArrowUp' );
485
- await page.keyboard.press( 'Delete' );
486
- await page.keyboard.type( '2' );
487
-
488
- expect( await getEditedPostContent() ).toMatchSnapshot();
489
- } );
490
-
491
- it( 'should merge forwards properly on multiple triggers', async () => {
492
- await page.keyboard.press( 'Enter' );
493
- await page.keyboard.type( '1' );
494
- await page.keyboard.press( 'Enter' );
495
- await page.keyboard.type( '2' );
496
- await page.keyboard.press( 'Enter' );
497
- await page.keyboard.type( '3' );
498
- await pressKeyTimes( 'ArrowUp', 2 );
499
- await pressKeyTimes( 'Delete', 2 );
500
- expect( await getEditedPostContent() ).toMatchInlineSnapshot( `
501
- "<!-- wp:paragraph -->
502
- <p>1</p>
503
- <!-- /wp:paragraph -->
504
-
505
- <!-- wp:paragraph -->
506
- <p>3</p>
507
- <!-- /wp:paragraph -->"
508
- ` );
509
- await page.keyboard.press( 'Delete' );
510
-
511
- expect( await getEditedPostContent() ).toMatchInlineSnapshot( `
512
- "<!-- wp:paragraph -->
513
- <p>13</p>
514
- <!-- /wp:paragraph -->"
515
- ` );
516
- } );
517
-
518
- it( 'should preserve horizontal position when navigating vertically between blocks', async () => {
519
- await page.keyboard.press( 'Enter' );
520
- await page.keyboard.type( 'abc' );
521
- await page.keyboard.press( 'Enter' );
522
- await page.keyboard.type( '23' );
523
- await page.keyboard.press( 'ArrowUp' );
524
- await page.keyboard.press( 'ArrowLeft' );
525
- await page.keyboard.press( 'ArrowLeft' );
526
- await page.keyboard.press( 'ArrowDown' );
527
- await page.keyboard.type( '1' );
528
-
529
- expect( await getEditedPostContent() ).toMatchSnapshot();
530
- } );
531
-
532
- it( 'should remember initial vertical position', async () => {
533
- await page.keyboard.press( 'Enter' );
534
- await page.keyboard.type( '1' );
535
- await page.keyboard.press( 'Enter' );
536
- await pressKeyWithModifier( 'shift', 'Enter' );
537
- await page.keyboard.type( '2' );
538
- await page.keyboard.press( 'ArrowUp' );
539
- await page.keyboard.press( 'ArrowUp' );
540
- await page.keyboard.type( 'x' ); // Should be right after "1".
541
-
542
- expect( await getEditedPostContent() ).toMatchSnapshot();
543
- } );
544
-
545
- it( 'should navigate contenteditable with side padding', async () => {
546
- await clickBlockAppender();
547
- await page.keyboard.press( 'Enter' );
548
- await page.evaluate( () => {
549
- document.activeElement.style.paddingLeft = '100px';
550
- } );
551
- await page.keyboard.press( 'Enter' );
552
- await page.keyboard.press( 'ArrowUp' );
553
- await page.keyboard.press( 'ArrowUp' );
554
- await page.keyboard.type( '1' );
555
-
556
- expect( await getEditedPostContent() ).toMatchSnapshot();
557
- } );
558
-
559
- it( 'should navigate empty paragraphs', async () => {
560
- await page.keyboard.press( 'Enter' );
561
- await page.keyboard.press( 'Enter' );
562
- await page.keyboard.press( 'Enter' );
563
- await page.keyboard.press( 'ArrowLeft' );
564
- await page.keyboard.press( 'ArrowLeft' );
565
- await page.keyboard.type( '1' );
566
- await page.keyboard.press( 'ArrowRight' );
567
- await page.keyboard.press( 'ArrowRight' );
568
- await page.keyboard.type( '3' );
569
-
570
- expect( await getEditedPostContent() ).toMatchSnapshot();
571
- } );
572
-
573
- it( 'should allow selecting entire list with longer last item', async () => {
574
- await page.keyboard.press( 'Enter' );
575
- await page.keyboard.type( 'a' );
576
- await page.keyboard.press( 'Enter' );
577
- await page.keyboard.type( '* b' );
578
- await page.keyboard.press( 'Enter' );
579
- await page.keyboard.type( 'cd' );
580
- await pressKeyWithModifier( 'shift', 'ArrowUp' );
581
- await pressKeyWithModifier( 'shift', 'ArrowUp' );
582
-
583
- // Ensure multi selection is not triggered and selection stays within
584
- // the list.
585
- await page.keyboard.press( 'Backspace' );
586
-
587
- expect( await getEditedPostContent() ).toMatchSnapshot();
588
- } );
589
-
590
- it( 'should not have a dead zone between blocks (lower)', async () => {
591
- await page.keyboard.press( 'Enter' );
592
- await page.keyboard.type( '1' );
593
- await page.keyboard.press( 'Enter' );
594
- await page.keyboard.type( '2' );
595
- await page.keyboard.press( 'ArrowUp' );
596
-
597
- // Find a point outside the paragraph between the blocks where it's
598
- // expected that the sibling inserter would be placed.
599
- const paragraph = await page.$( '[data-type="core/paragraph"]' );
600
- const paragraphRect = await paragraph.boundingBox();
601
- const x = paragraphRect.x + ( 2 * paragraphRect.width ) / 3;
602
- const y = paragraphRect.y + paragraphRect.height + 1;
603
-
604
- await page.mouse.move( x, y );
605
- await page.waitForSelector(
606
- '.block-editor-block-list__insertion-point'
607
- );
608
-
609
- const inserter = await page.$(
610
- '.block-editor-block-list__insertion-point'
611
- );
612
- const inserterRect = await inserter.boundingBox();
613
- const lowerInserterY = inserterRect.y + ( 2 * inserterRect.height ) / 3;
614
-
615
- await page.mouse.click( x, lowerInserterY );
616
- await page.keyboard.type( '3' );
617
-
618
- expect( await getEditedPostContent() ).toMatchSnapshot();
619
- } );
620
-
621
- it( 'should not have a dead zone above an aligned block', async () => {
622
- await page.keyboard.press( 'Enter' );
623
- await page.keyboard.type( '1' );
624
- await page.keyboard.press( 'Enter' );
625
- await page.keyboard.type( '/image' );
626
- await page.keyboard.press( 'Enter' );
627
- await clickBlockToolbarButton( 'Align' );
628
- const wideButton = await page.waitForXPath(
629
- `//button[contains(@class,'components-dropdown-menu__menu-item')]//span[contains(text(), 'Wide width')]`
630
- );
631
- await wideButton.click();
632
- // Focus the block content
633
- await page.keyboard.press( 'Tab' );
634
-
635
- // Select the previous block.
636
- await page.keyboard.press( 'ArrowUp' );
637
- await page.keyboard.press( 'ArrowUp' );
638
-
639
- // Confirm correct setup.
640
- expect( await getEditedPostContent() ).toMatchSnapshot();
641
-
642
- // Find a point outside the paragraph between the blocks where it's
643
- // expected that the sibling inserter would be placed.
644
- const paragraph = await page.$( '[data-type="core/paragraph"]' );
645
- const paragraphRect = await paragraph.boundingBox();
646
- const x = paragraphRect.x + ( 2 * paragraphRect.width ) / 3;
647
- const y = paragraphRect.y + paragraphRect.height + 1;
648
-
649
- await page.mouse.move( x, y );
650
- await page.waitForSelector(
651
- '.block-editor-block-list__insertion-point'
652
- );
653
-
654
- const inserter = await page.$(
655
- '.block-editor-block-list__insertion-point'
656
- );
657
- // Find the space between the inserter and the image block.
658
- const inserterRect = await inserter.boundingBox();
659
- const lowerInserterY = inserterRect.y + ( 2 * inserterRect.height ) / 3;
660
-
661
- // Clicking that in-between space should select the image block.
662
- await page.mouse.click( x, lowerInserterY );
663
-
664
- const type = await page.evaluate( () =>
665
- document.activeElement
666
- .closest( '[data-block]' )
667
- .getAttribute( 'data-type' )
668
- );
669
-
670
- expect( type ).toBe( 'core/image' );
671
- } );
672
-
673
- it( 'should only consider the content as one tab stop', async () => {
674
- await page.keyboard.press( 'Enter' );
675
- await page.keyboard.type( '/table' );
676
- await page.keyboard.press( 'Enter' );
677
- // Tab to the "Create table" button.
678
- await page.keyboard.press( 'Tab' );
679
- await page.keyboard.press( 'Tab' );
680
- // Create the table.
681
- await page.keyboard.press( 'Space' );
682
- // Navigate to the second cell.
683
- await page.keyboard.press( 'ArrowRight' );
684
- await page.keyboard.type( '2' );
685
- // Confirm correct setup.
686
- expect( await getEditedPostContent() ).toMatchSnapshot();
687
- } );
688
-
689
- it( 'should unselect all blocks when hitting double escape', async () => {
690
- // Add demo content.
691
- await page.keyboard.press( 'Enter' );
692
- await page.keyboard.type( 'Random Paragraph' );
693
-
694
- // Select a block.
695
- let activeBlockName = await getActiveBlockName();
696
- expect( activeBlockName ).toBe( 'core/paragraph' );
697
-
698
- // First escape enters navigaiton mode.
699
- await page.keyboard.press( 'Escape' );
700
- activeBlockName = await getActiveBlockName();
701
- expect( activeBlockName ).toBe( 'core/paragraph' );
702
-
703
- // Second escape unselects the blocks.
704
- await page.keyboard.press( 'Escape' );
705
- activeBlockName = await getActiveBlockName();
706
- expect( activeBlockName ).toBe( undefined );
707
- } );
708
-
709
- // Checks for regressions of https://github.com/WordPress/gutenberg/issues/40091.
710
- it( 'does not deselect the block when selecting text outside the editor canvas', async () => {
711
- await page.keyboard.press( 'Enter' );
712
- await page.keyboard.type( 'Random Paragraph' );
713
- await openDocumentSettingsSidebar();
714
- const blockDescription = await page.waitForSelector(
715
- '.block-editor-block-card__description'
716
- );
717
- const boundingBox = await blockDescription.boundingBox();
718
- const startPosition = {
719
- x: boundingBox.x + 10,
720
- y: boundingBox.y + 8,
721
- };
722
- const endPosition = {
723
- x: startPosition.x + 50,
724
- y: startPosition.y,
725
- };
726
-
727
- await page.mouse.move( startPosition.x, startPosition.y );
728
- await page.mouse.down();
729
- await page.mouse.move( endPosition.x, endPosition.y );
730
- await page.mouse.up();
731
-
732
- const selectedParagraph = await page.waitForSelector(
733
- '.wp-block-paragraph.is-selected'
734
- );
735
- expect( selectedParagraph ).toBeDefined();
736
- } );
737
- it( 'should prevent browser default formatting on multi selection', async () => {
738
- await page.keyboard.press( 'Enter' );
739
- await page.keyboard.type( 'first' );
740
- await page.keyboard.press( 'Enter' );
741
- await page.keyboard.type( 'second' );
742
-
743
- // Multi select both paragraphs.
744
- await pressKeyTimes( 'ArrowLeft', 2 );
745
- await page.keyboard.down( 'Shift' );
746
- await pressKeyTimes( 'ArrowLeft', 2 );
747
- await page.keyboard.press( 'ArrowUp' );
748
- await page.keyboard.up( 'Shift' );
749
- await pressKeyWithModifier( 'primary', 'b' );
750
- const paragraphs = await page.$$eval(
751
- '[data-type="core/paragraph"]',
752
- ( nodes ) => Array.from( nodes ).map( ( node ) => node.innerHTML )
753
- );
754
- expect( paragraphs ).toEqual( [ 'first', 'second' ] );
755
- } );
756
-
757
- it( 'should move to the start of the first line on ArrowUp', async () => {
758
- await page.keyboard.press( 'Enter' );
759
- await page.keyboard.type( 'a' );
760
-
761
- async function getHeight() {
762
- return await page.evaluate(
763
- () => document.activeElement.offsetHeight
764
- );
765
- }
766
-
767
- const height = await getHeight();
768
-
769
- // Keep typing until the height of the element increases. We need two
770
- // lines.
771
- while ( height === ( await getHeight() ) ) {
772
- await page.keyboard.type( 'a' );
773
- }
774
-
775
- // Move to the start of the second line.
776
- await page.keyboard.press( 'ArrowLeft' );
777
- // Move to the start of the first line.
778
- await page.keyboard.press( 'ArrowUp' );
779
- // Insert a "." for testing.
780
- await page.keyboard.type( '.' );
781
-
782
- // Expect the "." to be added at the start of the paragraph.
783
- expect(
784
- await page.evaluate( () =>
785
- document.activeElement.getAttribute( 'data-type' )
786
- )
787
- ).toBe( 'core/paragraph' );
788
- expect(
789
- await page.evaluate( () => document.activeElement.textContent )
790
- ).toMatch( /^\.a+$/ );
791
- } );
792
-
793
- it( 'should vertically move the caret from corner to corner', async () => {
794
- await page.keyboard.press( 'Enter' );
795
- await page.keyboard.type( 'a' );
796
-
797
- async function getHeight() {
798
- return await page.evaluate(
799
- () => document.activeElement.offsetHeight
800
- );
801
- }
802
-
803
- const height = await getHeight();
804
-
805
- // Keep typing until the height of the element increases. We need two
806
- // lines.
807
- while ( height === ( await getHeight() ) ) {
808
- await page.keyboard.type( 'a' );
809
- }
810
-
811
- // Create a new paragraph.
812
- await page.keyboard.press( 'Enter' );
813
- // Move to the start of the first line.
814
- await page.keyboard.press( 'ArrowUp' );
815
- // Insert a "." for testing.
816
- await page.keyboard.type( '.' );
817
-
818
- // Expect the "." to be added at the start of the second line.
819
- // It should not be added to the first line!
820
- expect(
821
- await page.evaluate( () =>
822
- document.activeElement.getAttribute( 'data-type' )
823
- )
824
- ).toBe( 'core/paragraph' );
825
- expect(
826
- await page.evaluate( () => document.activeElement.textContent )
827
- ).toMatch( /^a+\.a$/ );
828
- } );
829
- } );