-
Notifications
You must be signed in to change notification settings - Fork 4.1k
/
customizing-widgets.test.js
926 lines (778 loc) · 22.4 KB
/
customizing-widgets.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
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
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
/**
* WordPress dependencies
*/
import {
__experimentalActivatePlugin as activatePlugin,
activateTheme,
__experimentalDeactivatePlugin as deactivatePlugin,
visitAdminPage,
showBlockToolbar,
clickBlockToolbarButton,
deleteAllWidgets,
createURL,
} from '@wordpress/e2e-test-utils';
/**
* External dependencies
*/
// eslint-disable-next-line no-restricted-imports
import { find, findAll } from 'puppeteer-testing-library';
import { first } from 'lodash';
const twentyTwentyError = `Stylesheet twentytwenty-block-editor-styles-css was not properly added.
For blocks, use the block API's style (https://developer.wordpress.org/block-editor/reference-guides/block-api/block-metadata/#style) or editorStyle (https://developer.wordpress.org/block-editor/reference-guides/block-api/block-metadata/#editor-style).
For themes, use add_editor_style (https://developer.wordpress.org/block-editor/how-to-guides/themes/theme-support/#editor-styles).`;
describe( 'Widgets Customizer', () => {
beforeEach( async () => {
await deleteAllWidgets();
await visitAdminPage( 'customize.php' );
// Disable welcome guide if it is enabled.
const isWelcomeGuideActive = await page.evaluate( () =>
wp.data
.select( 'core/interface' )
.isFeatureActive( 'core/customize-widgets', 'welcomeGuide' )
);
if ( isWelcomeGuideActive ) {
await page.evaluate( () =>
wp.data
.dispatch( 'core/interface' )
.toggleFeature( 'core/customize-widgets', 'welcomeGuide' )
);
}
} );
beforeAll( async () => {
// TODO: Ideally we can bundle our test theme directly in the repo.
await activateTheme( 'twentytwenty' );
await deactivatePlugin(
'gutenberg-test-plugin-disables-the-css-animations'
);
// Disable the transition timing function to make it "snap".
// We can't disable all the transitions yet because of #32024.
await page.evaluateOnNewDocument( () => {
const style = document.createElement( 'style' );
style.innerHTML = `
* {
transition-timing-function: step-start !important;
animation-timing-function: step-start !important;
}
`;
window.addEventListener( 'DOMContentLoaded', () => {
document.head.appendChild( style );
} );
} );
await activatePlugin( 'gutenberg-test-widgets' );
} );
afterAll( async () => {
await activatePlugin(
'gutenberg-test-plugin-disables-the-css-animations'
);
await deactivatePlugin( 'gutenberg-test-widgets' );
await activateTheme( 'twentytwentyone' );
} );
it( 'should add blocks', async () => {
const widgetsPanel = await find( {
role: 'heading',
name: /Widgets/,
level: 3,
} );
await widgetsPanel.click();
const footer1Section = await find( {
role: 'heading',
name: /Footer #1/,
level: 3,
} );
await footer1Section.click();
await addBlock( 'Paragraph' );
await page.keyboard.type( 'First Paragraph' );
await waitForPreviewIframe();
await addBlock( 'Heading' );
await page.keyboard.type( 'My Heading' );
const inlineAddBlockButton = await find( {
role: 'combobox',
name: 'Add block',
haspopup: 'menu',
} );
await inlineAddBlockButton.click();
const inlineInserterSearchBox = await find( {
role: 'searchbox',
name: 'Search for blocks and patterns',
} );
await expect( inlineInserterSearchBox ).toHaveFocus();
await page.keyboard.type( 'Search' );
const searchOption = await find( {
role: 'option',
name: 'Search',
} );
await searchOption.click();
const addedSearchBlock = await find( {
role: 'document',
name: 'Block: Search',
} );
const searchTitle = await find(
{
role: 'textbox',
name: 'Label text',
},
{ root: addedSearchBlock }
);
await searchTitle.focus();
await page.keyboard.type( 'My ' );
await waitForPreviewIframe();
const findOptions = {
root: await find( {
name: 'Site Preview',
selector: 'iframe',
} ),
};
// Expect the paragraph to be found in the preview iframe.
await expect( {
text: 'First Paragraph',
selector: '.widget-content p',
} ).toBeFound( findOptions );
// Expect the heading to be found in the preview iframe.
await expect( {
role: 'heading',
name: 'My Heading',
selector: '.widget-content *',
} ).toBeFound( findOptions );
// Expect the search box to be found in the preview iframe.
await expect( {
role: 'searchbox',
name: 'My Search',
selector: '.widget-content *',
} ).toBeFound( findOptions );
expect( console ).toHaveErrored( twentyTwentyError );
} );
it( 'should open the inspector panel', async () => {
const widgetsPanel = await find( {
role: 'heading',
name: /Widgets/,
level: 3,
} );
await widgetsPanel.click();
const footer1Section = await find( {
role: 'heading',
name: /Footer #1/,
level: 3,
} );
await footer1Section.click();
await addBlock( 'Paragraph' );
await page.keyboard.type( 'First Paragraph' );
await showBlockToolbar();
await clickBlockToolbarButton( 'Options' );
let showMoreSettingsButton = await find( {
role: 'menuitem',
name: 'Show more settings',
} );
await showMoreSettingsButton.click();
const backButton = await find( {
role: 'button',
name: 'Back',
focused: true,
} );
await expect( backButton ).toHaveFocus();
// Expect the inspector panel to be found.
let inspectorHeading = await find( {
role: 'heading',
name: 'Customizing ▸ Widgets ▸ Footer #1 Block Settings',
level: 3,
} );
// Expect the block title to be found.
await expect( {
role: 'heading',
name: 'Paragraph',
level: 2,
} ).toBeFound();
await backButton.click();
// Go back to the widgets editor.
await find( {
role: 'heading',
name: 'Customizing ▸ Widgets Footer #1',
level: 3,
} );
await expect( inspectorHeading ).not.toBeVisible();
await clickBlockToolbarButton( 'Options' );
showMoreSettingsButton = await find( {
role: 'menuitem',
name: 'Show more settings',
} );
await showMoreSettingsButton.click();
// Expect the inspector panel to be found.
inspectorHeading = await find( {
role: 'heading',
name: 'Customizing ▸ Widgets ▸ Footer #1 Block Settings',
level: 3,
} );
// Press Escape to close the inspector panel.
await page.keyboard.press( 'Escape' );
// Go back to the widgets editor.
await expect( {
role: 'heading',
name: 'Customizing ▸ Widgets Footer #1',
level: 3,
} ).toBeFound();
await expect( inspectorHeading ).not.toBeVisible();
expect( console ).toHaveErrored( twentyTwentyError );
} );
it( 'should handle the inserter outer section', async () => {
const widgetsPanel = await find( {
role: 'heading',
name: /Widgets/,
level: 3,
} );
await widgetsPanel.click();
const footer1Section = await find( {
role: 'heading',
name: /^Footer #1/,
level: 3,
} );
await footer1Section.click();
// We need to make some changes for the publish settings to appear.
await addBlock( 'Paragraph' );
await page.keyboard.type( 'First Paragraph' );
await waitForPreviewIframe();
const documentTools = await find( {
role: 'toolbar',
name: 'Document tools',
} );
// Open the inserter outer section.
const addBlockButton = await find(
{
role: 'button',
name: 'Add block',
},
{ root: documentTools }
);
await addBlockButton.click();
// Expect the inserter outer section to be found.
await expect( {
role: 'heading',
name: 'Add a block',
level: 2,
} ).toBeFound();
// Expect to close the inserter outer section when pressing Escape.
await page.keyboard.press( 'Escape' );
// Open the inserter outer section again.
await addBlockButton.click();
// Expect the inserter outer section to be found again.
const inserterHeading = await find( {
role: 'heading',
name: 'Add a block',
level: 2,
} );
// Open the Publish Settings.
const publishSettingsButton = await find( {
role: 'button',
name: 'Publish Settings',
} );
await publishSettingsButton.click();
// Expect the Publish Settings outer section to be found.
const publishSettings = await find( {
selector: '#sub-accordion-section-publish_settings',
} );
// Expect the inserter outer section to be closed.
await expect( inserterHeading ).not.toBeVisible();
// Focus the block and start typing to hide the block toolbar.
// Shouldn't be needed if we automatically hide the toolbar on blur.
const paragraphBlock = await find( {
role: 'document',
name: 'Paragraph block',
} );
await paragraphBlock.focus();
await page.keyboard.type( ' ' );
// Open the inserter outer section.
await addBlockButton.click();
await expect( {
role: 'heading',
name: 'Add a block',
level: 2,
} ).toBeFound();
// Expect the Publish Settings section to be closed.
await expect( publishSettings ).not.toBeVisible();
// Back to the widget areas panel.
const backButton = await find( {
role: 'button',
name: 'Back',
} );
await backButton.click();
// Expect the inserter outer section to be closed.
await expect( {
role: 'heading',
name: 'Add a block',
level: 2,
} ).not.toBeFound();
expect( console ).toHaveErrored( twentyTwentyError );
} );
it( 'should move focus to the block', async () => {
const widgetsPanel = await find( {
role: 'heading',
name: /Widgets/,
level: 3,
} );
await widgetsPanel.click();
const footer1Section = await find( {
role: 'heading',
name: /^Footer #1/,
level: 3,
} );
await footer1Section.click();
await addBlock( 'Paragraph' );
await page.keyboard.type( 'First Paragraph' );
await waitForPreviewIframe();
await addBlock( 'Heading' );
await page.keyboard.type( 'First Heading' );
// Navigate back to the parent panel.
const backButton = await find( { role: 'button', name: 'Back' } );
await backButton.click();
await waitForPreviewIframe();
const iframe = await find( {
name: 'Site Preview',
selector: 'iframe',
} );
const paragraphWidget = await find(
{
text: /First Paragraph/,
selector: '.widget',
},
{
root: iframe,
}
);
const editParagraphWidget = await find(
{
role: 'button',
name: 'Click to edit this widget.',
},
{
root: paragraphWidget,
}
);
await editParagraphWidget.click();
const firstParagraphBlock = await find( {
role: 'document',
name: 'Paragraph block',
text: 'First Paragraph',
} );
await expect( firstParagraphBlock ).toHaveFocus();
// Expect to focus on a already focused widget.
await editParagraphWidget.click();
await expect( firstParagraphBlock ).toHaveFocus();
const headingWidget = await find(
{
text: /First Heading/,
selector: '.widget',
},
{
root: iframe,
}
);
const editHeadingWidget = await find(
{
role: 'button',
name: 'Click to edit this widget.',
},
{
root: headingWidget,
}
);
await editHeadingWidget.click();
const headingBlock = await find( {
role: 'document',
name: 'Block: Heading',
text: 'First Heading',
} );
await expect( headingBlock ).toHaveFocus();
expect( console ).toHaveErrored( twentyTwentyError );
} );
it( 'should clear block selection', async () => {
const widgetsPanel = await find( {
role: 'heading',
name: /Widgets/,
level: 3,
} );
await widgetsPanel.click();
const footer1Section = await find( {
role: 'heading',
name: /^Footer #1/,
level: 3,
} );
await footer1Section.click();
const paragraphBlock = await addBlock( 'Paragraph' );
await page.keyboard.type( 'First Paragraph' );
await showBlockToolbar();
const sectionHeading = await find( {
role: 'heading',
name: 'Customizing ▸ Widgets Footer #1',
level: 3,
} );
await sectionHeading.click();
// Expect clicking on the section title should clear the selection.
await expect( {
role: 'toolbar',
name: 'Block tools',
} ).not.toBeFound();
await paragraphBlock.focus();
await showBlockToolbar();
const preview = await page.$( '#customize-preview' );
await preview.click();
// Expect clicking on the preview iframe should clear the selection.
await expect( {
role: 'toolbar',
name: 'Block tools',
} ).not.toBeFound();
await paragraphBlock.focus();
await showBlockToolbar();
const editorContainer = await page.$(
'#customize-control-sidebars_widgets-sidebar-1'
);
const { x, y, width, height } = await editorContainer.boundingBox();
// Simulate Clicking on the empty space at the end of the editor.
await page.mouse.click( x + width / 2, y + height + 10 );
// Expect clicking on the empty space at the end of the editor
// should clear the selection.
await expect( {
role: 'toolbar',
name: 'Block tools',
} ).not.toBeFound();
expect( console ).toHaveErrored( twentyTwentyError );
} );
it( 'should handle legacy widgets', async () => {
const widgetsPanel = await find( {
role: 'heading',
name: /Widgets/,
level: 3,
} );
await widgetsPanel.click();
const footer1Section = await find( {
role: 'heading',
name: /^Footer #1/,
level: 3,
} );
await footer1Section.click();
const legacyWidgetBlock = await addBlock( 'Legacy Widget' );
const selectLegacyWidgets = await find( {
role: 'combobox',
name: 'Select a legacy widget to display:',
} );
await selectLegacyWidgets.select( 'test_widget' );
await expect( {
role: 'heading',
name: 'Test Widget',
level: 3,
} ).toBeFound( { root: legacyWidgetBlock } );
let titleInput = await find(
{
role: 'textbox',
name: 'Title:',
},
{
root: legacyWidgetBlock,
}
);
await titleInput.type( 'Hello Title' );
// Unfocus the current legacy widget.
await page.keyboard.press( 'Tab' );
// Disable reason: Sometimes the preview just doesn't fully load,
// it's the only way I know for now to ensure that the iframe is ready.
// eslint-disable-next-line no-restricted-syntax
await page.waitForTimeout( 2000 );
await waitForPreviewIframe();
// Expect the legacy widget to show in the site preview frame.
await expect( {
role: 'heading',
name: 'Hello Title',
} ).toBeFound( {
root: await find( {
name: 'Site Preview',
selector: 'iframe',
} ),
} );
// Expect the preview in block to show when unfocusing the legacy widget block.
await expect( {
role: 'heading',
name: 'Hello Title',
} ).toBeFound( {
root: await find( {
selector: 'iframe',
name: 'Legacy Widget Preview',
} ),
} );
await legacyWidgetBlock.focus();
await showBlockToolbar();
// Testing removing the block.
await clickBlockToolbarButton( 'Options' );
const removeBlockButton = await find( {
role: 'menuitem',
name: /Remove block/,
} );
await removeBlockButton.click();
// Add it back again using the variant.
const testWidgetBlock = await addBlock( 'Test Widget' );
titleInput = await find(
{
role: 'textbox',
name: 'Title:',
},
{
root: testWidgetBlock,
}
);
await titleInput.type( 'Hello again!' );
// Unfocus the current legacy widget.
await page.keyboard.press( 'Tab' );
// Expect the preview in block to show when unfocusing the legacy widget block.
await expect( {
role: 'heading',
name: 'Hello again!',
} ).toBeFound( {
root: await find( {
selector: 'iframe',
name: 'Legacy Widget Preview',
} ),
} );
const publishButton = await find( {
role: 'button',
name: 'Publish',
} );
await publishButton.click();
// Wait for publishing to finish.
await page.waitForResponse( createURL( '/wp-admin/admin-ajax.php' ) );
await expect( publishButton ).toMatchQuery( {
disabled: true,
} );
await page.goto( createURL( '/' ) );
// Expect the saved widgets to show on frontend.
await expect( {
role: 'heading',
name: 'Hello again!',
} ).toBeFound();
} );
it( 'should handle esc key events', async () => {
const widgetsPanel = await find( {
role: 'heading',
name: /Widgets/,
level: 3,
} );
await widgetsPanel.click();
const footer1Section = await find( {
role: 'heading',
name: /^Footer #1/,
level: 3,
} );
await footer1Section.click();
const paragraphBlock = await addBlock( 'Paragraph' );
await page.keyboard.type( 'First Paragraph' );
await showBlockToolbar();
// Open the more menu dropdown in block toolbar.
await clickBlockToolbarButton( 'Options' );
await expect( {
role: 'menu',
name: 'Options',
} ).toBeFound();
// Expect pressing the Escape key to close the dropdown,
// but not close the editor.
await page.keyboard.press( 'Escape' );
await expect( {
role: 'menu',
name: 'Options',
} ).not.toBeFound();
await expect( paragraphBlock ).toBeVisible();
await paragraphBlock.focus();
// Expect pressing the Escape key to enter navigation mode,
// but not close the editor.
await page.keyboard.press( 'Escape' );
await expect( {
text: /^You are currently in navigation mode\./,
selector: '*[aria-live="polite"][aria-relevant="additions text"]',
} ).toBeFound();
await expect( paragraphBlock ).toBeVisible();
expect( console ).toHaveErrored( twentyTwentyError );
} );
it( 'should move (inner) blocks to another sidebar', async () => {
const widgetsPanel = await find( {
role: 'heading',
name: /Widgets/,
level: 3,
} );
await widgetsPanel.click();
const footer1Section = await find( {
role: 'heading',
name: /Footer #1/,
level: 3,
} );
await footer1Section.click();
await addBlock( 'Paragraph' );
await page.keyboard.type( 'First Paragraph' );
await showBlockToolbar();
await clickBlockToolbarButton( 'Options' );
const groupButton = await find( {
role: 'menuitem',
name: 'Group',
} );
await groupButton.click();
// Refocus the paragraph block.
const paragraphBlock = await find( {
role: 'document',
name: 'Paragraph block',
value: 'First Paragraph',
} );
await paragraphBlock.focus();
await showBlockToolbar();
await clickBlockToolbarButton( 'Move to widget area' );
const footer2Option = await find( {
role: 'menuitemradio',
name: 'Footer #2',
} );
await footer2Option.click();
// Should switch to and expand Footer #2.
await expect( {
role: 'heading',
name: 'Customizing ▸ Widgets Footer #2',
} ).toBeFound();
// The paragraph block should be moved to the new sidebar and have focus.
const movedParagraphBlockQuery = {
role: 'document',
name: 'Paragraph block',
value: 'First Paragraph',
};
await expect( movedParagraphBlockQuery ).toBeFound();
const movedParagraphBlock = await find( movedParagraphBlockQuery );
await expect( movedParagraphBlock ).toHaveFocus();
expect( console ).toHaveErrored( twentyTwentyError );
} );
it( 'should not render Block Settings sections', async () => {
// We add Block Settings as a section, but it shouldn't display to
// the user as a section on the main menu. It's simply how we
// integrate the G sidebar inside the customizer.
const findAllBlockSettingsHeader = findAll(
{
role: 'heading',
name: /Block Settings/,
level: 3,
},
{ timeout: 0 }
);
await expect( findAllBlockSettingsHeader ).toThrowQueryEmptyError();
} );
it( 'should stay in block settings after making a change in that area', async () => {
// Open footer block widgets
const widgetsPanel = await find( {
role: 'heading',
name: /Widgets/,
level: 3,
} );
await widgetsPanel.click();
const footer1Section = await find( {
role: 'heading',
name: /^Footer #1/,
level: 3,
} );
await footer1Section.click();
// Add a block to make the publish button active.
await addBlock( 'Paragraph' );
await page.keyboard.type( 'First Paragraph' );
await waitForPreviewIframe();
// Click Publish
const publishButton = await find( {
role: 'button',
name: 'Publish',
} );
await publishButton.click();
// Wait for publishing to finish.
await page.waitForResponse( createURL( '/wp-admin/admin-ajax.php' ) );
await expect( publishButton ).toMatchQuery( {
disabled: true,
} );
// Select the paragraph block
const paragraphBlock = await find( {
role: 'document',
name: 'Paragraph block',
} );
await paragraphBlock.focus();
// Click the three dots button, then click "Show More Settings".
await showBlockToolbar();
await clickBlockToolbarButton( 'Options' );
const showMoreSettingsButton = await find( {
role: 'menuitem',
name: 'Show more settings',
} );
await showMoreSettingsButton.click();
// Change font size (Any change made in this section is sufficient; not required to be font size)
const CUSTOM_FONT_SIZE_LABEL_SELECTOR =
"//fieldset[legend[contains(text(),'Font size')]]//label[contains(text(), 'Custom')]";
await first( await page.$x( CUSTOM_FONT_SIZE_LABEL_SELECTOR ) ).click();
await page.keyboard.type( '23' );
await page.keyboard.press( 'Enter' );
// Now that we've made a change:
// (1) Publish button should be active
// (2) We should still be in the "Block Settings" area
await find( {
role: 'button',
name: 'Publish',
} );
// This fails on 539cea09 and earlier; we get kicked back to the widgets area.
// We expect to stay in block settings.
await find( {
role: 'heading',
name: 'Customizing ▸ Widgets ▸ Footer #1 Block Settings',
level: 3,
} );
expect( console ).toHaveErrored( twentyTwentyError );
} );
} );
/**
* Wait when there's only one preview iframe.
* There could be a 2 iframes when it's changing from no widgets to
* adding a first widget to the sidebar,
*/
async function waitForPreviewIframe() {
await page.waitForFunction(
() =>
document.querySelectorAll( '[name^="customize-preview-"]' )
.length === 1
);
}
async function addBlock( blockName ) {
const addBlockButton = await find(
{
role: 'button',
name: 'Add block',
},
{
root: await find( {
role: 'toolbar',
name: 'Document tools',
} ),
}
);
await addBlockButton.click();
const searchBox = await find( {
role: 'searchbox',
name: 'Search for blocks and patterns',
} );
// Clear the input.
await searchBox.evaluate( ( node ) => {
if ( node.value ) {
node.value = '';
}
} );
await searchBox.type( blockName );
// TODO - remove this timeout when the test plugin for disabling CSS
// animations in tests works properly.
//
// This waits for the inserter panel animation to finish before
// attempting to insert a block. If the panel is still animating
// puppeteer can click on the wrong block.
//
// eslint-disable-next-line no-restricted-syntax
await page.waitForTimeout( 300 );
const blockOption = await find( {
role: 'option',
name: blockName,
} );
await blockOption.click();
const addedBlock = await find( {
role: 'document',
selector: '.is-selected[data-block]',
} );
await addedBlock.focus();
return addedBlock;
}