@wordpress/e2e-tests 2.4.1-next.253d9b6e21.0 → 2.5.1

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 (49) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/README.md +62 -0
  3. package/config/flaky-tests-reporter.js +94 -0
  4. package/config/setup-test-framework.js +10 -0
  5. package/jest.config.js +11 -1
  6. package/package.json +8 -7
  7. package/plugins/class-test-widget.php +5 -2
  8. package/plugins/iframed-block/block.json +16 -0
  9. package/plugins/iframed-block/editor.css +6 -0
  10. package/plugins/iframed-block/editor.js +18 -0
  11. package/plugins/iframed-block/jquery.test.js +7 -0
  12. package/plugins/iframed-block/script.js +7 -0
  13. package/plugins/iframed-block/style.css +9 -0
  14. package/plugins/iframed-block.php +46 -0
  15. package/specs/editor/blocks/buttons.test.js +30 -0
  16. package/specs/editor/blocks/post-title.test.js +1 -1
  17. package/specs/editor/plugins/__snapshots__/iframed-block.test.js.snap +7 -0
  18. package/specs/editor/plugins/align-hook.test.js +116 -105
  19. package/specs/editor/plugins/annotations.test.js +3 -3
  20. package/specs/editor/plugins/iframed-block.test.js +58 -0
  21. package/specs/editor/various/__snapshots__/copy-cut-paste-whole-blocks.test.js.snap +28 -0
  22. package/specs/editor/various/__snapshots__/rich-text.test.js.snap +15 -3
  23. package/specs/editor/various/a11y.test.js +1 -1
  24. package/specs/editor/various/block-deletion.test.js +2 -2
  25. package/specs/editor/various/block-grouping.test.js +2 -2
  26. package/specs/editor/various/block-mover.test.js +1 -1
  27. package/specs/editor/various/change-detection.test.js +2 -1
  28. package/specs/editor/various/copy-cut-paste-whole-blocks.test.js +92 -0
  29. package/specs/editor/various/embedding.test.js +1 -1
  30. package/specs/editor/various/inserting-blocks.test.js +23 -0
  31. package/specs/editor/various/keyboard-navigable-blocks.test.js +2 -2
  32. package/specs/editor/various/multi-block-selection.test.js +23 -0
  33. package/specs/editor/various/new-post.test.js +6 -3
  34. package/specs/editor/various/preview.test.js +5 -1
  35. package/specs/editor/various/rich-text.test.js +29 -1
  36. package/specs/editor/various/splitting-merging.test.js +48 -2
  37. package/specs/editor/various/writing-flow.test.js +14 -13
  38. package/specs/experiments/__snapshots__/navigation-editor.test.js.snap +27 -33
  39. package/specs/experiments/blocks/__snapshots__/navigation.test.js.snap +35 -25
  40. package/specs/experiments/blocks/navigation.test.js +93 -17
  41. package/specs/experiments/fixtures/menu-items-request-fixture.json +84 -0
  42. package/specs/experiments/navigation-editor.test.js +341 -231
  43. package/specs/experiments/template-part.test.js +6 -3
  44. package/specs/experiments/template-revert.test.js +1 -1
  45. package/specs/performance/post-editor.test.js +108 -80
  46. package/specs/performance/site-editor.test.js +2 -17
  47. package/specs/widgets/customizing-widgets.test.js +118 -7
  48. package/specs/widgets/editing-widgets.test.js +52 -88
  49. package/plugins/classic-widgets.php +0 -11
@@ -2,14 +2,15 @@
2
2
  * WordPress dependencies
3
3
  */
4
4
  import {
5
- activatePlugin,
5
+ __experimentalActivatePlugin as activatePlugin,
6
6
  activateTheme,
7
7
  clickBlockToolbarButton,
8
- deactivatePlugin,
8
+ __experimentalDeactivatePlugin as deactivatePlugin,
9
9
  showBlockToolbar,
10
10
  visitAdminPage,
11
11
  deleteAllWidgets,
12
12
  pressKeyWithModifier,
13
+ __experimentalRest as rest,
13
14
  } from '@wordpress/e2e-test-utils';
14
15
 
15
16
  /**
@@ -19,6 +20,10 @@ import {
19
20
  import { find, findAll } from 'puppeteer-testing-library';
20
21
  import { groupBy, mapValues } from 'lodash';
21
22
 
23
+ const twentyTwentyError = `Stylesheet twentytwenty-block-editor-styles-css was not properly added.
24
+ 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).
25
+ For themes, use add_editor_style (https://developer.wordpress.org/block-editor/how-to-guides/themes/theme-support/#editor-styles).`;
26
+
22
27
  describe( 'Widgets screen', () => {
23
28
  beforeEach( async () => {
24
29
  await visitWidgetsScreen();
@@ -26,14 +31,14 @@ describe( 'Widgets screen', () => {
26
31
  // Disable welcome guide if it is enabled.
27
32
  const isWelcomeGuideActive = await page.evaluate( () =>
28
33
  wp.data
29
- .select( 'core/edit-widgets' )
30
- .__unstableIsFeatureActive( 'welcomeGuide' )
34
+ .select( 'core/interface' )
35
+ .isFeatureActive( 'core/edit-widgets', 'welcomeGuide' )
31
36
  );
32
37
  if ( isWelcomeGuideActive ) {
33
38
  await page.evaluate( () =>
34
39
  wp.data
35
- .dispatch( 'core/edit-widgets' )
36
- .__unstableToggleFeature( 'welcomeGuide' )
40
+ .dispatch( 'core/interface' )
41
+ .toggleFeature( 'core/edit-widgets', 'welcomeGuide' )
37
42
  );
38
43
  }
39
44
 
@@ -51,23 +56,10 @@ describe( 'Widgets screen', () => {
51
56
  beforeAll( async () => {
52
57
  // TODO: Ideally we can bundle our test theme directly in the repo.
53
58
  await activateTheme( 'twentytwenty' );
54
- // Reduced motion is needed to immediately show and dismiss the snackbars.
55
- await page.emulateMediaFeatures( [
56
- {
57
- name: 'prefers-reduced-motion',
58
- value: 'reduce',
59
- },
60
- ] );
61
59
  await deleteAllWidgets();
62
60
  } );
63
61
 
64
62
  afterAll( async () => {
65
- await page.emulateMediaFeatures( [
66
- {
67
- name: 'prefers-reduced-motion',
68
- value: 'no-preference',
69
- },
70
- ] );
71
63
  await activateTheme( 'twentytwentyone' );
72
64
  } );
73
65
 
@@ -245,6 +237,8 @@ describe( 'Widgets screen', () => {
245
237
  </div></div>",
246
238
  }
247
239
  ` );
240
+
241
+ expect( console ).toHaveErrored( twentyTwentyError );
248
242
  } );
249
243
 
250
244
  it.skip( 'Should insert content using the inline inserter', async () => {
@@ -554,8 +548,6 @@ describe( 'Widgets screen', () => {
554
548
  </div></div>",
555
549
  }
556
550
  ` );
557
- const initialWidgets = await getWidgetAreaWidgets();
558
- expect( initialWidgets[ 'sidebar-1' ].length ).toBe( 1 );
559
551
 
560
552
  firstParagraphBlock = await firstWidgetArea.$(
561
553
  '[data-block][data-type="core/paragraph"]'
@@ -608,66 +600,47 @@ describe( 'Widgets screen', () => {
608
600
  </div></div>",
609
601
  }
610
602
  ` );
611
- const editedWidgets = await getWidgetAreaWidgets();
612
- expect( editedWidgets[ 'sidebar-1' ].length ).toBe( 2 );
613
- expect( editedWidgets[ 'sidebar-1' ][ 0 ] ).toBe(
614
- initialWidgets[ 'sidebar-1' ][ 0 ]
603
+ expect( editedSerializedWidgetAreas[ 'sidebar-1' ] ).toBe(
604
+ [
605
+ initialSerializedWidgetAreas[ 'sidebar-1' ],
606
+ initialSerializedWidgetAreas[ 'sidebar-1' ],
607
+ ].join( '\n' )
615
608
  );
609
+
610
+ expect( console ).toHaveErrored( twentyTwentyError );
616
611
  } );
617
612
 
618
613
  it( 'Should display legacy widgets', async () => {
619
- /**
620
- * Using the classic widgets screen to simulate creating legacy widgets.
621
- */
622
- await activatePlugin( 'gutenberg-test-classic-widgets' );
623
- await visitAdminPage( 'widgets.php' );
624
-
625
- const searchWidget = await find(
626
- {
627
- role: 'heading',
628
- name: 'Search',
629
- level: 3,
630
- },
631
- {
632
- root: await page.$( '#widget-list' ),
633
- }
634
- );
635
- await searchWidget.click();
636
-
637
- const addWidgetButton = await find( {
638
- role: 'button',
639
- name: 'Add Widget',
614
+ // Get the default empty instance of a legacy search widget.
615
+ const { instance: defaultSearchInstance } = await rest( {
616
+ method: 'POST',
617
+ path: '/wp/v2/widget-types/search/encode',
618
+ data: { instance: {} },
640
619
  } );
641
- await addWidgetButton.click();
642
620
 
643
- // Wait for the changes to be saved.
644
- // TODO: Might have better ways to do this.
645
- await page.waitForFunction( () => {
646
- const addedSearchWidget = document.querySelector(
647
- '#widgets-right .widget'
648
- );
649
- const spinner = addedSearchWidget.querySelector( '.spinner' );
650
-
651
- return (
652
- addedSearchWidget.classList.contains( 'open' ) &&
653
- ! spinner.classList.contains( 'is-active' )
654
- );
621
+ // Create a search widget in the first sidebar using the default instance.
622
+ await rest( {
623
+ method: 'POST',
624
+ path: '/wp/v2/widgets',
625
+ data: {
626
+ id_base: 'search',
627
+ sidebar: 'sidebar-1',
628
+ instance: defaultSearchInstance,
629
+ },
655
630
  } );
656
- // FIXME: For some reasons, waiting for the spinner to disappear is not enough.
657
- // eslint-disable-next-line no-restricted-syntax
658
- await page.waitForTimeout( 500 );
659
631
 
660
- await deactivatePlugin( 'gutenberg-test-classic-widgets' );
661
- await visitWidgetsScreen();
632
+ await page.reload();
662
633
 
663
634
  // Wait for the Legacy Widget block's preview iframe to load.
664
635
  const frame = await new Promise( ( resolve ) => {
665
- const checkFrame = async ( candidateFrame ) => {
666
- const url = await candidateFrame.url();
667
- if ( url.includes( 'legacy-widget-preview' ) ) {
636
+ const checkFrame = async () => {
637
+ const frameElement = await page.$(
638
+ 'iframe.wp-block-legacy-widget__edit-preview-iframe'
639
+ );
640
+ if ( frameElement ) {
668
641
  page.off( 'frameattached', checkFrame );
669
642
  page.off( 'framenavigated', checkFrame );
670
- resolve( candidateFrame );
643
+ resolve( frameElement.contentFrame() );
671
644
  }
672
645
  };
673
646
  page.on( 'frameattached', checkFrame );
@@ -809,6 +782,8 @@ describe( 'Widgets screen', () => {
809
782
  </div></div>",
810
783
  }
811
784
  ` );
785
+
786
+ expect( console ).toHaveErrored( twentyTwentyError );
812
787
  } );
813
788
 
814
789
  it( 'Allows widget deletion to be undone', async () => {
@@ -847,6 +822,8 @@ describe( 'Widgets screen', () => {
847
822
  // Delete the last block and save again.
848
823
  await pressKeyWithModifier( 'access', 'z' );
849
824
  await saveWidgets();
825
+ // To do: clicking on the Snackbar causes focus loss.
826
+ await page.focus( '.block-editor-writing-flow' );
850
827
 
851
828
  // Undo block deletion and save again
852
829
  await pressKeyWithModifier( 'primary', 'z' );
@@ -866,6 +843,8 @@ describe( 'Widgets screen', () => {
866
843
  </div></div>",
867
844
  }
868
845
  ` );
846
+
847
+ expect( console ).toHaveErrored( twentyTwentyError );
869
848
  } );
870
849
  } );
871
850
 
@@ -912,13 +891,15 @@ async function saveWidgets() {
912
891
  // Close the snackbar.
913
892
  const savedSnackbar = await find( savedSnackbarQuery );
914
893
  await savedSnackbar.click();
894
+ // Expect focus not to be lost.
895
+ await expect(
896
+ await page.evaluate( () => document.activeElement.className )
897
+ ).toBe( 'components-snackbar-list edit-widgets-notices__snackbar' );
915
898
  await expect( savedSnackbarQuery ).not.toBeFound();
916
899
  }
917
900
 
918
901
  async function getSerializedWidgetAreas() {
919
- const widgets = await page.evaluate( () =>
920
- wp.data.select( 'core' ).getWidgets( { _embed: 'about' } )
921
- );
902
+ const widgets = await rest( { path: '/wp/v2/widgets' } );
922
903
 
923
904
  const serializedWidgetAreas = mapValues(
924
905
  groupBy( widgets, 'sidebar' ),
@@ -931,20 +912,3 @@ async function getSerializedWidgetAreas() {
931
912
 
932
913
  return serializedWidgetAreas;
933
914
  }
934
-
935
- async function getWidgetAreaWidgets() {
936
- const widgets = await page.evaluate( () => {
937
- const widgetAreas = wp.data
938
- .select( 'core/edit-widgets' )
939
- .getWidgetAreas();
940
- const sidebars = {};
941
-
942
- for ( const widgetArea of widgetAreas ) {
943
- sidebars[ widgetArea.id ] = widgetArea.widgets;
944
- }
945
-
946
- return sidebars;
947
- } );
948
-
949
- return widgets;
950
- }
@@ -1,11 +0,0 @@
1
- <?php
2
- /**
3
- * Plugin Name: Gutenberg Test Classic Widgets
4
- * Plugin URI: https://github.com/WordPress/gutenberg
5
- * Author: Gutenberg Team
6
- *
7
- * @package gutenberg-test-classic-widgets
8
- */
9
-
10
- // Disable the widgets block editor and enable the legacy widgets screen.
11
- add_filter( 'use_widgets_block_editor', '__return_false' );