@wordpress/e2e-tests 7.22.1 → 7.22.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wordpress/e2e-tests",
3
- "version": "7.22.1",
3
+ "version": "7.22.3",
4
4
  "description": "End-To-End (E2E) tests for WordPress.",
5
5
  "author": "The WordPress Contributors",
6
6
  "license": "GPL-2.0-or-later",
@@ -24,11 +24,11 @@
24
24
  },
25
25
  "dependencies": {
26
26
  "@wordpress/e2e-test-utils": "^10.22.1",
27
- "@wordpress/interactivity": "^5.0.1",
28
- "@wordpress/interactivity-router": "^1.1.1",
27
+ "@wordpress/interactivity": "^5.0.2",
28
+ "@wordpress/interactivity-router": "^1.1.2",
29
29
  "@wordpress/jest-console": "^7.22.1",
30
30
  "@wordpress/jest-puppeteer-axe": "^6.22.1",
31
- "@wordpress/scripts": "^27.2.1",
31
+ "@wordpress/scripts": "^27.2.3",
32
32
  "@wordpress/url": "^3.52.1",
33
33
  "chalk": "^4.0.0",
34
34
  "expect-puppeteer": "^4.4.0",
@@ -46,5 +46,5 @@
46
46
  "publishConfig": {
47
47
  "access": "public"
48
48
  },
49
- "gitHead": "730beb7fd33d3382d6032c3f33e451625a0fcf36"
49
+ "gitHead": "864c1c553cb284def3bd5c907998da45f5c143ea"
50
50
  }
@@ -18,6 +18,7 @@ wp_enqueue_script_module( 'directive-context-view' );
18
18
  >
19
19
  <!-- rendered during hydration -->
20
20
  </pre>
21
+ <button data-testid="parent replace" data-wp-on--click="actions.replaceObj">Replace obj</button>
21
22
  <button
22
23
  data-testid="parent prop1"
23
24
  name="prop1"
@@ -50,6 +51,14 @@ wp_enqueue_script_module( 'directive-context-view' );
50
51
  >
51
52
  obj.prop5
52
53
  </button>
54
+ <button
55
+ data-testid="parent new"
56
+ name="new"
57
+ value="modifiedFromParent"
58
+ data-wp-on--click="actions.updateContext"
59
+ >
60
+ new
61
+ </button>
53
62
  <div
54
63
  data-wp-context='{ "prop2":"child","prop3":"child","obj":{"prop5":"child","prop6":"child"},"array":[4,5,6] }'
55
64
  >
@@ -59,6 +68,7 @@ wp_enqueue_script_module( 'directive-context-view' );
59
68
  >
60
69
  <!-- rendered during hydration -->
61
70
  </pre>
71
+ <button data-testid="child replace" data-wp-on--click="actions.replaceObj">Replace obj</button>
62
72
  <button
63
73
  data-testid="child prop1"
64
74
  name="prop1"
@@ -127,10 +137,15 @@ wp_enqueue_script_module( 'directive-context-view' );
127
137
  data-wp-router-region="navigation"
128
138
  data-wp-context='{ "text": "first page" }'
129
139
  >
140
+ <div data-wp-context='{}'>
141
+ <div data-testid="navigation inherited text" data-wp-text="context.text"></div>
142
+ <div data-testid="navigation inherited text2" data-wp-text="context.text2"></div>
143
+ </div>
130
144
  <div data-testid="navigation text" data-wp-text="context.text"></div>
131
145
  <div data-testid="navigation new text" data-wp-text="context.newText"></div>
132
146
  <button data-testid="toggle text" data-wp-on--click="actions.toggleText">Toggle Text</button>
133
147
  <button data-testid="add new text" data-wp-on--click="actions.addNewText">Add New Text</button>
148
+ <button data-testid="add text2" data-wp-on--click="actions.addText2">Add Text 2</button>
134
149
  <button data-testid="navigate" data-wp-on--click="actions.navigate">Navigate</button>
135
150
  <button data-testid="async navigate" data-wp-on--click="actions.asyncNavigate">Async Navigate</button>
136
151
  </div>
@@ -143,3 +158,41 @@ wp_enqueue_script_module( 'directive-context-view' );
143
158
  <span data-testid="non-default suffix context" data-wp-text="context.text"></span>
144
159
  <span data-testid="default suffix context" data-wp-text="context.defaultText"></span>
145
160
  </div>
161
+
162
+ <div
163
+ data-wp-interactive='directive-context'
164
+ data-wp-context='{ "list": [
165
+ { "id": 1, "text": "Text 1" },
166
+ { "id": 2, "text": "Text 2" }
167
+ ] }'
168
+ >
169
+ <button data-testid="select 1" data-wp-on--click="actions.selectItem" value=1>Select 1</button>
170
+ <button data-testid="select 2" data-wp-on--click="actions.selectItem" value=2>Select 2</button>
171
+ <div data-testid="selected" data-wp-text="state.selected"></div>
172
+ </div>
173
+
174
+ <div
175
+ data-wp-interactive="directive-context-watch"
176
+ data-wp-context='{"counter":0}'
177
+ >
178
+ <button
179
+ data-testid="counter parent"
180
+ data-wp-on--click="actions.increment"
181
+ data-wp-text="context.counter"
182
+ ></button>
183
+ <div
184
+ data-wp-context='{"counter":0, "changes":0}'
185
+ data-wp-watch="callbacks.countChanges"
186
+ >
187
+ <button
188
+ data-testid="counter child"
189
+ data-wp-on--click="actions.increment"
190
+ data-wp-text="context.counter"
191
+ >
192
+ </button>
193
+ <span
194
+ data-testid="counter changes"
195
+ data-wp-text="context.changes"
196
+ ></span>
197
+ </div>
198
+ </div>
@@ -9,6 +9,10 @@ store( 'directive-context', {
9
9
  const ctx = getContext();
10
10
  return JSON.stringify( ctx, undefined, 2 );
11
11
  },
12
+ get selected() {
13
+ const { list, selected } = getContext();
14
+ return list.find( ( obj ) => obj === selected )?.text;
15
+ }
12
16
  },
13
17
  actions: {
14
18
  updateContext( event ) {
@@ -22,6 +26,15 @@ store( 'directive-context', {
22
26
  const ctx = getContext();
23
27
  ctx.text = ctx.text === 'Text 1' ? 'Text 2' : 'Text 1';
24
28
  },
29
+ selectItem( event ) {
30
+ const ctx = getContext();
31
+ const value = parseInt( event.target.value );
32
+ ctx.selected = ctx.list.find( ( { id } ) => id === value );
33
+ },
34
+ replaceObj() {
35
+ const ctx = getContext();
36
+ ctx.obj = { overwritten: true };
37
+ }
25
38
  },
26
39
  } );
27
40
 
@@ -29,12 +42,17 @@ const html = `
29
42
  <div
30
43
  data-wp-interactive='{ "namespace": "directive-context-navigate" }'
31
44
  data-wp-router-region="navigation"
32
- data-wp-context='{ "text": "second page" }'
45
+ data-wp-context='{ "text": "second page", "text2": "second page" }'
33
46
  >
47
+ <div data-wp-context='{}'>
48
+ <div data-testid="navigation inherited text" data-wp-text="context.text"></div>
49
+ <div data-testid="navigation inherited text2" data-wp-text="context.text2"></div>
50
+ </div>
34
51
  <div data-testid="navigation text" data-wp-text="context.text"></div>
35
52
  <div data-testid="navigation new text" data-wp-text="context.newText"></div>
36
53
  <button data-testid="toggle text" data-wp-on--click="actions.toggleText">Toggle Text</button>
37
- <button data-testid="add new text" data-wp-on--click="actions.addNewText">Add new text</button>
54
+ <button data-testid="add new text" data-wp-on--click="actions.addNewText">Add New Text</button>
55
+ <button data-testid="add text2" data-wp-on--click="actions.addText2">Add Text 2</button>
38
56
  <button data-testid="navigate" data-wp-on--click="actions.navigate">Navigate</button>
39
57
  <button data-testid="async navigate" data-wp-on--click="actions.asyncNavigate">Async Navigate</button>
40
58
  </div>`;
@@ -49,13 +67,17 @@ const { actions } = store( 'directive-context-navigate', {
49
67
  const ctx = getContext();
50
68
  ctx.newText = 'some new text';
51
69
  },
70
+ addText2() {
71
+ const ctx = getContext();
72
+ ctx.text2 = 'some new text';
73
+ },
52
74
  navigate() {
53
75
  return import( '@wordpress/interactivity-router' ).then(
54
- ( { actions: routerActions } ) =>
55
- routerActions.navigate(
56
- window.location,
57
- { force: true, html },
58
- )
76
+ ( { actions: routerActions } ) => {
77
+ const url = new URL( window.location.href );
78
+ url.searchParams.set( 'next_page', 'true' );
79
+ return routerActions.navigate( url, { force: true, html } );
80
+ }
59
81
  );
60
82
 
61
83
  },
@@ -66,3 +88,21 @@ const { actions } = store( 'directive-context-navigate', {
66
88
  },
67
89
  },
68
90
  } );
91
+
92
+ store( 'directive-context-watch', {
93
+ actions: {
94
+ increment: () => {
95
+ const ctx = getContext();
96
+ ctx.counter = ctx.counter + 1;
97
+ },
98
+ },
99
+ callbacks: {
100
+ countChanges: () => {
101
+ const ctx = getContext();
102
+ // Subscribe to changes in counter.
103
+ // eslint-disable-next-line no-unused-expressions
104
+ ctx.counter;
105
+ ctx.changes = ctx.changes + 1;
106
+ },
107
+ },
108
+ });
@@ -15,17 +15,28 @@ if ( $attributes['disableNavigation'] ) {
15
15
  array( 'clientNavigationDisabled' => true )
16
16
  );
17
17
  }
18
+
19
+ if ( isset( $attributes['data'] ) ) {
20
+ wp_interactivity_state(
21
+ 'router',
22
+ array( 'data' => $attributes['data'] )
23
+ );
24
+ }
18
25
  ?>
19
26
 
20
27
  <div
21
- data-wp-interactive='{ "namespace": "router" }'
28
+ data-wp-interactive="router"
22
29
  data-wp-router-region="region-1"
23
30
  >
24
31
  <h2 data-testid="title"><?php echo $attributes['title']; ?></h2>
25
32
 
26
33
  <output
27
- data-testid="router navigations"
28
- data-wp-text="state.navigations"
34
+ data-testid="router navigations pending"
35
+ data-wp-text="state.navigations.pending"
36
+ >NaN</output>
37
+ <output
38
+ data-testid="router navigations count"
39
+ data-wp-text="state.navigations.count"
29
40
  >NaN</output>
30
41
  <output
31
42
  data-testid="router status"
@@ -39,24 +50,30 @@ if ( $attributes['disableNavigation'] ) {
39
50
  Timeout <span data-wp-text="state.timeout">NaN</span>
40
51
  </button>
41
52
 
42
- <?php
43
- if ( isset( $attributes['links'] ) ) {
44
- foreach ( $attributes['links'] as $key => $link ) {
45
- $i = $key += 1;
46
- echo <<<HTML
47
- <a
48
- data-testid="link $i"
49
- data-wp-on--click="actions.navigate"
50
- href="$link"
51
- >link $i</a>
52
- <a
53
- data-testid="link $i with hash"
54
- data-wp-on--click="actions.navigate"
55
- data-force-navigation="true"
56
- href="$link#link-$i-with-hash"
57
- >link $i with hash</a>
53
+ <nav>
54
+ <?php
55
+ if ( isset( $attributes['links'] ) ) {
56
+ foreach ( $attributes['links'] as $key => $link ) {
57
+ $i = $key += 1;
58
+ echo <<<HTML
59
+ <a
60
+ data-testid="link $i"
61
+ data-wp-on--click="actions.navigate"
62
+ href="$link"
63
+ >link $i</a>
64
+ <a
65
+ data-testid="link $i with hash"
66
+ data-wp-on--click="actions.navigate"
67
+ data-force-navigation="true"
68
+ href="$link#link-$i-with-hash"
69
+ >link $i with hash</a>
58
70
  HTML;
71
+ }
59
72
  }
60
- }
61
- ?>
73
+ ?>
74
+ </nav>
75
+ <div data-testid="getterProp" data-wp-text="state.data.getterProp"></div>
76
+ <div data-testid="prop1" data-wp-text="state.data.prop1"></div>
77
+ <div data-testid="prop2" data-wp-text="state.data.prop2"></div>
78
+ <div data-testid="prop3" data-wp-text="state.data.prop3"></div>
62
79
  </div>
@@ -6,14 +6,23 @@ import { store } from '@wordpress/interactivity';
6
6
  const { state } = store( 'router', {
7
7
  state: {
8
8
  status: 'idle',
9
- navigations: 0,
9
+ navigations: {
10
+ pending: 0,
11
+ count: 0,
12
+ },
10
13
  timeout: 10000,
14
+ data: {
15
+ get getterProp() {
16
+ return `value from getter (${ state.data.prop1 })`;
17
+ }
18
+ }
11
19
  },
12
20
  actions: {
13
21
  *navigate( e ) {
14
22
  e.preventDefault();
15
23
 
16
- state.navigations += 1;
24
+ state.navigations.count += 1;
25
+ state.navigations.pending += 1;
17
26
  state.status = 'busy';
18
27
 
19
28
  const force = e.target.dataset.forceNavigation === 'true';
@@ -24,9 +33,9 @@ const { state } = store( 'router', {
24
33
  );
25
34
  yield actions.navigate( e.target.href, { force, timeout } );
26
35
 
27
- state.navigations -= 1;
36
+ state.navigations.pending -= 1;
28
37
 
29
- if ( state.navigations === 0 ) {
38
+ if ( state.navigations.pending === 0 ) {
30
39
  state.status = 'idle';
31
40
  }
32
41
  },
@@ -0,0 +1,15 @@
1
+ {
2
+ "$schema": "https://schemas.wp.org/trunk/block.json",
3
+ "apiVersion": 2,
4
+ "name": "test/store",
5
+ "title": "E2E Interactivity tests - store definition",
6
+ "category": "text",
7
+ "icon": "heart",
8
+ "description": "",
9
+ "supports": {
10
+ "interactivity": true
11
+ },
12
+ "textdomain": "e2e-interactivity",
13
+ "viewScript": "store-view",
14
+ "render": "file:./render.php"
15
+ }
@@ -0,0 +1,17 @@
1
+ <?php
2
+ /**
3
+ * HTML for testing the directive `data-wp-bind`.
4
+ *
5
+ * @package gutenberg-test-interactive-blocks
6
+ */
7
+
8
+ wp_enqueue_script_module( 'store-view' );
9
+ ?>
10
+
11
+ <div data-wp-interactive="test/store">
12
+ <div
13
+ data-testid="non-plain object"
14
+ data-wp-text="state.isNotProxified"
15
+ data-wp-init="callbacks.init"
16
+ ></div>
17
+ </div>
@@ -0,0 +1,20 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import { store, getElement } from '@wordpress/interactivity';
5
+
6
+
7
+ const { state } = store( 'test/store', {
8
+ state: {
9
+ get isNotProxified() {
10
+ const { ref } = getElement();
11
+ return state.elementRef === ref;
12
+ }
13
+ },
14
+ callbacks: {
15
+ init() {
16
+ const { ref } = getElement();
17
+ state.elementRef = ref; // HTMLElement
18
+ }
19
+ }
20
+ } )