@wordpress/e2e-tests 7.7.0 → 7.8.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 +2 -0
- package/package.json +7 -7
- package/plugins/block-api/index.js +5 -2
- package/plugins/block-api.php +2 -0
- package/plugins/deprecated-node-matcher/index.js +12 -16
- package/plugins/deprecated-node-matcher.php +0 -1
- package/plugins/inner-blocks-allowed-blocks/index.js +1 -0
- package/plugins/inner-blocks-templates/index.js +33 -30
- package/plugins/interactive-blocks/directive-bind/block.json +14 -0
- package/plugins/interactive-blocks/directive-bind/render.php +59 -0
- package/plugins/interactive-blocks/directive-bind/view.js +23 -0
- package/plugins/interactive-blocks/directive-class/block.json +14 -0
- package/plugins/interactive-blocks/directive-class/render.php +75 -0
- package/plugins/interactive-blocks/directive-class/view.js +21 -0
- package/plugins/interactive-blocks/directive-context/block.json +14 -0
- package/plugins/interactive-blocks/directive-context/render.php +121 -0
- package/plugins/interactive-blocks/directive-context/view.js +22 -0
- package/plugins/interactive-blocks/directive-effect/block.json +14 -0
- package/plugins/interactive-blocks/directive-effect/render.php +27 -0
- package/plugins/interactive-blocks/directive-effect/view.js +61 -0
- package/plugins/interactive-blocks/directive-priorities/block.json +14 -0
- package/plugins/interactive-blocks/directive-priorities/render.php +20 -0
- package/plugins/interactive-blocks/directive-priorities/view.js +121 -0
- package/plugins/interactive-blocks/directive-show/block.json +14 -0
- package/plugins/interactive-blocks/directive-show/render.php +53 -0
- package/plugins/interactive-blocks/directive-show/view.js +24 -0
- package/plugins/interactive-blocks/directive-text/block.json +14 -0
- package/plugins/interactive-blocks/directive-text/render.php +35 -0
- package/plugins/interactive-blocks/directive-text/view.js +17 -0
- package/plugins/interactive-blocks/negation-operator/block.json +14 -0
- package/plugins/interactive-blocks/negation-operator/render.php +26 -0
- package/plugins/interactive-blocks/negation-operator/view.js +22 -0
- package/plugins/interactive-blocks/store-tag/block.json +14 -0
- package/plugins/interactive-blocks/store-tag/render.php +64 -0
- package/plugins/interactive-blocks/store-tag/view.js +24 -0
- package/plugins/interactive-blocks/tovdom/block.json +14 -0
- package/plugins/interactive-blocks/tovdom/cdata.js +15 -0
- package/plugins/interactive-blocks/tovdom/processing-instructions.js +16 -0
- package/plugins/interactive-blocks/tovdom/render.php +33 -0
- package/plugins/interactive-blocks/tovdom/view.js +5 -0
- package/plugins/interactive-blocks/tovdom-islands/block.json +14 -0
- package/plugins/interactive-blocks/tovdom-islands/render.php +66 -0
- package/plugins/interactive-blocks/tovdom-islands/view.js +9 -0
- package/plugins/interactive-blocks.php +48 -0
- package/specs/editor/plugins/container-blocks.test.js +2 -1
- package/specs/editor/various/block-editor-keyboard-shortcuts.test.js +1 -1
- package/specs/editor/various/links.test.js +18 -11
- package/specs/editor/various/reusable-blocks.test.js +5 -5
- package/specs/experiments/blocks/post-comments-form.test.js +1 -1
- package/specs/site-editor/settings-sidebar.test.js +1 -1
@@ -0,0 +1,22 @@
|
|
1
|
+
( ( { wp } ) => {
|
2
|
+
const { store } = wp.interactivity;
|
3
|
+
|
4
|
+
store( {
|
5
|
+
derived: {
|
6
|
+
renderContext: ( { context } ) => {
|
7
|
+
return JSON.stringify( context, undefined, 2 );
|
8
|
+
},
|
9
|
+
},
|
10
|
+
actions: {
|
11
|
+
updateContext: ( { context, event } ) => {
|
12
|
+
const { name, value } = event.target;
|
13
|
+
const [ key, ...path ] = name.split( '.' ).reverse();
|
14
|
+
const obj = path.reduceRight( ( o, k ) => o[ k ], context );
|
15
|
+
obj[ key ] = value;
|
16
|
+
},
|
17
|
+
toggleContextText: ( { context } ) => {
|
18
|
+
context.text = context.text === 'Text 1' ? 'Text 2' : 'Text 1';
|
19
|
+
},
|
20
|
+
},
|
21
|
+
} );
|
22
|
+
} )( window );
|
@@ -0,0 +1,14 @@
|
|
1
|
+
{
|
2
|
+
"apiVersion": 2,
|
3
|
+
"name": "test/directive-effect",
|
4
|
+
"title": "E2E Interactivity tests - directive effect",
|
5
|
+
"category": "text",
|
6
|
+
"icon": "heart",
|
7
|
+
"description": "",
|
8
|
+
"supports": {
|
9
|
+
"interactivity": true
|
10
|
+
},
|
11
|
+
"textdomain": "e2e-interactivity",
|
12
|
+
"viewScript": "directive-effect-view",
|
13
|
+
"render": "file:./render.php"
|
14
|
+
}
|
@@ -0,0 +1,27 @@
|
|
1
|
+
<?php
|
2
|
+
/**
|
3
|
+
* HTML for testing the directive `data-wp-effect`.
|
4
|
+
*
|
5
|
+
* @package gutenberg-test-interactive-blocks
|
6
|
+
*/
|
7
|
+
|
8
|
+
?>
|
9
|
+
<div data-wp-interactive>
|
10
|
+
<div data-wp-fakeshow="state.isOpen">
|
11
|
+
<input
|
12
|
+
data-testid="input"
|
13
|
+
data-wp-effect="effects.elementAddedToTheDOM"
|
14
|
+
/>
|
15
|
+
</div>
|
16
|
+
|
17
|
+
<div
|
18
|
+
data-wp-text="selectors.elementInTheDOM"
|
19
|
+
data-testid="element in the DOM"
|
20
|
+
></div>
|
21
|
+
|
22
|
+
<div data-wp-effect="effects.changeFocus"></div>
|
23
|
+
|
24
|
+
<button data-testid="toggle" data-wp-on--click="actions.toggle">
|
25
|
+
Update
|
26
|
+
</button>
|
27
|
+
</div>
|
@@ -0,0 +1,61 @@
|
|
1
|
+
( ( { wp } ) => {
|
2
|
+
const { store, directive, useContext, useMemo } = wp.interactivity;
|
3
|
+
|
4
|
+
// Fake `data-wp-fakeshow` directive to test when things are removed from the DOM.
|
5
|
+
// Replace with `data-wp-show` when it's ready.
|
6
|
+
directive(
|
7
|
+
'fakeshow',
|
8
|
+
( {
|
9
|
+
directives: {
|
10
|
+
fakeshow: { default: fakeshow },
|
11
|
+
},
|
12
|
+
element,
|
13
|
+
evaluate,
|
14
|
+
context,
|
15
|
+
} ) => {
|
16
|
+
const contextValue = useContext( context );
|
17
|
+
const children = useMemo(
|
18
|
+
() =>
|
19
|
+
element.type === 'template'
|
20
|
+
? element.props.templateChildren
|
21
|
+
: element,
|
22
|
+
[]
|
23
|
+
);
|
24
|
+
if ( ! evaluate( fakeshow, { context: contextValue } ) ) return null;
|
25
|
+
return children;
|
26
|
+
}
|
27
|
+
);
|
28
|
+
|
29
|
+
store( {
|
30
|
+
state: {
|
31
|
+
isOpen: true,
|
32
|
+
isElementInTheDOM: false,
|
33
|
+
},
|
34
|
+
selectors: {
|
35
|
+
elementInTheDOM: ( { state } ) =>
|
36
|
+
state.isElementInTheDOM
|
37
|
+
? 'element is in the DOM'
|
38
|
+
: 'element is not in the DOM',
|
39
|
+
},
|
40
|
+
actions: {
|
41
|
+
toggle( { state } ) {
|
42
|
+
state.isOpen = ! state.isOpen;
|
43
|
+
},
|
44
|
+
},
|
45
|
+
effects: {
|
46
|
+
elementAddedToTheDOM: ( { state } ) => {
|
47
|
+
state.isElementInTheDOM = true;
|
48
|
+
|
49
|
+
return () => {
|
50
|
+
state.isElementInTheDOM = false;
|
51
|
+
};
|
52
|
+
},
|
53
|
+
changeFocus: ( { state } ) => {
|
54
|
+
if ( state.isOpen ) {
|
55
|
+
document.querySelector( "[data-testid='input']" ).focus();
|
56
|
+
}
|
57
|
+
},
|
58
|
+
},
|
59
|
+
} );
|
60
|
+
|
61
|
+
} )( window );
|
@@ -0,0 +1,14 @@
|
|
1
|
+
{
|
2
|
+
"apiVersion": 2,
|
3
|
+
"name": "test/directive-priorities",
|
4
|
+
"title": "E2E Interactivity tests - directive priorities",
|
5
|
+
"category": "text",
|
6
|
+
"icon": "heart",
|
7
|
+
"description": "",
|
8
|
+
"supports": {
|
9
|
+
"interactivity": true
|
10
|
+
},
|
11
|
+
"textdomain": "e2e-interactivity",
|
12
|
+
"viewScript": "directive-priorities-view",
|
13
|
+
"render": "file:./render.php"
|
14
|
+
}
|
@@ -0,0 +1,20 @@
|
|
1
|
+
<?php
|
2
|
+
/**
|
3
|
+
* HTML for testing priorities between directives.
|
4
|
+
*
|
5
|
+
* @package gutenberg-test-interactive-blocks
|
6
|
+
*/
|
7
|
+
|
8
|
+
?>
|
9
|
+
<div data-wp-interactive>
|
10
|
+
<pre data-testid="execution order"></pre>
|
11
|
+
|
12
|
+
<!-- Element with test directives -->
|
13
|
+
<div
|
14
|
+
data-testid="test directives"
|
15
|
+
data-wp-test-attribute
|
16
|
+
data-wp-test-children
|
17
|
+
data-wp-test-text
|
18
|
+
data-wp-test-context
|
19
|
+
></div>
|
20
|
+
</div>
|
@@ -0,0 +1,121 @@
|
|
1
|
+
( ( { wp } ) => {
|
2
|
+
/**
|
3
|
+
* WordPress dependencies
|
4
|
+
*/
|
5
|
+
const {
|
6
|
+
store,
|
7
|
+
directive,
|
8
|
+
deepSignal,
|
9
|
+
useContext,
|
10
|
+
useEffect,
|
11
|
+
createElement: h
|
12
|
+
} = wp.interactivity;
|
13
|
+
|
14
|
+
/**
|
15
|
+
* Util to check that render calls happen in order.
|
16
|
+
*
|
17
|
+
* @param {string} n Name passed from the directive being executed.
|
18
|
+
*/
|
19
|
+
const executionProof = ( n ) => {
|
20
|
+
const el = document.querySelector( '[data-testid="execution order"]' );
|
21
|
+
if ( ! el.textContent ) el.textContent = n;
|
22
|
+
else el.textContent += `, ${ n }`;
|
23
|
+
};
|
24
|
+
|
25
|
+
/**
|
26
|
+
* Simple context directive, just for testing purposes. It provides a deep
|
27
|
+
* signal with these two properties:
|
28
|
+
* - attribute: 'from context'
|
29
|
+
* - text: 'from context'
|
30
|
+
*/
|
31
|
+
directive(
|
32
|
+
'test-context',
|
33
|
+
( { context: { Provider }, props: { children } } ) => {
|
34
|
+
executionProof( 'context' );
|
35
|
+
const value = deepSignal( {
|
36
|
+
attribute: 'from context',
|
37
|
+
text: 'from context',
|
38
|
+
} );
|
39
|
+
return h( Provider, { value }, children );
|
40
|
+
},
|
41
|
+
{ priority: 8 }
|
42
|
+
);
|
43
|
+
|
44
|
+
/**
|
45
|
+
* Simple attribute directive, for testing purposes. It reads the value of
|
46
|
+
* `attribute` from context and populates `data-attribute` with it.
|
47
|
+
*/
|
48
|
+
directive( 'test-attribute', ( { context, evaluate, element } ) => {
|
49
|
+
executionProof( 'attribute' );
|
50
|
+
const contextValue = useContext( context );
|
51
|
+
const attributeValue = evaluate( 'context.attribute', {
|
52
|
+
context: contextValue,
|
53
|
+
} );
|
54
|
+
useEffect( () => {
|
55
|
+
element.ref.current.setAttribute(
|
56
|
+
'data-attribute',
|
57
|
+
attributeValue,
|
58
|
+
);
|
59
|
+
}, [] );
|
60
|
+
element.props[ 'data-attribute' ] = attributeValue;
|
61
|
+
} );
|
62
|
+
|
63
|
+
/**
|
64
|
+
* Simple text directive, for testing purposes. It reads the value of
|
65
|
+
* `text` from context and populates `children` with it.
|
66
|
+
*/
|
67
|
+
directive(
|
68
|
+
'test-text',
|
69
|
+
( { context, evaluate, element } ) => {
|
70
|
+
executionProof( 'text' );
|
71
|
+
const contextValue = useContext( context );
|
72
|
+
const textValue = evaluate( 'context.text', {
|
73
|
+
context: contextValue,
|
74
|
+
} );
|
75
|
+
element.props.children =
|
76
|
+
h( 'p', { 'data-testid': 'text' }, textValue );
|
77
|
+
},
|
78
|
+
{ priority: 12 }
|
79
|
+
);
|
80
|
+
|
81
|
+
/**
|
82
|
+
* Children directive, for testing purposes. It adds a wrapper around
|
83
|
+
* `children`, including two buttons to modify `text` and `attribute` values
|
84
|
+
* from the received context.
|
85
|
+
*/
|
86
|
+
directive(
|
87
|
+
'test-children',
|
88
|
+
( { context, evaluate, element } ) => {
|
89
|
+
executionProof( 'children' );
|
90
|
+
const contextValue = useContext( context );
|
91
|
+
const updateAttribute = () => {
|
92
|
+
evaluate(
|
93
|
+
'actions.updateAttribute',
|
94
|
+
{ context: contextValue }
|
95
|
+
);
|
96
|
+
};
|
97
|
+
const updateText = () => {
|
98
|
+
evaluate( 'actions.updateText', { context: contextValue } );
|
99
|
+
};
|
100
|
+
element.props.children = h(
|
101
|
+
'div',
|
102
|
+
{},
|
103
|
+
element.props.children,
|
104
|
+
h( 'button', { onClick: updateAttribute }, 'Update attribute' ),
|
105
|
+
h( 'button', { onClick: updateText }, 'Update text' )
|
106
|
+
);
|
107
|
+
},
|
108
|
+
{ priority: 14 }
|
109
|
+
);
|
110
|
+
|
111
|
+
store( {
|
112
|
+
actions: {
|
113
|
+
updateText( { context } ) {
|
114
|
+
context.text = 'updated';
|
115
|
+
},
|
116
|
+
updateAttribute( { context } ) {
|
117
|
+
context.attribute = 'updated';
|
118
|
+
},
|
119
|
+
},
|
120
|
+
} );
|
121
|
+
} )( window );
|
@@ -0,0 +1,14 @@
|
|
1
|
+
{
|
2
|
+
"apiVersion": 2,
|
3
|
+
"name": "test/directive-show",
|
4
|
+
"title": "E2E Interactivity tests - directive show",
|
5
|
+
"category": "text",
|
6
|
+
"icon": "heart",
|
7
|
+
"description": "",
|
8
|
+
"supports": {
|
9
|
+
"interactivity": true
|
10
|
+
},
|
11
|
+
"textdomain": "e2e-interactivity",
|
12
|
+
"viewScript": "directive-show-view",
|
13
|
+
"render": "file:./render.php"
|
14
|
+
}
|
@@ -0,0 +1,53 @@
|
|
1
|
+
<?php
|
2
|
+
/**
|
3
|
+
* HTML for testing the directive `data-wp-show`.
|
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
|
+
data-wp-show="state.trueValue"
|
26
|
+
id="truthy-div"
|
27
|
+
data-testid="show if callback returns truthy value"
|
28
|
+
>
|
29
|
+
<p>trueValue children</p>
|
30
|
+
</div>
|
31
|
+
|
32
|
+
<div
|
33
|
+
data-wp-show="state.falseValue"
|
34
|
+
data-testid="do not show if callback returns false value"
|
35
|
+
>
|
36
|
+
<p>falseValue children</p>
|
37
|
+
</div>
|
38
|
+
|
39
|
+
<div data-wp-context='{ "falseValue": false }'>
|
40
|
+
<div
|
41
|
+
data-wp-show="context.falseValue"
|
42
|
+
data-testid="can use context values"
|
43
|
+
>
|
44
|
+
falseValue
|
45
|
+
</div>
|
46
|
+
<button
|
47
|
+
data-wp-on--click="actions.toggleContextFalseValue"
|
48
|
+
data-testid="toggle context false value"
|
49
|
+
>
|
50
|
+
Toggle context falseValue
|
51
|
+
</button>
|
52
|
+
</div>
|
53
|
+
</div>
|
@@ -0,0 +1,24 @@
|
|
1
|
+
( ( { wp } ) => {
|
2
|
+
/**
|
3
|
+
* WordPress dependencies
|
4
|
+
*/
|
5
|
+
const { store } = wp.interactivity;
|
6
|
+
|
7
|
+
store( {
|
8
|
+
state: {
|
9
|
+
trueValue: true,
|
10
|
+
falseValue: false,
|
11
|
+
},
|
12
|
+
actions: {
|
13
|
+
toggleTrueValue: ( { state } ) => {
|
14
|
+
state.trueValue = ! state.trueValue;
|
15
|
+
},
|
16
|
+
toggleFalseValue: ( { state } ) => {
|
17
|
+
state.falseValue = ! state.falseValue;
|
18
|
+
},
|
19
|
+
toggleContextFalseValue: ( { context } ) => {
|
20
|
+
context.falseValue = ! context.falseValue;
|
21
|
+
},
|
22
|
+
},
|
23
|
+
} );
|
24
|
+
} )( window );
|
@@ -0,0 +1,14 @@
|
|
1
|
+
{
|
2
|
+
"apiVersion": 2,
|
3
|
+
"name": "test/directive-text",
|
4
|
+
"title": "E2E Interactivity tests - directive text",
|
5
|
+
"category": "text",
|
6
|
+
"icon": "heart",
|
7
|
+
"description": "",
|
8
|
+
"supports": {
|
9
|
+
"interactivity": true
|
10
|
+
},
|
11
|
+
"textdomain": "e2e-interactivity",
|
12
|
+
"viewScript": "directive-text-view",
|
13
|
+
"render": "file:./render.php"
|
14
|
+
}
|
@@ -0,0 +1,35 @@
|
|
1
|
+
<?php
|
2
|
+
/**
|
3
|
+
* HTML for testing the directive `data-wp-text`.
|
4
|
+
*
|
5
|
+
* @package gutenberg-test-interactive-blocks
|
6
|
+
*/
|
7
|
+
|
8
|
+
?>
|
9
|
+
<div data-wp-interactive>
|
10
|
+
<div>
|
11
|
+
<span
|
12
|
+
data-wp-text="state.text"
|
13
|
+
data-testid="show state text"
|
14
|
+
></span>
|
15
|
+
<button
|
16
|
+
data-wp-on--click="actions.toggleStateText"
|
17
|
+
data-testid="toggle state text"
|
18
|
+
>
|
19
|
+
Toggle State Text
|
20
|
+
</button>
|
21
|
+
</div>
|
22
|
+
|
23
|
+
<div data-wp-context='{ "text": "Text 1" }'>
|
24
|
+
<span
|
25
|
+
data-wp-text="context.text"
|
26
|
+
data-testid="show context text"
|
27
|
+
></span>
|
28
|
+
<button
|
29
|
+
data-wp-on--click="actions.toggleContextText"
|
30
|
+
data-testid="toggle context text"
|
31
|
+
>
|
32
|
+
Toggle Context Text
|
33
|
+
</button>
|
34
|
+
</div>
|
35
|
+
</div>
|
@@ -0,0 +1,17 @@
|
|
1
|
+
( ( { wp } ) => {
|
2
|
+
const { store } = wp.interactivity;
|
3
|
+
|
4
|
+
store( {
|
5
|
+
state: {
|
6
|
+
text: 'Text 1',
|
7
|
+
},
|
8
|
+
actions: {
|
9
|
+
toggleStateText: ( { state } ) => {
|
10
|
+
state.text = state.text === 'Text 1' ? 'Text 2' : 'Text 1';
|
11
|
+
},
|
12
|
+
toggleContextText: ( { context } ) => {
|
13
|
+
context.text = context.text === 'Text 1' ? 'Text 2' : 'Text 1';
|
14
|
+
},
|
15
|
+
},
|
16
|
+
} );
|
17
|
+
} )( window );
|
@@ -0,0 +1,14 @@
|
|
1
|
+
{
|
2
|
+
"apiVersion": 2,
|
3
|
+
"name": "test/negation-operator",
|
4
|
+
"title": "E2E Interactivity tests - negation operator",
|
5
|
+
"category": "text",
|
6
|
+
"icon": "heart",
|
7
|
+
"description": "",
|
8
|
+
"supports": {
|
9
|
+
"interactivity": true
|
10
|
+
},
|
11
|
+
"textdomain": "e2e-interactivity",
|
12
|
+
"viewScript": "negation-operator-view",
|
13
|
+
"render": "file:./render.php"
|
14
|
+
}
|
@@ -0,0 +1,26 @@
|
|
1
|
+
<?php
|
2
|
+
/**
|
3
|
+
* HTML for testing the negation operator in directives.
|
4
|
+
*
|
5
|
+
* @package gutenberg-test-interactive-blocks
|
6
|
+
*/
|
7
|
+
|
8
|
+
?>
|
9
|
+
<div data-wp-interactive>
|
10
|
+
<button
|
11
|
+
data-wp-on--click="actions.toggle"
|
12
|
+
data-testid="toggle active value"
|
13
|
+
>
|
14
|
+
Toggle Active Value
|
15
|
+
</button>
|
16
|
+
|
17
|
+
<div
|
18
|
+
data-wp-bind--hidden="!state.active"
|
19
|
+
data-testid="add hidden attribute if state is not active"
|
20
|
+
></div>
|
21
|
+
|
22
|
+
<div
|
23
|
+
data-wp-bind--hidden="!selectors.active"
|
24
|
+
data-testid="add hidden attribute if selector is not active"
|
25
|
+
></div>
|
26
|
+
</div>
|
@@ -0,0 +1,22 @@
|
|
1
|
+
( ( { wp } ) => {
|
2
|
+
/**
|
3
|
+
* WordPress dependencies
|
4
|
+
*/
|
5
|
+
const { store } = wp.interactivity;
|
6
|
+
|
7
|
+
store( {
|
8
|
+
selectors: {
|
9
|
+
active: ( { state } ) => {
|
10
|
+
return state.active;
|
11
|
+
},
|
12
|
+
},
|
13
|
+
state: {
|
14
|
+
active: false,
|
15
|
+
},
|
16
|
+
actions: {
|
17
|
+
toggle: ( { state } ) => {
|
18
|
+
state.active = ! state.active;
|
19
|
+
},
|
20
|
+
},
|
21
|
+
} );
|
22
|
+
} )( window );
|
@@ -0,0 +1,14 @@
|
|
1
|
+
{
|
2
|
+
"apiVersion": 2,
|
3
|
+
"name": "test/store-tag",
|
4
|
+
"title": "E2E Interactivity tests - store tag",
|
5
|
+
"category": "text",
|
6
|
+
"icon": "heart",
|
7
|
+
"description": "",
|
8
|
+
"supports": {
|
9
|
+
"interactivity": true
|
10
|
+
},
|
11
|
+
"textdomain": "e2e-interactivity",
|
12
|
+
"viewScript": "store-tag-view",
|
13
|
+
"render": "file:./render.php"
|
14
|
+
}
|
@@ -0,0 +1,64 @@
|
|
1
|
+
<?php
|
2
|
+
/**
|
3
|
+
* HTML for testing the hydration of the serialized store.
|
4
|
+
*
|
5
|
+
* @package gutenberg-test-interactive-blocks
|
6
|
+
* @phpcs:disable VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable
|
7
|
+
*/
|
8
|
+
|
9
|
+
// These variables simulates SSR.
|
10
|
+
$test_store_tag_counter = 'ok' === $attributes['condition'] ? 3 : 0;
|
11
|
+
$test_store_tag_double = $test_store_tag_counter * 2;
|
12
|
+
?>
|
13
|
+
<div data-wp-interactive>
|
14
|
+
<div>
|
15
|
+
Counter:
|
16
|
+
<span
|
17
|
+
data-wp-bind--children="state.counter.value"
|
18
|
+
data-testid="counter value"
|
19
|
+
><?php echo $test_store_tag_counter; ?></span
|
20
|
+
>
|
21
|
+
<br />
|
22
|
+
Double:
|
23
|
+
<span
|
24
|
+
data-wp-bind--children="state.counter.double"
|
25
|
+
data-testid="counter double"
|
26
|
+
><?php echo $test_store_tag_double; ?></span
|
27
|
+
>
|
28
|
+
<br />
|
29
|
+
<button
|
30
|
+
data-wp-on--click="actions.counter.increment"
|
31
|
+
data-testid="counter button"
|
32
|
+
>
|
33
|
+
+1
|
34
|
+
</button>
|
35
|
+
<span
|
36
|
+
data-wp-bind--children="state.counter.clicks"
|
37
|
+
data-testid="counter clicks"
|
38
|
+
>0</span
|
39
|
+
>
|
40
|
+
clicks
|
41
|
+
</div>
|
42
|
+
</div>
|
43
|
+
<?php
|
44
|
+
|
45
|
+
if ( 'missing' !== $attributes['condition'] ) {
|
46
|
+
|
47
|
+
if ( 'ok' === $attributes['condition'] ) {
|
48
|
+
$test_store_tag_json = '{ "state": { "counter": { "value": 3 } } }';
|
49
|
+
}
|
50
|
+
|
51
|
+
if ( 'corrupted-json' === $attributes['condition'] ) {
|
52
|
+
$test_store_tag_json = 'this is not a JSON';
|
53
|
+
}
|
54
|
+
|
55
|
+
if ( 'invalid-state' === $attributes['condition'] ) {
|
56
|
+
$test_store_tag_json = '{ "state": null }';
|
57
|
+
}
|
58
|
+
|
59
|
+
echo <<<HTML
|
60
|
+
<script type="application/json" id="wp-interactivity-store-data">
|
61
|
+
$test_store_tag_json
|
62
|
+
</script>
|
63
|
+
HTML;
|
64
|
+
}
|
@@ -0,0 +1,24 @@
|
|
1
|
+
( ( { wp } ) => {
|
2
|
+
/**
|
3
|
+
* WordPress dependencies
|
4
|
+
*/
|
5
|
+
const { store } = wp.interactivity;
|
6
|
+
|
7
|
+
store( {
|
8
|
+
state: {
|
9
|
+
counter: {
|
10
|
+
// `value` is defined in the server.
|
11
|
+
double: ( { state } ) => state.counter.value * 2,
|
12
|
+
clicks: 0,
|
13
|
+
},
|
14
|
+
},
|
15
|
+
actions: {
|
16
|
+
counter: {
|
17
|
+
increment: ( { state } ) => {
|
18
|
+
state.counter.value += 1;
|
19
|
+
state.counter.clicks += 1;
|
20
|
+
},
|
21
|
+
},
|
22
|
+
},
|
23
|
+
} );
|
24
|
+
} )( window );
|
@@ -0,0 +1,14 @@
|
|
1
|
+
{
|
2
|
+
"apiVersion": 2,
|
3
|
+
"name": "test/tovdom",
|
4
|
+
"title": "E2E Interactivity tests - tovdom",
|
5
|
+
"category": "text",
|
6
|
+
"icon": "heart",
|
7
|
+
"description": "",
|
8
|
+
"supports": {
|
9
|
+
"interactivity": true
|
10
|
+
},
|
11
|
+
"textdomain": "e2e-interactivity",
|
12
|
+
"viewScript": "tovdom-view",
|
13
|
+
"render": "file:./render.php"
|
14
|
+
}
|
@@ -0,0 +1,15 @@
|
|
1
|
+
const cdata = `
|
2
|
+
<div>
|
3
|
+
<![CDATA[##1##]]>
|
4
|
+
<div data-testid="it should keep this node between CDATA">
|
5
|
+
<![CDATA[##2##]]>
|
6
|
+
</div>
|
7
|
+
</div>
|
8
|
+
`;
|
9
|
+
|
10
|
+
const cdataElement = new DOMParser()
|
11
|
+
.parseFromString( cdata, 'text/xml' )
|
12
|
+
.querySelector( 'div' );
|
13
|
+
document
|
14
|
+
.getElementById( 'replace-with-cdata' )
|
15
|
+
.replaceWith( cdataElement );
|
@@ -0,0 +1,16 @@
|
|
1
|
+
const processingInstructions = `
|
2
|
+
<div>
|
3
|
+
<?xpacket ##1## ?>
|
4
|
+
<div data-testid="it should keep this node between processing instructions">
|
5
|
+
Processing instructions inner node
|
6
|
+
<?xpacket ##2## ?>
|
7
|
+
</div>
|
8
|
+
</div>
|
9
|
+
`;
|
10
|
+
|
11
|
+
const processingInstructionsElement = new DOMParser()
|
12
|
+
.parseFromString( processingInstructions, 'text/xml' )
|
13
|
+
.querySelector( 'div' );
|
14
|
+
document
|
15
|
+
.getElementById( 'replace-with-processing-instructions' )
|
16
|
+
.replaceWith( processingInstructionsElement );
|