/
writing-flow.test.js
649 lines (550 loc) · 23.1 KB
/
writing-flow.test.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
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
/**
* WordPress dependencies
*/
import {
clickBlockAppender,
getEditedPostContent,
createNewPost,
pressKeyTimes,
pressKeyWithModifier,
insertBlock,
clickBlockToolbarButton,
} from '@wordpress/e2e-test-utils';
const getActiveBlockName = async () =>
page.evaluate(
() => wp.data.select( 'core/block-editor' ).getSelectedBlock()?.name
);
const addParagraphsAndColumnsDemo = async () => {
// Add demo content
await clickBlockAppender();
await page.keyboard.type( 'First paragraph' );
await page.keyboard.press( 'Enter' );
await page.keyboard.type( '/columns' );
await page.waitForXPath(
`//*[contains(@class, "components-autocomplete__result") and contains(@class, "is-selected") and contains(text(), 'Columns')]`
);
await page.keyboard.press( 'Enter' );
await page.click( ':focus [aria-label="Two columns; equal split"]' );
await page.click( ':focus .block-editor-button-block-appender' );
await page.waitForSelector( '.block-editor-inserter__search input:focus' );
await page.keyboard.type( 'Paragraph' );
await pressKeyTimes( 'Tab', 2 ); // Tab to paragraph result.
await page.keyboard.press( 'Enter' ); // Insert paragraph.
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.
// TODO: ArrowDown should traverse into the second column. In slower
// CPUs, it can sometimes remain in the first column paragraph. This
// is a temporary solution.
await page.focus( '.wp-block[data-type="core/column"]:nth-child(2)' );
await page.click( ':focus .block-editor-button-block-appender' );
await page.waitForSelector( '.block-editor-inserter__search input:focus' );
await page.keyboard.type( 'Paragraph' );
await pressKeyTimes( 'Tab', 2 ); // Tab to paragraph result.
await page.keyboard.press( 'Enter' ); // Insert paragraph.
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.
// Arrow down from last of layouts exits nested context to default
// appender of root level.
await page.keyboard.press( 'ArrowDown' );
await page.keyboard.type( 'Second paragraph' );
};
describe( 'Writing Flow', () => {
beforeEach( async () => {
await createNewPost();
} );
it( 'Should navigate inner blocks with arrow keys', async () => {
// TODO: The `waitForSelector` calls in this function should ultimately
// not be necessary for interactions, and exist as a stop-gap solution
// where rendering delays in slower CPU can cause intermittent failure.
// Assertions are made both against the active DOM element and the
// editor state, in order to protect against potential disparities.
//
// See: https://github.com/WordPress/gutenberg/issues/18928
let activeElementText, activeBlockName;
// Add demo content
await addParagraphsAndColumnsDemo();
// Arrow up into nested context focuses last text input
await page.keyboard.press( 'ArrowUp' );
activeBlockName = await getActiveBlockName();
expect( activeBlockName ).toBe( 'core/paragraph' );
activeElementText = await page.evaluate(
() => document.activeElement.textContent
);
expect( activeElementText ).toBe( '2nd col' );
// Arrow up in inner blocks should navigate through (1) column wrapper,
// (2) text fields.
await page.keyboard.press( 'ArrowUp' );
activeBlockName = await getActiveBlockName();
expect( activeBlockName ).toBe( 'core/column' );
await page.keyboard.press( 'ArrowUp' );
const activeElementBlockType = await page.evaluate( () =>
document.activeElement.getAttribute( 'data-type' )
);
expect( activeElementBlockType ).toBe( 'core/columns' );
activeBlockName = await getActiveBlockName();
expect( activeBlockName ).toBe( 'core/columns' );
// Arrow up from focused (columns) block wrapper exits nested context
// to prior text input.
await page.keyboard.press( 'ArrowUp' );
activeBlockName = await getActiveBlockName();
expect( activeBlockName ).toBe( 'core/paragraph' );
activeElementText = await page.evaluate(
() => document.activeElement.textContent
);
expect( activeElementText ).toBe( 'First paragraph' );
expect( await getEditedPostContent() ).toMatchSnapshot();
} );
it( 'Should navigate between inner and root blocks in navigation mode', async () => {
// In navigation mode the active element is the block name button, so we can't easily check the block content.
let activeBlockName;
// Add demo content
await addParagraphsAndColumnsDemo();
// Switch to navigation mode
await page.keyboard.press( 'Escape' );
// Arrow up to Columns block
await page.keyboard.press( 'ArrowUp' );
activeBlockName = await getActiveBlockName();
expect( activeBlockName ).toBe( 'core/columns' );
// Arrow right into Column block
await page.keyboard.press( 'ArrowRight' );
activeBlockName = await getActiveBlockName();
expect( activeBlockName ).toBe( 'core/column' );
// Arrow down to reach second Column block
await page.keyboard.press( 'ArrowDown' );
// Arrow right again into Paragraph block
await page.keyboard.press( 'ArrowRight' );
activeBlockName = await getActiveBlockName();
expect( activeBlockName ).toBe( 'core/paragraph' );
// Arrow left back to Column block
await page.keyboard.press( 'ArrowLeft' );
activeBlockName = await getActiveBlockName();
expect( activeBlockName ).toBe( 'core/column' );
// Arrow left back to Columns block
await page.keyboard.press( 'ArrowLeft' );
activeBlockName = await getActiveBlockName();
expect( activeBlockName ).toBe( 'core/columns' );
// Arrow up to first paragraph
await page.keyboard.press( 'ArrowUp' );
activeBlockName = await getActiveBlockName();
expect( activeBlockName ).toBe( 'core/paragraph' );
} );
it( 'should navigate around inline boundaries', async () => {
// Add demo content
await clickBlockAppender();
await page.keyboard.type( 'First' );
await page.keyboard.press( 'Enter' );
await page.keyboard.type( 'Second' );
await page.keyboard.press( 'Enter' );
await page.keyboard.type( 'Third' );
// Navigate to second paragraph
await pressKeyTimes( 'ArrowLeft', 6 );
// Bold second paragraph text
await page.keyboard.down( 'Shift' );
await pressKeyTimes( 'ArrowLeft', 6 );
await page.keyboard.up( 'Shift' );
await pressKeyWithModifier( 'primary', 'b' );
// Arrow left from selected bold should collapse to before the inline
// boundary. Arrow once more to traverse into first paragraph.
await page.keyboard.press( 'ArrowLeft' );
await page.keyboard.press( 'ArrowLeft' );
await page.keyboard.type( 'After' );
// Arrow right from end of first should traverse to second, *BEFORE*
// the bolded text. Another press should move within inline boundary.
await pressKeyTimes( 'ArrowRight', 2 );
await page.keyboard.type( 'Inside' );
// Arrow left from end of beginning of inline boundary should move to
// the outside of the inline boundary.
await pressKeyTimes( 'ArrowLeft', 6 );
await page.keyboard.press( 'ArrowLeft' ); // Separate for emphasis.
await page.keyboard.type( 'Before' );
// Likewise, test at the end of the inline boundary for same effect.
await page.keyboard.press( 'ArrowRight' ); // Move inside
await pressKeyTimes( 'ArrowRight', 12 );
await page.keyboard.type( 'Inside' );
await page.keyboard.press( 'ArrowRight' );
// Edge case: Verify that workaround to test for ZWSP at beginning of
// focus node does not take effect when on the right edge of inline
// boundary (thus preventing traversing to the next block by arrow).
await page.keyboard.press( 'ArrowRight' );
await page.keyboard.press( 'ArrowLeft' );
// Should be after the inline boundary again.
await page.keyboard.type( 'After' );
// Finally, ensure that ArrowRight from end of unbolded text moves to
// the last paragraph
await page.keyboard.press( 'ArrowRight' );
await page.keyboard.type( 'Before' );
expect( await getEditedPostContent() ).toMatchSnapshot();
} );
it( 'should navigate around nested inline boundaries', async () => {
await clickBlockAppender();
await pressKeyWithModifier( 'primary', 'b' );
await page.keyboard.type( '1 2' );
await page.keyboard.down( 'Shift' );
await page.keyboard.press( 'ArrowLeft' );
await page.keyboard.up( 'Shift' );
await pressKeyWithModifier( 'primary', 'i' );
await page.keyboard.press( 'ArrowLeft' );
await page.keyboard.press( 'ArrowLeft' );
await page.keyboard.down( 'Shift' );
await page.keyboard.press( 'ArrowLeft' );
await page.keyboard.up( 'Shift' );
await pressKeyWithModifier( 'primary', 'i' );
await page.keyboard.press( 'ArrowLeft' );
expect( await getEditedPostContent() ).toMatchSnapshot();
await page.keyboard.type( 'a' );
await page.keyboard.press( 'ArrowRight' );
await page.keyboard.type( 'b' );
await page.keyboard.press( 'ArrowRight' );
await page.keyboard.type( 'c' );
await page.keyboard.press( 'ArrowRight' );
await page.keyboard.type( 'd' );
await page.keyboard.press( 'ArrowRight' );
await page.keyboard.type( 'e' );
await page.keyboard.press( 'ArrowRight' );
await page.keyboard.type( 'f' );
await page.keyboard.press( 'ArrowRight' );
await page.keyboard.type( 'g' );
await page.keyboard.press( 'ArrowRight' );
await page.keyboard.type( 'h' );
await page.keyboard.press( 'ArrowRight' );
await page.keyboard.type( 'i' );
await page.keyboard.press( 'ArrowRight' );
await page.keyboard.type( 'j' );
expect( await getEditedPostContent() ).toMatchSnapshot();
} );
it( 'should insert line break at end', async () => {
await clickBlockAppender();
await page.keyboard.type( 'a' );
await pressKeyWithModifier( 'shift', 'Enter' );
expect( await getEditedPostContent() ).toMatchSnapshot();
} );
it( 'should insert line break at end and continue writing', async () => {
await clickBlockAppender();
await page.keyboard.type( 'a' );
await pressKeyWithModifier( 'shift', 'Enter' );
await page.keyboard.type( 'b' );
expect( await getEditedPostContent() ).toMatchSnapshot();
} );
it( 'should insert line break mid text', async () => {
await clickBlockAppender();
await page.keyboard.type( 'ab' );
await page.keyboard.press( 'ArrowLeft' );
await pressKeyWithModifier( 'shift', 'Enter' );
expect( await getEditedPostContent() ).toMatchSnapshot();
} );
it( 'should insert line break at start', async () => {
await clickBlockAppender();
await page.keyboard.type( 'a' );
await page.keyboard.press( 'ArrowLeft' );
await pressKeyWithModifier( 'shift', 'Enter' );
expect( await getEditedPostContent() ).toMatchSnapshot();
} );
it( 'should insert line break in empty container', async () => {
await clickBlockAppender();
await pressKeyWithModifier( 'shift', 'Enter' );
expect( await getEditedPostContent() ).toMatchSnapshot();
} );
it( 'should not create extra line breaks in multiline value', async () => {
await insertBlock( 'Quote' );
await page.keyboard.type( 'a' );
await page.keyboard.press( 'Backspace' );
expect( await getEditedPostContent() ).toMatchSnapshot();
} );
it( 'should navigate native inputs vertically, not horizontally', async () => {
// See: https://github.com/WordPress/gutenberg/issues/9626
await insertBlock( 'Shortcode' );
// Should remain in title upon ArrowRight:
await page.keyboard.press( 'ArrowRight' );
let isInShortcodeBlock = await page.evaluate(
() => !! document.activeElement.closest( '.wp-block-shortcode' )
);
expect( isInShortcodeBlock ).toBe( true );
// Should remain in title upon modifier + ArrowDown:
await pressKeyWithModifier( 'primary', 'ArrowDown' );
isInShortcodeBlock = await page.evaluate(
() => !! document.activeElement.closest( '.wp-block-shortcode' )
);
expect( isInShortcodeBlock ).toBe( true );
// Should navigate into blocks list upon ArrowDown:
await page.keyboard.press( 'ArrowDown' );
const isInParagraphBlock = await page.evaluate(
() => !! document.activeElement.closest( '.wp-block-paragraph' )
);
expect( isInParagraphBlock ).toBe( true );
} );
it( 'should not delete surrounding space when deleting a word with Backspace', async () => {
await clickBlockAppender();
await page.keyboard.type( '1 2 3' );
await pressKeyTimes( 'ArrowLeft', ' 3'.length );
await page.keyboard.press( 'Backspace' );
expect( await getEditedPostContent() ).toMatchSnapshot();
await page.keyboard.type( '2' );
expect( await getEditedPostContent() ).toMatchSnapshot();
} );
it( 'should not delete surrounding space when deleting a word with Alt+Backspace', async () => {
await clickBlockAppender();
await page.keyboard.type( 'alpha beta gamma' );
await pressKeyTimes( 'ArrowLeft', ' gamma'.length );
if ( process.platform === 'darwin' ) {
await pressKeyWithModifier( 'alt', 'Backspace' );
} else {
await pressKeyWithModifier( 'primary', 'Backspace' );
}
expect( await getEditedPostContent() ).toMatchSnapshot();
await page.keyboard.type( 'beta' );
expect( await getEditedPostContent() ).toMatchSnapshot();
} );
it( 'should not delete surrounding space when deleting a selected word', async () => {
await clickBlockAppender();
await page.keyboard.type( 'alpha beta gamma' );
await pressKeyTimes( 'ArrowLeft', ' gamma'.length );
await page.keyboard.down( 'Shift' );
await pressKeyTimes( 'ArrowLeft', 'beta'.length );
await page.keyboard.up( 'Shift' );
await page.keyboard.press( 'Backspace' );
expect( await getEditedPostContent() ).toMatchSnapshot();
await page.keyboard.type( 'beta' );
expect( await getEditedPostContent() ).toMatchSnapshot();
} );
it( 'should create valid paragraph blocks when rapidly pressing Enter', async () => {
await clickBlockAppender();
await pressKeyTimes( 'Enter', 10 );
// Check that none of the paragraph blocks have <br> in them.
expect( await getEditedPostContent() ).toMatchSnapshot();
} );
it( 'should navigate empty paragraph', async () => {
await clickBlockAppender();
await page.keyboard.press( 'Enter' );
await page.keyboard.press( 'ArrowLeft' );
await page.keyboard.type( '1' );
await page.keyboard.press( 'ArrowRight' );
await page.keyboard.type( '2' );
expect( await getEditedPostContent() ).toMatchSnapshot();
} );
it( 'should navigate contenteditable with padding', async () => {
await clickBlockAppender();
await page.keyboard.press( 'Enter' );
await page.evaluate( () => {
document.activeElement.style.paddingTop = '100px';
} );
await page.keyboard.press( 'ArrowUp' );
await page.keyboard.type( '1' );
await page.evaluate( () => {
document.activeElement.style.paddingBottom = '100px';
} );
await page.keyboard.press( 'ArrowDown' );
await page.keyboard.type( '2' );
expect( await getEditedPostContent() ).toMatchSnapshot();
} );
it( 'should navigate contenteditable with normal line height', async () => {
await clickBlockAppender();
await page.keyboard.press( 'Enter' );
await page.evaluate( () => {
document.activeElement.style.lineHeight = 'normal';
} );
await page.keyboard.press( 'ArrowUp' );
await page.keyboard.type( '1' );
expect( await getEditedPostContent() ).toMatchSnapshot();
} );
it( 'should not prematurely multi-select', async () => {
await clickBlockAppender();
await page.keyboard.type( '1' );
await page.keyboard.press( 'Enter' );
await page.keyboard.type( '><<' );
await pressKeyWithModifier( 'shift', 'Enter' );
await page.keyboard.type( '<<<' );
await page.keyboard.down( 'Shift' );
await pressKeyTimes( 'ArrowLeft', '<<\n<<<'.length );
await page.keyboard.up( 'Shift' );
await page.keyboard.press( 'Backspace' );
expect( await getEditedPostContent() ).toMatchSnapshot();
} );
it( 'should merge paragraphs', async () => {
await page.keyboard.press( 'Enter' );
await page.keyboard.type( '1' );
await page.keyboard.press( 'Enter' );
await page.keyboard.type( '2' );
await page.keyboard.press( 'ArrowLeft' );
await page.keyboard.press( 'Backspace' );
expect( await getEditedPostContent() ).toMatchSnapshot();
} );
it( 'should merge forwards', async () => {
await page.keyboard.press( 'Enter' );
await page.keyboard.type( '1' );
await page.keyboard.press( 'Enter' );
await page.keyboard.type( '3' );
await page.keyboard.press( 'ArrowUp' );
await page.keyboard.press( 'Delete' );
await page.keyboard.type( '2' );
expect( await getEditedPostContent() ).toMatchSnapshot();
} );
it( 'should preserve horizontal position when navigating vertically between blocks', async () => {
await page.keyboard.press( 'Enter' );
await page.keyboard.type( 'abc' );
await page.keyboard.press( 'Enter' );
await page.keyboard.type( '23' );
await page.keyboard.press( 'ArrowUp' );
await page.keyboard.press( 'ArrowLeft' );
await page.keyboard.press( 'ArrowLeft' );
await page.keyboard.press( 'ArrowDown' );
await page.keyboard.type( '1' );
expect( await getEditedPostContent() ).toMatchSnapshot();
} );
it( 'should remember initial vertical position', async () => {
await page.keyboard.press( 'Enter' );
await page.keyboard.type( '1' );
await page.keyboard.press( 'Enter' );
await pressKeyWithModifier( 'shift', 'Enter' );
await page.keyboard.type( '2' );
await page.keyboard.press( 'ArrowUp' );
await page.keyboard.press( 'ArrowUp' );
await page.keyboard.type( 'x' ); // Should be right after "1".
expect( await getEditedPostContent() ).toMatchSnapshot();
} );
it( 'should navigate contenteditable with side padding', async () => {
await clickBlockAppender();
await page.keyboard.press( 'Enter' );
await page.evaluate( () => {
document.activeElement.style.paddingLeft = '100px';
} );
await page.keyboard.press( 'Enter' );
await page.keyboard.press( 'ArrowUp' );
await page.keyboard.press( 'ArrowUp' );
await page.keyboard.type( '1' );
expect( await getEditedPostContent() ).toMatchSnapshot();
} );
it( 'should navigate empty paragraphs', async () => {
await page.keyboard.press( 'Enter' );
await page.keyboard.press( 'Enter' );
await page.keyboard.press( 'Enter' );
await page.keyboard.press( 'ArrowLeft' );
await page.keyboard.press( 'ArrowLeft' );
await page.keyboard.type( '1' );
await page.keyboard.press( 'ArrowRight' );
await page.keyboard.press( 'ArrowRight' );
await page.keyboard.type( '3' );
expect( await getEditedPostContent() ).toMatchSnapshot();
} );
it( 'should allow selecting entire list with longer last item', async () => {
await page.keyboard.press( 'Enter' );
await page.keyboard.type( 'a' );
await page.keyboard.press( 'Enter' );
await page.keyboard.type( '* b' );
await page.keyboard.press( 'Enter' );
await page.keyboard.type( 'cd' );
await pressKeyWithModifier( 'shift', 'ArrowUp' );
await pressKeyWithModifier( 'shift', 'ArrowUp' );
// Ensure multi selection is not triggered and selection stays within
// the list.
await page.keyboard.press( 'Backspace' );
expect( await getEditedPostContent() ).toMatchSnapshot();
} );
it( 'should not have a dead zone between blocks (lower)', async () => {
await page.keyboard.press( 'Enter' );
await page.keyboard.type( '1' );
await page.keyboard.press( 'Enter' );
await page.keyboard.type( '2' );
await page.keyboard.press( 'ArrowUp' );
// Find a point outside the paragraph between the blocks where it's
// expected that the sibling inserter would be placed.
const paragraph = await page.$( '[data-type="core/paragraph"]' );
const paragraphRect = await paragraph.boundingBox();
const x = paragraphRect.x + ( 2 * paragraphRect.width ) / 3;
const y = paragraphRect.y + paragraphRect.height + 1;
await page.mouse.move( x, y );
await page.waitForSelector(
'.block-editor-block-list__insertion-point'
);
const inserter = await page.$(
'.block-editor-block-list__insertion-point'
);
const inserterRect = await inserter.boundingBox();
const lowerInserterY = inserterRect.y + ( 2 * inserterRect.height ) / 3;
await page.mouse.click( x, lowerInserterY );
await page.keyboard.type( '3' );
expect( await getEditedPostContent() ).toMatchSnapshot();
} );
it( 'should not have a dead zone above an aligned block', async () => {
await page.keyboard.press( 'Enter' );
await page.keyboard.type( '1' );
await page.keyboard.press( 'Enter' );
await page.keyboard.type( '/image' );
await page.keyboard.press( 'Enter' );
await clickBlockToolbarButton( 'Align' );
const wideButton = await page.waitForXPath(
`//button[contains(@class,'components-dropdown-menu__menu-item')]//span[contains(text(), 'Wide width')]`
);
await wideButton.click();
// Select the previous block.
await page.keyboard.press( 'ArrowUp' );
// Confirm correct setup.
expect( await getEditedPostContent() ).toMatchSnapshot();
// Find a point outside the paragraph between the blocks where it's
// expected that the sibling inserter would be placed.
const paragraph = await page.$( '[data-type="core/paragraph"]' );
const paragraphRect = await paragraph.boundingBox();
const x = paragraphRect.x + ( 2 * paragraphRect.width ) / 3;
const y = paragraphRect.y + paragraphRect.height + 1;
await page.mouse.move( x, y );
await page.waitForSelector(
'.block-editor-block-list__insertion-point'
);
const inserter = await page.$(
'.block-editor-block-list__insertion-point'
);
const inserterRect = await inserter.boundingBox();
const lowerInserterY = inserterRect.y + ( 2 * inserterRect.height ) / 3;
await page.mouse.click( x, lowerInserterY );
const type = await page.evaluate( () =>
document.activeElement.getAttribute( 'data-type' )
);
expect( type ).toBe( 'core/image' );
} );
it( 'should only consider the content as one tab stop', async () => {
await page.keyboard.press( 'Enter' );
await page.keyboard.type( '/table' );
await page.keyboard.press( 'Enter' );
// Move into the placeholder UI.
await page.keyboard.press( 'ArrowDown' );
// Tab to the "Create table" button.
await page.keyboard.press( 'Tab' );
await page.keyboard.press( 'Tab' );
// Create the table.
await page.keyboard.press( 'Space' );
// Return focus after focus loss. This should be fixed.
await page.keyboard.press( 'Tab' );
// Navigate to the second cell.
await page.keyboard.press( 'ArrowRight' );
await page.keyboard.type( '2' );
// Confirm correct setup.
expect( await getEditedPostContent() ).toMatchSnapshot();
// The content should only have one tab stop.
await page.keyboard.press( 'Tab' );
expect(
await page.evaluate( () =>
document.activeElement.getAttribute( 'aria-label' )
)
).toBe( 'Post' );
await pressKeyWithModifier( 'shift', 'Tab' );
await pressKeyWithModifier( 'shift', 'Tab' );
expect(
await page.evaluate( () =>
document.activeElement.getAttribute( 'aria-label' )
)
).toBe( 'Table' );
} );
it( 'Should unselect all blocks when hitting double escape', async () => {
// Add demo content.
await page.keyboard.press( 'Enter' );
await page.keyboard.type( 'Random Paragraph' );
// Select a block.
let activeBlockName = await getActiveBlockName();
expect( activeBlockName ).toBe( 'core/paragraph' );
// First escape enters navigaiton mode.
await page.keyboard.press( 'Escape' );
activeBlockName = await getActiveBlockName();
expect( activeBlockName ).toBe( 'core/paragraph' );
// Second escape unselects the blocks.
await page.keyboard.press( 'Escape' );
activeBlockName = await getActiveBlockName();
expect( activeBlockName ).toBe( undefined );
} );
} );