-
Notifications
You must be signed in to change notification settings - Fork 4.2k
/
inserting-blocks.spec.js
773 lines (655 loc) · 21.4 KB
/
inserting-blocks.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
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
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
/**
* External dependencies
*/
const path = require( 'path' );
/**
* WordPress dependencies
*/
const { test, expect } = require( '@wordpress/e2e-test-utils-playwright' );
test.use( {
insertingBlocksUtils: async ( { page, editor }, use ) => {
await use( new InsertingBlocksUtils( { page, editor } ) );
},
} );
test.describe( 'Inserting blocks (@firefox, @webkit)', () => {
test.afterAll( async ( { requestUtils } ) => {
await requestUtils.deleteAllPosts();
await requestUtils.deleteAllBlocks();
await requestUtils.deleteAllPatternCategories();
} );
test.afterEach( async ( { requestUtils } ) => {
await requestUtils.deleteAllBlocks();
await requestUtils.deleteAllPatternCategories();
} );
test( 'inserts a default block on bottom padding click', async ( {
admin,
editor,
} ) => {
await admin.createNewPost();
await editor.insertBlock( { name: 'core/image' } );
const body = editor.canvas.locator( 'body' );
const box = await body.boundingBox();
await body.click( {
position: {
x: box.width / 2,
y: box.height - 10,
},
} );
expect( await editor.getBlocks() ).toMatchObject( [
{ name: 'core/image' },
{ name: 'core/paragraph' },
] );
} );
test( 'inserts blocks by dragging and dropping from the global inserter', async ( {
admin,
page,
editor,
insertingBlocksUtils,
}, testInfo ) => {
testInfo.fixme(
testInfo.project.name === 'firefox',
'The clientX value is always 0 in firefox, see https://github.com/microsoft/playwright/issues/17761 for more info.'
);
await admin.createNewPost();
await editor.switchToLegacyCanvas();
// We need a dummy block in place to display the drop indicator due to a bug.
// @see https://github.com/WordPress/gutenberg/issues/44064
await editor.insertBlock( {
name: 'core/paragraph',
attributes: { content: 'Dummy text' },
} );
const paragraphBlock = page.locator(
'[data-type="core/paragraph"] >> text=Dummy text'
);
await page.click(
'role=region[name="Editor top bar"i] >> role=button[name="Toggle block inserter"i]'
);
await page.fill(
'role=region[name="Block Library"i] >> role=searchbox[name="Search for blocks and patterns"i]',
'Heading'
);
await page.hover(
'role=listbox[name="Blocks"i] >> role=option[name="Heading"i]'
);
const paragraphBoundingBox = await paragraphBlock.boundingBox();
await expect( insertingBlocksUtils.indicator ).toBeVisible();
await insertingBlocksUtils.expectIndicatorBelowParagraph(
paragraphBoundingBox
);
await page.mouse.down();
await insertingBlocksUtils.dragOver( paragraphBoundingBox );
await insertingBlocksUtils.expectIndicatorBelowParagraph(
paragraphBoundingBox
);
// Expect the draggable-chip to appear.
await expect( insertingBlocksUtils.draggableChip ).toBeVisible();
await page.mouse.up();
await expect.poll( editor.getEditedPostContent )
.toBe( `<!-- wp:paragraph -->
<p>Dummy text</p>
<!-- /wp:paragraph -->
<!-- wp:heading -->
<h2 class="wp-block-heading"></h2>
<!-- /wp:heading -->` );
} );
test( 'cancels dragging blocks from the global inserter by pressing Escape', async ( {
admin,
page,
editor,
insertingBlocksUtils,
} ) => {
await admin.createNewPost();
await editor.switchToLegacyCanvas();
// We need a dummy block in place to display the drop indicator due to a bug.
// @see https://github.com/WordPress/gutenberg/issues/44064
await editor.insertBlock( {
name: 'core/paragraph',
attributes: { content: 'Dummy text' },
} );
const beforeContent = await editor.getEditedPostContent();
const paragraphBlock = page.locator(
'[data-type="core/paragraph"] >> text=Dummy text'
);
await page.click(
'role=region[name="Editor top bar"i] >> role=button[name="Toggle block inserter"i]'
);
await page.fill(
'role=region[name="Block Library"i] >> role=searchbox[name="Search for blocks and patterns"i]',
'Heading'
);
await page.hover(
'role=listbox[name="Blocks"i] >> role=option[name="Heading"i]'
);
const paragraphBoundingBox = await paragraphBlock.boundingBox();
await page.mouse.down();
await insertingBlocksUtils.dragOver( paragraphBoundingBox );
await expect( insertingBlocksUtils.indicator ).toBeVisible();
await expect( insertingBlocksUtils.draggableChip ).toBeVisible();
await page.keyboard.press( 'Escape' );
await expect( insertingBlocksUtils.indicator ).toBeHidden();
await expect( insertingBlocksUtils.draggableChip ).toBeHidden();
await page.mouse.up();
await expect.poll( editor.getEditedPostContent ).toBe( beforeContent );
} );
test( 'inserts patterns by dragging and dropping from the global inserter', async ( {
admin,
page,
editor,
insertingBlocksUtils,
}, testInfo ) => {
testInfo.fixme(
testInfo.project.name === 'firefox',
'The clientX value is always 0 in firefox, see https://github.com/microsoft/playwright/issues/17761 for more info.'
);
await admin.createNewPost();
await editor.switchToLegacyCanvas();
// We need a dummy block in place to display the drop indicator due to a bug.
// @see https://github.com/WordPress/gutenberg/issues/44064
await editor.insertBlock( {
name: 'core/paragraph',
attributes: { content: 'Dummy text' },
} );
const paragraphBlock = page.locator(
'[data-type="core/paragraph"] >> text=Dummy text'
);
await page.click(
'role=region[name="Editor top bar"i] >> role=button[name="Toggle block inserter"i]'
);
const PATTERN_NAME = 'Social links with a shared background color';
await page.fill(
'role=region[name="Block Library"i] >> role=searchbox[name="Search for blocks and patterns"i]',
PATTERN_NAME
);
await page.hover(
`role=listbox[name="Block Patterns"i] >> role=option[name="${ PATTERN_NAME }"i]`
);
// FIXME: I think we should show the indicator when hovering on patterns as well?
// @see https://github.com/WordPress/gutenberg/issues/45183
// await expect( insertingBlocksUtils.indicator ).toBeVisible();
const paragraphBoundingBox = await paragraphBlock.boundingBox();
await page.mouse.down();
await insertingBlocksUtils.dragOver( paragraphBoundingBox );
await expect( insertingBlocksUtils.indicator ).toBeVisible();
await insertingBlocksUtils.expectIndicatorBelowParagraph(
paragraphBoundingBox
);
await expect( insertingBlocksUtils.draggableChip ).toBeVisible();
await page.mouse.up();
expect( await editor.getEditedPostContent() ).toMatchSnapshot();
} );
test( 'inserts synced patterns by dragging and dropping from the global inserter', async ( {
admin,
page,
editor,
insertingBlocksUtils,
}, testInfo ) => {
testInfo.fixme(
testInfo.project.name === 'firefox',
'The clientX value is always 0 in firefox, see https://github.com/microsoft/playwright/issues/17761 for more info.'
);
const PATTERN_NAME = 'My synced pattern';
await admin.createNewPost();
await editor.switchToLegacyCanvas();
// We need a dummy block in place to display the drop indicator due to a bug.
// @see https://github.com/WordPress/gutenberg/issues/44064
await editor.insertBlock( {
name: 'core/paragraph',
attributes: { content: 'Dummy text' },
} );
const paragraphBlock = page.locator(
'[data-type="core/paragraph"] >> text=Dummy text'
);
// Create a synced pattern from the paragraph block.
await editor.insertBlock( {
name: 'core/paragraph',
attributes: { content: 'A useful paragraph to reuse' },
} );
await editor.showBlockToolbar();
await page
.getByRole( 'toolbar', { name: 'Block tools' } )
.getByRole( 'button', { name: 'Options' } )
.click();
await page.getByRole( 'menuitem', { name: 'Create pattern' } ).click();
const createPatternDialog = page.getByRole( 'dialog', {
name: 'add new pattern',
} );
await createPatternDialog
.getByRole( 'textbox', { name: 'Name' } )
.fill( PATTERN_NAME );
await createPatternDialog
.getByRole( 'checkbox', { name: 'Synced' } )
.setChecked( true );
await createPatternDialog
.getByRole( 'button', { name: 'Add' } )
.click();
const patternBlock = page.getByRole( 'document', {
name: 'Block: Pattern',
} );
await expect( patternBlock ).toBeFocused();
// Insert a synced pattern.
await page.click(
'role=region[name="Editor top bar"i] >> role=button[name="Toggle block inserter"i]'
);
await page.fill(
'role=region[name="Block Library"i] >> role=searchbox[name="Search for blocks and patterns"i]',
PATTERN_NAME
);
await page.hover(
`role=listbox[name="Block Patterns"i] >> role=option[name="${ PATTERN_NAME }"i]`
);
const paragraphBoundingBox = await paragraphBlock.boundingBox();
await page.mouse.down();
await insertingBlocksUtils.dragOver( paragraphBoundingBox );
await expect( insertingBlocksUtils.indicator ).toBeVisible();
await insertingBlocksUtils.expectIndicatorBelowParagraph(
paragraphBoundingBox
);
await expect( insertingBlocksUtils.draggableChip ).toBeVisible();
await page.mouse.up();
await expect.poll( editor.getBlocks ).toMatchObject( [
{
name: 'core/paragraph',
attributes: {
content: 'Dummy text',
},
},
{
name: 'core/block',
attributes: { ref: expect.any( Number ) },
},
{
name: 'core/block',
attributes: { ref: expect.any( Number ) },
},
] );
} );
test( 'cancels dragging patterns from the global inserter by pressing Escape', async ( {
admin,
page,
editor,
insertingBlocksUtils,
} ) => {
await admin.createNewPost();
await editor.switchToLegacyCanvas();
// We need a dummy block in place to display the drop indicator due to a bug.
// @see https://github.com/WordPress/gutenberg/issues/44064
await editor.insertBlock( {
name: 'core/paragraph',
attributes: { content: 'Dummy text' },
} );
const beforeContent = await editor.getEditedPostContent();
const paragraphBlock = page.locator(
'[data-type="core/paragraph"] >> text=Dummy text'
);
await page.click(
'role=region[name="Editor top bar"i] >> role=button[name="Toggle block inserter"i]'
);
const PATTERN_NAME = 'Social links with a shared background color';
await page.fill(
'role=region[name="Block Library"i] >> role=searchbox[name="Search for blocks and patterns"i]',
PATTERN_NAME
);
await page.hover(
`role=listbox[name="Block Patterns"i] >> role=option[name="${ PATTERN_NAME }"i]`
);
const paragraphBoundingBox = await paragraphBlock.boundingBox();
await page.mouse.down();
await insertingBlocksUtils.dragOver( paragraphBoundingBox );
await expect( insertingBlocksUtils.indicator ).toBeVisible();
await expect( insertingBlocksUtils.draggableChip ).toBeVisible();
await page.keyboard.press( 'Escape' );
await expect( insertingBlocksUtils.indicator ).toBeHidden();
await expect( insertingBlocksUtils.draggableChip ).toBeHidden();
await page.mouse.up();
await expect.poll( editor.getEditedPostContent ).toBe( beforeContent );
} );
// A test for https://github.com/WordPress/gutenberg/issues/43090.
test( 'should close the inserter when clicking on the toggle button', async ( {
admin,
page,
editor,
} ) => {
await admin.createNewPost();
const inserterButton = page.getByRole( 'button', {
name: 'Toggle block inserter',
} );
const blockLibrary = page.getByRole( 'region', {
name: 'Block Library',
} );
await inserterButton.click();
await blockLibrary.getByRole( 'option', { name: 'Buttons' } ).click();
await expect
.poll( editor.getBlocks )
.toMatchObject( [ { name: 'core/buttons' } ] );
await inserterButton.click();
await expect( blockLibrary ).toBeHidden();
} );
test( 'should insert block with the slash inserter when using multiple words', async ( {
admin,
editor,
page,
} ) => {
await admin.createNewPost();
await editor.canvas
.getByRole( 'button', { name: 'Add default block' } )
.click();
await page.keyboard.type( '/tag cloud' );
await expect(
page.getByRole( 'option', { name: 'Tag Cloud', selected: true } )
).toBeVisible();
await page.keyboard.press( 'Enter' );
await expect(
editor.canvas.getByRole( 'document', { name: 'Block: Tag Cloud' } )
).toBeVisible();
} );
// Check for regression of https://github.com/WordPress/gutenberg/issues/24262.
test( 'inserts a block in proper place after having clicked `Browse All` from inline inserter', async ( {
admin,
editor,
page,
} ) => {
await admin.createNewPost();
await editor.canvas
.getByRole( 'button', { name: 'Add default block' } )
.click();
await page.keyboard.type( 'First paragraph' );
await page.keyboard.press( 'Enter' );
await page.keyboard.type( '## Heading' );
await page.keyboard.press( 'Enter' );
await page.keyboard.type( 'Second paragraph' );
await page.keyboard.press( 'Enter' );
await page.keyboard.type( 'Third paragraph' );
const boundingBox = await editor.canvas
.getByRole( 'document', { name: 'Block: Heading' } )
.boundingBox();
// Using the between inserter.
await page.mouse.move(
boundingBox.x + boundingBox.width / 2,
boundingBox.y - 10,
// An arbitrary number of `steps` imitates cursor movement in the test environment,
// activating the in-between inserter.
{ steps: 10 }
);
await page
.getByRole( 'button', {
name: 'Add block',
} )
.click();
await page.getByRole( 'button', { name: 'Browse All' } ).click();
await page
.getByRole( 'listbox', { name: 'Media' } )
.getByRole( 'option', { name: 'Image' } )
.click();
await expect
.poll( editor.getBlocks )
.toMatchObject( [
{ name: 'core/paragraph' },
{ name: 'core/image' },
{ name: 'core/heading' },
{ name: 'core/paragraph' },
{ name: 'core/paragraph' },
] );
} );
// Check for regression of https://github.com/WordPress/gutenberg/issues/25785.
test( 'inserts a block should show a blue line indicator', async ( {
admin,
editor,
page,
insertingBlocksUtils,
} ) => {
await admin.createNewPost();
await editor.canvas
.getByRole( 'button', { name: 'Add default block' } )
.click();
await page.keyboard.type( 'First paragraph' );
await editor.insertBlock( { name: 'core/image' } );
const paragraphBlock = editor.canvas.getByRole( 'document', {
name: 'Block: Paragraph',
} );
await editor.selectBlocks( paragraphBlock );
await page
.getByRole( 'toolbar', { name: 'Document tools' } )
.getByRole( 'button', { name: 'Toggle block inserter' } )
.click();
await page
.getByRole( 'listbox', { name: 'Text' } )
.getByRole( 'option', { name: 'Heading' } )
.hover();
await expect( insertingBlocksUtils.indicator ).toBeVisible();
const paragraphBoundingBox = await paragraphBlock.boundingBox();
const indicatorBoundingBox =
await insertingBlocksUtils.indicator.boundingBox();
// Expect the indicator to be below the selected block.
expect( indicatorBoundingBox.y ).toBeGreaterThan(
paragraphBoundingBox.y
);
} );
// Check for regression of https://github.com/WordPress/gutenberg/issues/24403.
test( 'inserts a block in proper place after having clicked `Browse All` from block appender', async ( {
admin,
editor,
page,
} ) => {
await admin.createNewPost();
await editor.insertBlock( { name: 'core/group' } );
await editor.insertBlock( {
name: 'core/paragraph',
attributes: { content: 'Paragraph after group' },
} );
await editor.canvas
.getByRole( 'button', {
name: 'Group: Gather blocks in a container.',
} )
.click();
await editor.canvas
.getByRole( 'button', {
name: 'Add block',
} )
.click();
await page.getByRole( 'button', { name: 'Browse All' } ).click();
await page
.getByRole( 'listbox', { name: 'Text' } )
.getByRole( 'option', { name: 'Paragraph' } )
.click();
await editor.canvas
.getByRole( 'document', { name: 'Empty block' } )
.fill( 'Paragraph inside group' );
await expect.poll( editor.getBlocks ).toMatchObject( [
{
name: 'core/group',
innerBlocks: [
{
name: 'core/paragraph',
attributes: { content: 'Paragraph inside group' },
},
],
},
{
name: 'core/paragraph',
attributes: { content: 'Paragraph after group' },
},
] );
} );
test( 'passes the search value in the main inserter when clicking `Browse all`', async ( {
admin,
editor,
page,
} ) => {
await admin.createNewPost();
await editor.insertBlock( { name: 'core/group' } );
await editor.insertBlock( {
name: 'core/paragraph',
attributes: { content: 'Paragraph after group' },
} );
await editor.canvas
.getByRole( 'button', {
name: 'Group: Gather blocks in a container.',
} )
.click();
await editor.canvas
.getByRole( 'button', {
name: 'Add block',
} )
.click();
await page
.getByRole( 'searchbox', {
name: 'Search for blocks and patterns',
} )
.first()
.fill( 'Verse' );
await page.getByRole( 'button', { name: 'Browse All' } ).click();
await expect(
page
.getByRole( 'region', { name: 'Block Library' } )
.getByRole( 'searchbox', {
name: 'Search for blocks and patterns',
} )
.first()
).toHaveValue( 'Verse' );
await expect(
page.getByRole( 'listbox', { name: 'Blocks' } ).first()
).toHaveCount( 1 );
} );
// Check for regression of https://github.com/WordPress/gutenberg/issues/27586.
test( 'can close the main inserter after inserting a single-use block, like the More block', async ( {
admin,
editor,
page,
} ) => {
await admin.createNewPost();
await page
.getByRole( 'toolbar', { name: 'Document tools' } )
.getByRole( 'button', { name: 'Toggle block inserter' } )
.click();
await page.getByRole( 'option', { name: 'More', exact: true } ).click();
// Moving focus to the More block should not close the inserter.
await editor.canvas
.getByRole( 'textbox', { name: 'Read more' } )
.fill( 'More' );
await expect(
page.getByRole( 'region', {
name: 'Block Library',
} )
).toBeVisible();
} );
test( 'shows block preview when hovering over block in inserter', async ( {
admin,
page,
} ) => {
await admin.createNewPost();
await page
.getByRole( 'toolbar', { name: 'Document tools' } )
.getByRole( 'button', { name: 'Toggle block inserter' } )
.click();
await page
.getByRole( 'listbox', { name: 'Text' } )
.getByRole( 'option', { name: 'Paragraph' } )
.hover();
await expect(
page.locator( '.block-editor-inserter__preview' )
).toBeInViewport();
} );
[ 'large', 'small' ].forEach( ( viewport ) => {
test( `last-inserted block should be given and keep the selection (${ viewport } viewport)`, async ( {
admin,
editor,
page,
pageUtils,
} ) => {
await pageUtils.setBrowserViewport( viewport );
await admin.createNewPost();
await editor.insertBlock( {
name: 'core/paragraph',
attributes: { content: 'Testing inserted block selection' },
} );
await page
.getByRole( 'toolbar', { name: 'Document tools' } )
.getByRole( 'button', { name: 'Toggle block inserter' } )
.click();
await page
.getByRole( 'listbox', { name: 'Media' } )
.getByRole( 'option', { name: 'Image' } )
.click();
await expect(
editor.canvas.getByRole( 'document', { name: 'Block: Image' } )
).toBeVisible();
await expect
.poll( () =>
page.evaluate(
() =>
window.wp.data
.select( 'core/block-editor' )
.getSelectedBlock()?.name
)
)
.toBe( 'core/image' );
// Restore the viewport.
await pageUtils.setBrowserViewport( 'large' );
} );
} );
} );
test.describe( 'insert media from inserter', () => {
let uploadedMedia;
test.beforeAll( async ( { requestUtils } ) => {
await requestUtils.deleteAllMedia();
uploadedMedia = await requestUtils.uploadMedia(
path.resolve(
process.cwd(),
'test/e2e/assets/10x10_e2e_test_image_z9T8jK.png'
)
);
} );
test.afterAll( async ( { requestUtils } ) => {
await Promise.all( [
requestUtils.deleteAllMedia(),
requestUtils.deleteAllPosts(),
] );
} );
test( 'insert media from the global inserter', async ( {
admin,
page,
editor,
} ) => {
await admin.createNewPost();
await page.getByLabel( 'Toggle block inserter' ).click();
await page.getByRole( 'tab', { name: 'Media' } ).click();
await page.getByRole( 'tab', { name: 'Images' } ).click();
await page.getByLabel( uploadedMedia.title.raw ).click();
await expect.poll( editor.getEditedPostContent ).toBe(
`<!-- wp:image {"id":${ uploadedMedia.id }} -->
<figure class="wp-block-image"><img src="${ uploadedMedia.source_url }" alt="${ uploadedMedia.alt_text }" class="wp-image-${ uploadedMedia.id }"/></figure>
<!-- /wp:image -->`
);
} );
} );
class InsertingBlocksUtils {
constructor( { page, editor } ) {
this.page = page;
this.editor = editor;
this.indicator = this.page.locator(
'data-testid=block-list-insertion-point-indicator'
);
this.draggableChip = this.page.locator(
'data-testid=block-draggable-chip >> visible=true'
);
}
async dragOver( boundingBox ) {
// Call the move function twice to make sure the `dragOver` event is sent.
// @see https://github.com/microsoft/playwright/issues/17153
for ( let i = 0; i < 2; i += 1 ) {
await this.page.mouse.move(
// Hover on the right side of the block to avoid collapsing with the preview.
// But not too far to avoid triggering the grouping block inserter.
boundingBox.x + boundingBox.width - 32,
// Hover on the bottom of the paragraph block.
boundingBox.y + boundingBox.height - 1
);
}
}
async expectIndicatorBelowParagraph( paragraphBoundingBox ) {
// Expect the indicator to be below the paragraph block.
await expect
.poll( () => this.indicator.boundingBox().then( ( { y } ) => y ) )
.toBeGreaterThan( paragraphBoundingBox.y );
}
}