@wordpress/e2e-tests 7.7.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.
Files changed (61) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/package.json +7 -7
  3. package/plugins/block-api/index.js +5 -2
  4. package/plugins/block-api.php +2 -0
  5. package/plugins/block-context.php +9 -13
  6. package/plugins/deprecated-node-matcher/index.js +12 -16
  7. package/plugins/deprecated-node-matcher.php +0 -1
  8. package/plugins/iframed-enqueue-block-assets/script.js +3 -0
  9. package/plugins/iframed-enqueue-block-assets.php +13 -0
  10. package/plugins/inner-blocks-allowed-blocks/index.js +1 -0
  11. package/plugins/inner-blocks-templates/index.js +33 -30
  12. package/plugins/interactive-blocks/directive-bind/block.json +14 -0
  13. package/plugins/interactive-blocks/directive-bind/render.php +59 -0
  14. package/plugins/interactive-blocks/directive-bind/view.js +23 -0
  15. package/plugins/interactive-blocks/directive-class/block.json +14 -0
  16. package/plugins/interactive-blocks/directive-class/render.php +75 -0
  17. package/plugins/interactive-blocks/directive-class/view.js +21 -0
  18. package/plugins/interactive-blocks/directive-context/block.json +14 -0
  19. package/plugins/interactive-blocks/directive-context/render.php +121 -0
  20. package/plugins/interactive-blocks/directive-context/view.js +22 -0
  21. package/plugins/interactive-blocks/directive-effect/block.json +14 -0
  22. package/plugins/interactive-blocks/directive-effect/render.php +27 -0
  23. package/plugins/interactive-blocks/directive-effect/view.js +61 -0
  24. package/plugins/interactive-blocks/directive-priorities/block.json +14 -0
  25. package/plugins/interactive-blocks/directive-priorities/render.php +20 -0
  26. package/plugins/interactive-blocks/directive-priorities/view.js +121 -0
  27. package/plugins/interactive-blocks/directive-show/block.json +14 -0
  28. package/plugins/interactive-blocks/directive-show/render.php +53 -0
  29. package/plugins/interactive-blocks/directive-show/view.js +24 -0
  30. package/plugins/interactive-blocks/directive-style/block.json +14 -0
  31. package/plugins/interactive-blocks/directive-style/render.php +93 -0
  32. package/plugins/interactive-blocks/directive-style/view.js +22 -0
  33. package/plugins/interactive-blocks/directive-text/block.json +14 -0
  34. package/plugins/interactive-blocks/directive-text/render.php +35 -0
  35. package/plugins/interactive-blocks/directive-text/view.js +17 -0
  36. package/plugins/interactive-blocks/negation-operator/block.json +14 -0
  37. package/plugins/interactive-blocks/negation-operator/render.php +26 -0
  38. package/plugins/interactive-blocks/negation-operator/view.js +22 -0
  39. package/plugins/interactive-blocks/store-tag/block.json +14 -0
  40. package/plugins/interactive-blocks/store-tag/render.php +64 -0
  41. package/plugins/interactive-blocks/store-tag/view.js +24 -0
  42. package/plugins/interactive-blocks/tovdom/block.json +14 -0
  43. package/plugins/interactive-blocks/tovdom/cdata.js +15 -0
  44. package/plugins/interactive-blocks/tovdom/processing-instructions.js +16 -0
  45. package/plugins/interactive-blocks/tovdom/render.php +33 -0
  46. package/plugins/interactive-blocks/tovdom/view.js +5 -0
  47. package/plugins/interactive-blocks/tovdom-islands/block.json +14 -0
  48. package/plugins/interactive-blocks/tovdom-islands/render.php +66 -0
  49. package/plugins/interactive-blocks/tovdom-islands/view.js +9 -0
  50. package/plugins/interactive-blocks.php +48 -0
  51. package/specs/editor/plugins/__snapshots__/container-blocks.test.js.snap +5 -4
  52. package/specs/editor/plugins/container-blocks.test.js +2 -1
  53. package/specs/editor/plugins/iframed-equeue-block-assets.test.js +7 -0
  54. package/specs/editor/various/block-editor-keyboard-shortcuts.test.js +1 -1
  55. package/specs/editor/various/links.test.js +18 -11
  56. package/specs/editor/various/publish-button.test.js +0 -15
  57. package/specs/editor/various/reusable-blocks.test.js +7 -13
  58. package/specs/experiments/blocks/post-comments-form.test.js +1 -1
  59. package/specs/site-editor/multi-entity-saving.test.js +0 -102
  60. package/specs/site-editor/settings-sidebar.test.js +1 -1
  61. package/specs/editor/various/adding-inline-tokens.test.js +0 -80
package/CHANGELOG.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 7.9.0 (2023-07-20)
6
+
7
+ ## 7.8.0 (2023-07-05)
8
+
5
9
  ## 7.7.0 (2023-06-23)
6
10
 
7
11
  ## 7.6.0 (2023-06-07)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wordpress/e2e-tests",
3
- "version": "7.7.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.7.0",
27
- "@wordpress/jest-console": "^7.7.0",
28
- "@wordpress/jest-puppeteer-axe": "^6.7.0",
29
- "@wordpress/scripts": "^26.7.0",
30
- "@wordpress/url": "^3.37.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": "d47d8069e1aae05d4a16dc287902eb90edcbff50"
48
+ "gitHead": "6f14d11ed4cb59df110a28ebaa23ecba95eb673a"
49
49
  }
@@ -1,13 +1,16 @@
1
1
  ( function () {
2
2
  const { registerBlockType } = wp.blocks;
3
+ const { useBlockProps } = wp.blockEditor;
4
+ const { createElement: el } = wp.element;
3
5
  const { addFilter } = wp.hooks;
4
6
 
5
7
  registerBlockType( 'e2e-tests/hello-world', {
8
+ apiVersion: 3,
6
9
  title: 'Hello World',
7
10
  description: 'Hello World test block.',
8
11
  category: 'widgets',
9
- edit() {
10
- return 'Hello Editor!';
12
+ edit: function Edit() {
13
+ return el( 'p', useBlockProps(), 'Hello Editor!' );
11
14
  },
12
15
  save() {
13
16
  return 'Hello Frontend!';
@@ -16,6 +16,8 @@ function enqueue_block_api_plugin_script() {
16
16
  plugins_url( 'block-api/index.js', __FILE__ ),
17
17
  array(
18
18
  'wp-blocks',
19
+ 'wp-block-editor',
20
+ 'wp-element',
19
21
  'wp-hooks',
20
22
  ),
21
23
  filemtime( plugin_dir_path( __FILE__ ) . 'block-api/index.js' ),
@@ -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
  }
@@ -1,9 +1,10 @@
1
1
  ( function () {
2
2
  const registerBlockType = wp.blocks.registerBlockType;
3
- const RichText = wp.blockEditor.RichText;
3
+ const { useBlockProps, RichText } = wp.blockEditor;
4
4
  const el = wp.element.createElement;
5
5
 
6
6
  registerBlockType( 'core/deprecated-children-matcher', {
7
+ apiVersion: 3,
7
8
  title: 'Deprecated Children Matcher',
8
9
  attributes: {
9
10
  value: {
@@ -13,40 +14,35 @@
13
14
  },
14
15
  },
15
16
  category: 'text',
16
- edit( { attributes, setAttributes } ) {
17
+ edit: function EditChildrenMatcher( { attributes, setAttributes } ) {
17
18
  return el( RichText, {
18
19
  tagName: 'p',
19
20
  value: attributes.value,
20
21
  onChange( nextValue ) {
21
22
  setAttributes( { value: nextValue } );
22
23
  },
24
+ ...useBlockProps(),
23
25
  } );
24
26
  },
25
27
  save( { attributes } ) {
26
28
  return el( RichText.Content, {
27
29
  tagName: 'p',
28
30
  value: attributes.value,
31
+ ...useBlockProps.save(),
29
32
  } );
30
33
  },
31
34
  } );
32
35
 
33
36
  function toRichTextValue( value ) {
34
- // eslint-disable-next-line no-undef
35
- return _.map( value, function ( subValue ) {
36
- return subValue.children;
37
- } );
37
+ return value?.map( ( { children } ) => children ) ?? [];
38
38
  }
39
39
 
40
40
  function fromRichTextValue( value ) {
41
- // eslint-disable-next-line no-undef
42
- return _.map( value, function ( subValue ) {
43
- return {
44
- children: subValue,
45
- };
46
- } );
41
+ return value.map( ( subValue ) => ( { children: subValue } ) );
47
42
  }
48
43
 
49
44
  registerBlockType( 'core/deprecated-node-matcher', {
45
+ apiVersion: 3,
50
46
  title: 'Deprecated Node Matcher',
51
47
  attributes: {
52
48
  value: {
@@ -61,10 +57,10 @@
61
57
  },
62
58
  },
63
59
  category: 'text',
64
- edit( { attributes, setAttributes } ) {
60
+ edit: function EditNodeMatcher( { attributes, setAttributes } ) {
65
61
  return el(
66
62
  'blockquote',
67
- {},
63
+ useBlockProps(),
68
64
  el( RichText, {
69
65
  multiline: 'p',
70
66
  value: toRichTextValue( attributes.value ),
@@ -74,12 +70,12 @@
74
70
  } );
75
71
  },
76
72
  } )
77
- );
73
+ )
78
74
  },
79
75
  save( { attributes } ) {
80
76
  return el(
81
77
  'blockquote',
82
- {},
78
+ useBlockProps.save(),
83
79
  el( RichText.Content, {
84
80
  value: toRichTextValue( attributes.value ),
85
81
  } )
@@ -15,7 +15,6 @@ function enqueue_deprecated_node_matcher_plugin_script() {
15
15
  'gutenberg-test-deprecated-node-matcher',
16
16
  plugins_url( 'deprecated-node-matcher/index.js', __FILE__ ),
17
17
  array(
18
- 'lodash',
19
18
  'wp-blocks',
20
19
  'wp-element',
21
20
  'wp-block-editor',
@@ -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
  );
@@ -12,6 +12,7 @@
12
12
  const allowedBlocksWhenMultipleChildren = [ 'core/gallery', 'core/video' ];
13
13
 
14
14
  registerBlockType( 'test/allowed-blocks-dynamic', {
15
+ apiVersion: 3,
15
16
  title: 'Allowed Blocks Dynamic',
16
17
  icon: 'carrot',
17
18
  category: 'text',
@@ -2,7 +2,7 @@
2
2
  const registerBlockType = wp.blocks.registerBlockType;
3
3
  const createBlock = wp.blocks.createBlock;
4
4
  const el = wp.element.createElement;
5
- const InnerBlocks = wp.blockEditor.InnerBlocks;
5
+ const { InnerBlocks, useBlockProps } = wp.blockEditor;
6
6
  const useState = window.wp.element.useState;
7
7
 
8
8
  const TEMPLATE = [
@@ -47,35 +47,38 @@
47
47
  };
48
48
 
49
49
  registerBlockType( 'test/test-inner-blocks-no-locking', {
50
+ apiVersion: 3,
50
51
  title: 'Test Inner Blocks no locking',
51
52
  icon: 'cart',
52
53
  category: 'text',
53
54
 
54
- edit() {
55
- return el( InnerBlocks, {
55
+ edit: function InnerBlocksNoLockingEdit() {
56
+ return el( 'div', useBlockProps(), el( InnerBlocks, {
56
57
  template: TEMPLATE,
57
- } );
58
+ } ) );
58
59
  },
59
60
 
60
61
  save,
61
62
  } );
62
63
 
63
64
  registerBlockType( 'test/test-inner-blocks-locking-all', {
65
+ apiVersion: 3,
64
66
  title: 'Test InnerBlocks locking all',
65
67
  icon: 'cart',
66
68
  category: 'text',
67
69
 
68
- edit() {
69
- return el( InnerBlocks, {
70
+ edit: function InnerBlocksBlocksLockingAllEdit() {
71
+ return el( 'div', useBlockProps(), el( InnerBlocks, {
70
72
  template: TEMPLATE,
71
73
  templateLock: 'all',
72
- } );
74
+ } ) );
73
75
  },
74
76
 
75
77
  save,
76
78
  } );
77
79
 
78
80
  registerBlockType( 'test/test-inner-blocks-update-locked-template', {
81
+ apiVersion: 3,
79
82
  title: 'Test Inner Blocks update locked template',
80
83
  icon: 'cart',
81
84
  category: 'text',
@@ -87,7 +90,7 @@
87
90
  },
88
91
  },
89
92
 
90
- edit( props ) {
93
+ edit: function InnerBlocksUpdateLockedTemplateEdit( props ) {
91
94
  const hasUpdatedTemplated = props.attributes.hasUpdatedTemplate;
92
95
  return el( 'div', null, [
93
96
  el(
@@ -99,12 +102,12 @@
99
102
  },
100
103
  'Update template'
101
104
  ),
102
- el( InnerBlocks, {
105
+ el( 'div', useBlockProps(), el( InnerBlocks, {
103
106
  template: hasUpdatedTemplated
104
107
  ? TEMPLATE_TWO_PARAGRAPHS
105
108
  : TEMPLATE,
106
109
  templateLock: 'all',
107
- } ),
110
+ } ) ),
108
111
  ] );
109
112
  },
110
113
 
@@ -112,21 +115,23 @@
112
115
  } );
113
116
 
114
117
  registerBlockType( 'test/test-inner-blocks-paragraph-placeholder', {
118
+ apiVersion: 3,
115
119
  title: 'Test Inner Blocks Paragraph Placeholder',
116
120
  icon: 'cart',
117
121
  category: 'text',
118
122
 
119
- edit() {
120
- return el( InnerBlocks, {
123
+ edit: function InnerBlocksParagraphPlaceholderEdit() {
124
+ return el( 'div', useBlockProps(), el( InnerBlocks, {
121
125
  template: TEMPLATE_PARAGRAPH_PLACEHOLDER,
122
126
  templateInsertUpdatesSelection: true,
123
- } );
127
+ } ) );
124
128
  },
125
129
 
126
130
  save,
127
131
  } );
128
132
 
129
133
  registerBlockType( 'test/test-inner-blocks-transformer-target', {
134
+ apiVersion: 3,
130
135
  title: 'Test Inner Blocks transformer target',
131
136
  icon: 'cart',
132
137
  category: 'text',
@@ -165,36 +170,34 @@
165
170
  ],
166
171
  },
167
172
 
168
- edit() {
169
- return el( InnerBlocks, {
173
+ edit: function InnerBlocksTransformerTargetEdit() {
174
+ return el( 'div', useBlockProps(), el( InnerBlocks, {
170
175
  template: TEMPLATE,
171
- } );
176
+ } ) );
172
177
  },
173
178
 
174
179
  save,
175
180
  } );
176
181
 
177
-
178
- function InnerBlocksAsyncTemplateEdit() {
179
- const [ template, setTemplate ] = useState( [] );
180
-
181
- setInterval( () => {
182
- setTemplate( TEMPLATE_TWO_PARAGRAPHS );
183
- }, 1000 );
184
-
185
- return el( InnerBlocks, {
186
- template,
187
- } );
188
- }
189
-
190
182
  registerBlockType(
191
183
  'test/test-inner-blocks-async-template',
192
184
  {
185
+ apiVersion: 3,
193
186
  title: 'Test Inner Blocks Async Template',
194
187
  icon: 'cart',
195
188
  category: 'text',
196
189
 
197
- edit: InnerBlocksAsyncTemplateEdit,
190
+ edit: function InnerBlocksAsyncTemplateEdit() {
191
+ const [ template, setTemplate ] = useState( [] );
192
+
193
+ setInterval( () => {
194
+ setTemplate( TEMPLATE_TWO_PARAGRAPHS );
195
+ }, 1000 );
196
+
197
+ return el('div', useBlockProps(), el( InnerBlocks, {
198
+ template,
199
+ } ) );
200
+ },
198
201
 
199
202
  // Purposely do not save inner blocks so that it's possible to test template resolution.
200
203
  save() {},
@@ -0,0 +1,14 @@
1
+ {
2
+ "apiVersion": 2,
3
+ "name": "test/directive-bind",
4
+ "title": "E2E Interactivity tests - directive bind",
5
+ "category": "text",
6
+ "icon": "heart",
7
+ "description": "",
8
+ "supports": {
9
+ "interactivity": true
10
+ },
11
+ "textdomain": "e2e-interactivity",
12
+ "viewScript": "directive-bind-view",
13
+ "render": "file:./render.php"
14
+ }
@@ -0,0 +1,59 @@
1
+ <?php
2
+ /**
3
+ * HTML for testing the directive `data-wp-bind`.
4
+ *
5
+ * @package gutenberg-test-interactive-blocks
6
+ */
7
+
8
+ ?>
9
+ <div data-wp-interactive>
10
+ <a
11
+ data-wp-bind--href="state.url"
12
+ data-testid="add missing href at hydration"
13
+ ></a>
14
+
15
+ <a
16
+ href="/other-url"
17
+ data-wp-bind--href="state.url"
18
+ data-testid="change href at hydration"
19
+ ></a>
20
+
21
+ <input
22
+ type="checkbox"
23
+ data-wp-bind--checked="state.checked"
24
+ data-testid="add missing checked at hydration"
25
+ />
26
+
27
+ <input
28
+ type="checkbox"
29
+ checked
30
+ data-wp-bind--checked="!state.checked"
31
+ data-testid="remove existing checked at hydration"
32
+ />
33
+
34
+ <a
35
+ href="/other-url"
36
+ data-wp-bind--href="state.url"
37
+ data-testid="nested binds - 1"
38
+ >
39
+ <img
40
+ width="1"
41
+ data-wp-bind--width="state.width"
42
+ data-testid="nested binds - 2"
43
+ />
44
+ </a>
45
+
46
+ <button data-testid="toggle" data-wp-on--click="actions.toggle">
47
+ Update
48
+ </button>
49
+
50
+ <p
51
+ data-wp-bind--hidden="!state.show"
52
+ data-wp-bind--aria-hidden="!state.show"
53
+ data-wp-bind--aria-expanded="state.show"
54
+ data-wp-bind--data-some-value="state.show"
55
+ data-testid="check enumerated attributes with true/false exist and have a string value"
56
+ >
57
+ Some Text
58
+ </p>
59
+ </div>
@@ -0,0 +1,23 @@
1
+ ( ( { wp } ) => {
2
+ const { store } = wp.interactivity;
3
+
4
+ store( {
5
+ state: {
6
+ url: '/some-url',
7
+ checked: true,
8
+ show: false,
9
+ width: 1,
10
+ },
11
+ foo: {
12
+ bar: 1,
13
+ },
14
+ actions: {
15
+ toggle: ( { state, foo } ) => {
16
+ state.url = '/some-other-url';
17
+ state.checked = ! state.checked;
18
+ state.show = ! state.show;
19
+ state.width += foo.bar;
20
+ },
21
+ },
22
+ } );
23
+ } )( window );
@@ -0,0 +1,14 @@
1
+ {
2
+ "apiVersion": 2,
3
+ "name": "test/directive-class",
4
+ "title": "E2E Interactivity tests - directive class",
5
+ "category": "text",
6
+ "icon": "heart",
7
+ "description": "",
8
+ "supports": {
9
+ "interactivity": true
10
+ },
11
+ "textdomain": "e2e-interactivity",
12
+ "viewScript": "directive-class-view",
13
+ "render": "file:./render.php"
14
+ }
@@ -0,0 +1,75 @@
1
+ <?php
2
+ /**
3
+ * HTML for testing the directive `data-wp-class`.
4
+ *
5
+ * @package gutenberg-test-interactive-blocks
6
+ */
7
+
8
+ ?>
9
+ <div data-wp-interactive>
10
+ <button
11
+ data-wp-on--click="actions.toggleTrueValue"
12
+ data-testid="toggle trueValue"
13
+ >
14
+ Toggle trueValue
15
+ </button>
16
+
17
+ <button
18
+ data-wp-on--click="actions.toggleFalseValue"
19
+ data-testid="toggle falseValue"
20
+ >
21
+ Toggle falseValue
22
+ </button>
23
+
24
+ <div
25
+ class="foo bar"
26
+ data-wp-class--foo="state.falseValue"
27
+ data-testid="remove class if callback returns falsy value"
28
+ ></div>
29
+
30
+ <div
31
+ class="foo"
32
+ data-wp-class--bar="state.trueValue"
33
+ data-testid="add class if callback returns truthy value"
34
+ ></div>
35
+
36
+ <div
37
+ class="foo bar"
38
+ data-wp-class--foo="state.falseValue"
39
+ data-wp-class--bar="state.trueValue"
40
+ data-wp-class--baz="state.trueValue"
41
+ data-testid="handles multiple classes and callbacks"
42
+ ></div>
43
+
44
+ <div
45
+ class="foo foo-bar"
46
+ data-wp-class--foo="state.falseValue"
47
+ data-wp-class--foo-bar="state.trueValue"
48
+ data-testid="handles class names that are contained inside other class names"
49
+ ></div>
50
+
51
+ <div
52
+ class="foo bar baz"
53
+ data-wp-class--bar="state.trueValue"
54
+ data-testid="can toggle class in the middle"
55
+ ></div>
56
+
57
+ <div
58
+ data-wp-class--foo="state.falseValue"
59
+ data-testid="can toggle class when class attribute is missing"
60
+ ></div>
61
+
62
+ <div data-wp-context='{ "falseValue": false }'>
63
+ <div
64
+ class="foo"
65
+ data-wp-class--foo="context.falseValue"
66
+ data-testid="can use context values"
67
+ ></div>
68
+ <button
69
+ data-wp-on--click="actions.toggleContextFalseValue"
70
+ data-testid="toggle context false value"
71
+ >
72
+ Toggle context falseValue
73
+ </button>
74
+ </div>
75
+ </div>
@@ -0,0 +1,21 @@
1
+ ( ( { wp } ) => {
2
+ const { store } = wp.interactivity;
3
+
4
+ store( {
5
+ state: {
6
+ trueValue: true,
7
+ falseValue: false,
8
+ },
9
+ actions: {
10
+ toggleTrueValue: ( { state } ) => {
11
+ state.trueValue = ! state.trueValue;
12
+ },
13
+ toggleFalseValue: ( { state } ) => {
14
+ state.falseValue = ! state.falseValue;
15
+ },
16
+ toggleContextFalseValue: ( { context } ) => {
17
+ context.falseValue = ! context.falseValue;
18
+ },
19
+ },
20
+ } );
21
+ } )( window );
@@ -0,0 +1,14 @@
1
+ {
2
+ "apiVersion": 2,
3
+ "name": "test/directive-context",
4
+ "title": "E2E Interactivity tests - directive context",
5
+ "category": "text",
6
+ "icon": "heart",
7
+ "description": "",
8
+ "supports": {
9
+ "interactivity": true
10
+ },
11
+ "textdomain": "e2e-interactivity",
12
+ "viewScript": "directive-context-view",
13
+ "render": "file:./render.php"
14
+ }