@wordpress/e2e-tests 7.8.0 → 7.9.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.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 7.9.0 (2023-07-20)
6
+
5
7
  ## 7.8.0 (2023-07-05)
6
8
 
7
9
  ## 7.7.0 (2023-06-23)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wordpress/e2e-tests",
3
- "version": "7.8.0",
3
+ "version": "7.9.0",
4
4
  "description": "End-To-End (E2E) tests for WordPress.",
5
5
  "author": "The WordPress Contributors",
6
6
  "license": "GPL-2.0-or-later",
@@ -23,11 +23,11 @@
23
23
  "node": ">=14"
24
24
  },
25
25
  "dependencies": {
26
- "@wordpress/e2e-test-utils": "^10.8.0",
27
- "@wordpress/jest-console": "^7.8.0",
28
- "@wordpress/jest-puppeteer-axe": "^6.8.0",
29
- "@wordpress/scripts": "^26.8.0",
30
- "@wordpress/url": "^3.38.0",
26
+ "@wordpress/e2e-test-utils": "^10.9.0",
27
+ "@wordpress/jest-console": "^7.9.0",
28
+ "@wordpress/jest-puppeteer-axe": "^6.9.0",
29
+ "@wordpress/scripts": "^26.9.0",
30
+ "@wordpress/url": "^3.39.0",
31
31
  "chalk": "^4.0.0",
32
32
  "expect-puppeteer": "^4.4.0",
33
33
  "filenamify": "^4.2.0",
@@ -45,5 +45,5 @@
45
45
  "publishConfig": {
46
46
  "access": "public"
47
47
  },
48
- "gitHead": "bcd13d59b22553b3c9dc5869077bff1e864cf9f5"
48
+ "gitHead": "6f14d11ed4cb59df110a28ebaa23ecba95eb673a"
49
49
  }
@@ -8,10 +8,10 @@
8
8
  */
9
9
 
10
10
  /**
11
- * Enqueues a custom script for the plugin.
11
+ * Registers plugin test context blocks.
12
12
  */
13
- function gutenberg_test_enqueue_block_context_script() {
14
- wp_enqueue_script(
13
+ function gutenberg_test_register_context_blocks() {
14
+ wp_register_script(
15
15
  'gutenberg-test-block-context',
16
16
  plugins_url( 'block-context/index.js', __FILE__ ),
17
17
  array(
@@ -22,37 +22,32 @@ function gutenberg_test_enqueue_block_context_script() {
22
22
  filemtime( plugin_dir_path( __FILE__ ) . 'block-context/index.js' ),
23
23
  true
24
24
  );
25
- }
26
- add_action( 'init', 'gutenberg_test_enqueue_block_context_script' );
27
25
 
28
- /**
29
- * Registers plugin test context blocks.
30
- */
31
- function gutenberg_test_register_context_blocks() {
32
26
  register_block_type(
33
27
  'gutenberg/test-context-provider',
34
28
  array(
35
- 'attributes' => array(
29
+ 'attributes' => array(
36
30
  'recordId' => array(
37
31
  'type' => 'number',
38
32
  'default' => 0,
39
33
  ),
40
34
  ),
41
- 'provides_context' => array(
35
+ 'provides_context' => array(
42
36
  'gutenberg/recordId' => 'recordId',
43
37
  ),
38
+ 'editor_script_handles' => array( 'gutenberg-test-block-context' ),
44
39
  )
45
40
  );
46
41
 
47
42
  register_block_type(
48
43
  'gutenberg/test-context-consumer',
49
44
  array(
50
- 'uses_context' => array(
45
+ 'uses_context' => array(
51
46
  'gutenberg/recordId',
52
47
  'postId',
53
48
  'postType',
54
49
  ),
55
- 'render_callback' => static function( $attributes, $content, $block ) {
50
+ 'render_callback' => static function( $attributes, $content, $block ) {
56
51
  $ordered_context = array(
57
52
  $block->context['gutenberg/recordId'],
58
53
  $block->context['postId'],
@@ -61,6 +56,7 @@ function gutenberg_test_register_context_blocks() {
61
56
 
62
57
  return implode( ',', $ordered_context );
63
58
  },
59
+ 'editor_script_handles' => array( 'gutenberg-test-block-context' ),
64
60
  )
65
61
  );
66
62
  }
@@ -0,0 +1,3 @@
1
+ window.addEventListener( 'load', () => {
2
+ document.body.dataset.iframedEnqueueBlockAssetsL10n = window.iframedEnqueueBlockAssetsL10n.test;
3
+ } );
@@ -17,5 +17,18 @@ add_action(
17
17
  filemtime( plugin_dir_path( __FILE__ ) . 'iframed-enqueue-block-assets/style.css' )
18
18
  );
19
19
  wp_add_inline_style( 'iframed-enqueue-block-assets', 'body{padding:20px!important}' );
20
+ wp_enqueue_script(
21
+ 'iframed-enqueue-block-assets-script',
22
+ plugin_dir_url( __FILE__ ) . 'iframed-enqueue-block-assets/script.js',
23
+ array(),
24
+ filemtime( plugin_dir_path( __FILE__ ) . 'iframed-enqueue-block-assets/script.js' )
25
+ );
26
+ wp_localize_script(
27
+ 'iframed-enqueue-block-assets-script',
28
+ 'iframedEnqueueBlockAssetsL10n',
29
+ array(
30
+ 'test' => 'Iframed Enqueue Block Assets!',
31
+ )
32
+ );
20
33
  }
21
34
  );
@@ -0,0 +1,14 @@
1
+ {
2
+ "apiVersion": 2,
3
+ "name": "test/directive-style",
4
+ "title": "E2E Interactivity tests - directive style",
5
+ "category": "text",
6
+ "icon": "heart",
7
+ "description": "",
8
+ "supports": {
9
+ "interactivity": true
10
+ },
11
+ "textdomain": "e2e-interactivity",
12
+ "viewScript": "directive-style-view",
13
+ "render": "file:./render.php"
14
+ }
@@ -0,0 +1,93 @@
1
+ <?php
2
+ /**
3
+ * HTML for testing the directive `data-wp-style`.
4
+ *
5
+ * @package gutenberg-test-interactive-blocks
6
+ */
7
+
8
+ ?>
9
+
10
+ <div data-wp-interactive>
11
+ <button
12
+ data-wp-on--click="actions.toggleColor"
13
+ data-testid="toggle color"
14
+ >
15
+ Toggle Color
16
+ </button>
17
+
18
+ <button
19
+ data-wp-on--click="actions.switchColorToFalse"
20
+ data-testid="switch color to false"
21
+ >
22
+ Switch Color to False
23
+ </button>
24
+
25
+ <div
26
+ style="color: red; background: green;"
27
+ data-wp-style--color="state.color"
28
+ data-testid="dont change style if callback returns same value on hydration"
29
+ >Don't change style if callback returns same value on hydration</div>
30
+
31
+ <div
32
+ style="color: blue; background: green;"
33
+ data-wp-style--color="state.falseValue"
34
+ data-testid="remove style if callback returns falsy value on hydration"
35
+ >Remove style if callback returns falsy value on hydration</div>
36
+
37
+ <div
38
+ style="color: blue; background: green;"
39
+ data-wp-style--color="state.color"
40
+ data-testid="change style if callback returns a new value on hydration"
41
+ >Change style if callback returns a new value on hydration</div>
42
+
43
+ <div
44
+ style="color: blue; background: green; border: 1px solid black"
45
+ data-wp-style--color="state.falseValue"
46
+ data-wp-style--background="state.color"
47
+ data-wp-style--border="state.border"
48
+ data-testid="handles multiple styles and callbacks on hydration"
49
+ >Handles multiple styles and callbacks on hydration</div>
50
+
51
+ <div
52
+ data-wp-style--color="state.color"
53
+ data-testid="can add style when style attribute is missing on hydration"
54
+ >Can add style when style attribute is missing on hydration</div>
55
+
56
+ <div
57
+ style="color: red;"
58
+ data-wp-style--color="state.color"
59
+ data-testid="can toggle style"
60
+ >Can toggle style</div>
61
+
62
+ <div
63
+ style="color: red;"
64
+ data-wp-style--color="state.color"
65
+ data-testid="can remove style"
66
+ >Can remove style</div>
67
+
68
+ <div
69
+ style="color: blue; background: green; border: 1px solid black;"
70
+ data-wp-style--background="state.color"
71
+ data-testid="can toggle style in the middle"
72
+ >Can toggle style in the middle</div>
73
+
74
+ <div
75
+ style="background-color: green;"
76
+ data-wp-style--background-color="state.color"
77
+ data-testid="handles styles names with hyphens"
78
+ >Handles styles names with hyphens</div>
79
+
80
+ <div data-wp-context='{ "color": "blue" }'>
81
+ <div
82
+ style="color: blue;"
83
+ data-wp-style--color="context.color"
84
+ data-testid="can use context values"
85
+ ></div>
86
+ <button
87
+ data-wp-on--click="actions.toggleContext"
88
+ data-testid="toggle context"
89
+ >
90
+ Toggle context
91
+ </button>
92
+ </div>
93
+ </div>
@@ -0,0 +1,22 @@
1
+ ( ( { wp } ) => {
2
+ const { store } = wp.interactivity;
3
+
4
+ store( {
5
+ state: {
6
+ falseValue: false,
7
+ color: "red",
8
+ border: "2px solid yellow"
9
+ },
10
+ actions: {
11
+ toggleColor: ( { state } ) => {
12
+ state.color = state.color === "red" ? "blue" : "red";
13
+ },
14
+ switchColorToFalse: ({ state }) => {
15
+ state.color = false;
16
+ },
17
+ toggleContext: ( { context } ) => {
18
+ context.color = context.color === "red" ? "blue" : "red";
19
+ },
20
+ },
21
+ } );
22
+ } )( window );
@@ -22,10 +22,11 @@ exports[`InnerBlocks Template Sync Ensures blocks without locking are kept intac
22
22
  <p class="has-large-font-size">Content…</p>
23
23
  <!-- /wp:paragraph -->
24
24
 
25
- <!-- wp:paragraph -->
26
- <p>added paragraph</p>
27
- <!-- /wp:paragraph -->
28
- <!-- /wp:test/test-inner-blocks-no-locking -->"
25
+ <!-- wp:paragraph -->
26
+ <p>added paragraph</p>
27
+ <!-- /wp:paragraph -->
28
+ <!-- /wp:test/test-inner-blocks-no-locking -->
29
+ "
29
30
  `;
30
31
 
31
32
  exports[`InnerBlocks Template Sync Removes blocks that are not expected by the template if a lock all exists 1`] = `
@@ -32,6 +32,7 @@ describe( 'iframed inline styles', () => {
32
32
  } );
33
33
 
34
34
  it( 'should load styles added through enqueue_block_assets', async () => {
35
+ await page.waitForSelector( 'iframe[name="editor-canvas"]' );
35
36
  // Check stylesheet.
36
37
  expect(
37
38
  await getComputedStyle( canvas(), 'body', 'background-color' )
@@ -40,5 +41,11 @@ describe( 'iframed inline styles', () => {
40
41
  expect( await getComputedStyle( canvas(), 'body', 'padding' ) ).toBe(
41
42
  '20px'
42
43
  );
44
+
45
+ expect(
46
+ await canvas().evaluate( () => ( { ...document.body.dataset } ) )
47
+ ).toEqual( {
48
+ iframedEnqueueBlockAssetsL10n: 'Iframed Enqueue Block Assets!',
49
+ } );
43
50
  } );
44
51
  } );
@@ -43,19 +43,4 @@ describe( 'PostPublishButton', () => {
43
43
  await page.$( '.editor-post-publish-button[aria-disabled="true"]' )
44
44
  ).not.toBeNull();
45
45
  } );
46
-
47
- it( 'should be disabled when metabox is being saved', async () => {
48
- await canvas().type( '.editor-post-title__input', 'E2E Test Post' ); // Make it saveable.
49
- expect(
50
- await page.$( '.editor-post-publish-button[aria-disabled="true"]' )
51
- ).toBeNull();
52
-
53
- await page.evaluate( () => {
54
- window.wp.data.dispatch( 'core/edit-post' ).requestMetaBoxUpdates();
55
- return true;
56
- } );
57
- expect(
58
- await page.$( '.editor-post-publish-button[aria-disabled="true"]' )
59
- ).not.toBeNull();
60
- } );
61
46
  } );
@@ -23,8 +23,6 @@ const reusableBlockNameInputSelector =
23
23
  '.reusable-blocks-menu-items__convert-modal .components-text-control__input';
24
24
  const reusableBlockInspectorNameInputSelector =
25
25
  '.block-editor-block-inspector .components-text-control__input';
26
- const syncToggleSelector =
27
- '.reusable-blocks-menu-items__convert-modal .components-form-toggle__input';
28
26
  const syncToggleSelectorChecked =
29
27
  '.reusable-blocks-menu-items__convert-modal .components-form-toggle.is-checked';
30
28
 
@@ -205,14 +203,12 @@ describe( 'Reusable blocks', () => {
205
203
  );
206
204
  await nameInput.click();
207
205
  await page.keyboard.type( 'Multi-selection reusable block' );
208
- const syncToggle = await page.waitForSelector( syncToggleSelector );
209
- syncToggle.click();
210
206
  await page.waitForSelector( syncToggleSelectorChecked );
211
207
  await page.keyboard.press( 'Enter' );
212
208
 
213
209
  // Wait for creation to finish.
214
210
  await page.waitForXPath(
215
- '//*[contains(@class, "components-snackbar")]/*[text()="Synced Pattern created."]'
211
+ '//*[contains(@class, "components-snackbar")]/*[contains(text(),"Pattern created:")]'
216
212
  );
217
213
 
218
214
  await clearAllBlocks();
@@ -352,7 +348,7 @@ describe( 'Reusable blocks', () => {
352
348
  expect( reusableBlockWithParagraph ).toBeTruthy();
353
349
 
354
350
  // Convert back to regular blocks.
355
- await clickBlockToolbarButton( 'Select Pattern' );
351
+ await clickBlockToolbarButton( 'Select Edited block' );
356
352
  await clickBlockToolbarButton( 'Detach pattern' );
357
353
  await page.waitForXPath( selector, {
358
354
  hidden: true,
@@ -389,8 +385,6 @@ describe( 'Reusable blocks', () => {
389
385
  );
390
386
  await nameInput.click();
391
387
  await page.keyboard.type( 'Block with styles' );
392
- const syncToggle = await page.waitForSelector( syncToggleSelector );
393
- syncToggle.click();
394
388
  await page.waitForSelector( syncToggleSelectorChecked );
395
389
  await page.keyboard.press( 'Enter' );
396
390
  const reusableBlock = await canvas().waitForSelector(
@@ -12,8 +12,6 @@ import {
12
12
  activateTheme,
13
13
  clickButton,
14
14
  createReusableBlock,
15
- visitSiteEditor,
16
- enterEditMode,
17
15
  deleteAllTemplates,
18
16
  canvas,
19
17
  } from '@wordpress/e2e-test-utils';
@@ -239,104 +237,4 @@ describe( 'Multi-entity save flow', () => {
239
237
  expect( checkboxInputs ).toHaveLength( 1 );
240
238
  } );
241
239
  } );
242
-
243
- describe( 'Site Editor', () => {
244
- // Selectors - Site editor specific.
245
- const saveSiteSelector = '.edit-site-save-button__button';
246
- const activeSaveSiteSelector = `${ saveSiteSelector }[aria-disabled=false]`;
247
- const disabledSaveSiteSelector = `${ saveSiteSelector }[aria-disabled=true]`;
248
- const saveA11ySelector = '.edit-site-editor__toggle-save-panel-button';
249
-
250
- const saveAllChanges = async () => {
251
- // Clicking button should open panel with boxes checked.
252
- await page.click( activeSaveSiteSelector );
253
- await page.waitForSelector( savePanelSelector );
254
- await assertAllBoxesChecked();
255
-
256
- // Save a11y button should not be present with save panel open.
257
- await assertExistence( saveA11ySelector, false );
258
-
259
- // Saving should result in items being saved.
260
- await page.click( entitiesSaveSelector );
261
- };
262
-
263
- it( 'Save flow should work as expected', async () => {
264
- // Navigate to site editor.
265
- await visitSiteEditor( {
266
- postId: 'emptytheme//index',
267
- postType: 'wp_template',
268
- } );
269
-
270
- await enterEditMode();
271
-
272
- // Select the header template part via list view.
273
- await page.click( '.edit-site-header-edit-mode__list-view-toggle' );
274
- const headerTemplatePartListViewButton = await page.waitForXPath(
275
- '//a[contains(@class, "block-editor-list-view-block-select-button")][contains(., "header")]'
276
- );
277
- headerTemplatePartListViewButton.click();
278
- await page.click( 'button[aria-label="Close"]' );
279
-
280
- // Insert something to dirty the editor.
281
- await insertBlock( 'Paragraph' );
282
-
283
- const enabledButton = await page.waitForSelector(
284
- activeSaveSiteSelector
285
- );
286
-
287
- // Should be enabled after edits.
288
- expect( enabledButton ).not.toBeNull();
289
-
290
- // Save a11y button should be present.
291
- await assertExistence( saveA11ySelector, true );
292
-
293
- // Save all changes.
294
- await saveAllChanges();
295
-
296
- const disabledButton = await page.waitForSelector(
297
- disabledSaveSiteSelector
298
- );
299
- expect( disabledButton ).not.toBeNull();
300
- } );
301
-
302
- it( 'Save flow should allow re-saving after changing the same block attribute', async () => {
303
- // Navigate to site editor.
304
- await visitSiteEditor( {
305
- postId: 'emptytheme//index',
306
- postType: 'wp_template',
307
- } );
308
-
309
- await enterEditMode();
310
-
311
- // Insert a paragraph at the bottom.
312
- await insertBlock( 'Paragraph' );
313
-
314
- // Open the block settings.
315
- await page.click( 'button[aria-label="Settings"]' );
316
-
317
- // Wait for the font size picker controls.
318
- await page.waitForSelector(
319
- '.components-font-size-picker__controls'
320
- );
321
-
322
- // Change the font size.
323
- await page.click(
324
- '.components-font-size-picker__controls button[aria-label="Small"]'
325
- );
326
-
327
- // Save all changes.
328
- await saveAllChanges();
329
-
330
- // Change the font size.
331
- await page.click(
332
- '.components-font-size-picker__controls button[aria-label="Medium"]'
333
- );
334
-
335
- // Assert that the save button has been re-enabled.
336
- const saveButton = await page.waitForSelector(
337
- activeSaveSiteSelector
338
- );
339
- expect( saveButton ).not.toBeNull();
340
- } );
341
- } );
342
240
  } );
@@ -1,80 +0,0 @@
1
- /**
2
- * External dependencies
3
- */
4
- import path from 'path';
5
- import fs from 'fs';
6
- import os from 'os';
7
- import { v4 as uuid } from 'uuid';
8
-
9
- /**
10
- * WordPress dependencies
11
- */
12
- import {
13
- clickBlockAppender,
14
- getEditedPostContent,
15
- createNewPost,
16
- clickBlockToolbarButton,
17
- clickButton,
18
- pressKeyWithModifier,
19
- } from '@wordpress/e2e-test-utils';
20
-
21
- describe( 'adding inline tokens', () => {
22
- beforeEach( async () => {
23
- await createNewPost();
24
- } );
25
-
26
- it( 'should insert inline image', async () => {
27
- // Create a paragraph.
28
- await clickBlockAppender();
29
- await page.keyboard.type( 'a ' );
30
-
31
- await clickBlockToolbarButton( 'More' );
32
- await clickButton( 'Inline image' );
33
-
34
- // Wait for media modal to appear and upload image.
35
- // Wait for media modal to appear and upload image.
36
- const inputElement = await page.waitForSelector(
37
- '.media-modal .moxie-shim input[type=file]'
38
- );
39
- const testImagePath = path.join(
40
- __dirname,
41
- '..',
42
- '..',
43
- '..',
44
- 'assets',
45
- '10x10_e2e_test_image_z9T8jK.png'
46
- );
47
- const filename = uuid();
48
- const tmpFileName = path.join( os.tmpdir(), filename + '.png' );
49
- fs.copyFileSync( testImagePath, tmpFileName );
50
- await inputElement.uploadFile( tmpFileName );
51
-
52
- // Wait for upload.
53
- await page.waitForSelector(
54
- `.media-modal li[aria-label="${ filename }"]`
55
- );
56
-
57
- // Insert the uploaded image.
58
- await page.click( '.media-modal button.media-button-select' );
59
-
60
- // Check the content.
61
- const regex = new RegExp(
62
- `<!-- wp:paragraph -->\\s*<p>a <img class="wp-image-\\d+" style="width:\\s*10px;?" src="[^"]+\\/${ filename }\\.png" alt=""\\/?><\\/p>\\s*<!-- \\/wp:paragraph -->`
63
- );
64
- expect( await getEditedPostContent() ).toMatch( regex );
65
-
66
- await pressKeyWithModifier( 'shift', 'ArrowLeft' );
67
- await page.waitForSelector(
68
- '.block-editor-format-toolbar__image-popover'
69
- );
70
- await page.keyboard.press( 'Tab' );
71
- await page.keyboard.type( '20' );
72
- await page.keyboard.press( 'Enter' );
73
-
74
- // Check the content.
75
- const regex2 = new RegExp(
76
- `<!-- wp:paragraph -->\\s*<p>a <img class="wp-image-\\d+" style="width:\\s*20px;?" src="[^"]+\\/${ filename }\\.png" alt=""\\/?><\\/p>\\s*<!-- \\/wp:paragraph -->`
77
- );
78
- expect( await getEditedPostContent() ).toMatch( regex2 );
79
- } );
80
- } );