@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.
- package/CHANGELOG.md +4 -0
- package/package.json +7 -7
- package/plugins/block-api/index.js +5 -2
- package/plugins/block-api.php +2 -0
- package/plugins/block-context.php +9 -13
- package/plugins/deprecated-node-matcher/index.js +12 -16
- package/plugins/deprecated-node-matcher.php +0 -1
- package/plugins/iframed-enqueue-block-assets/script.js +3 -0
- package/plugins/iframed-enqueue-block-assets.php +13 -0
- 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-style/block.json +14 -0
- package/plugins/interactive-blocks/directive-style/render.php +93 -0
- package/plugins/interactive-blocks/directive-style/view.js +22 -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/__snapshots__/container-blocks.test.js.snap +5 -4
- package/specs/editor/plugins/container-blocks.test.js +2 -1
- package/specs/editor/plugins/iframed-equeue-block-assets.test.js +7 -0
- 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/publish-button.test.js +0 -15
- package/specs/editor/various/reusable-blocks.test.js +7 -13
- package/specs/experiments/blocks/post-comments-form.test.js +1 -1
- package/specs/site-editor/multi-entity-saving.test.js +0 -102
- package/specs/site-editor/settings-sidebar.test.js +1 -1
- package/specs/editor/various/adding-inline-tokens.test.js +0 -80
@@ -0,0 +1,121 @@
|
|
1
|
+
<?php
|
2
|
+
/**
|
3
|
+
* HTML for testing the directive `data-wp-context`.
|
4
|
+
*
|
5
|
+
* @package gutenberg-test-interactive-blocks
|
6
|
+
*/
|
7
|
+
|
8
|
+
?>
|
9
|
+
<div data-wp-interactive>
|
10
|
+
<div
|
11
|
+
data-wp-context='{ "prop1":"parent","prop2":"parent","obj":{"prop4":"parent","prop5":"parent"},"array":[1,2,3] }'
|
12
|
+
>
|
13
|
+
<pre
|
14
|
+
data-testid="parent context"
|
15
|
+
data-wp-bind--children="derived.renderContext"
|
16
|
+
>
|
17
|
+
<!-- rendered during hydration -->
|
18
|
+
</pre>
|
19
|
+
<button
|
20
|
+
data-testid="parent prop1"
|
21
|
+
name="prop1"
|
22
|
+
value="modifiedFromParent"
|
23
|
+
data-wp-on--click="actions.updateContext"
|
24
|
+
>
|
25
|
+
prop1
|
26
|
+
</button>
|
27
|
+
<button
|
28
|
+
data-testid="parent prop2"
|
29
|
+
name="prop2"
|
30
|
+
value="modifiedFromParent"
|
31
|
+
data-wp-on--click="actions.updateContext"
|
32
|
+
>
|
33
|
+
prop2
|
34
|
+
</button>
|
35
|
+
<button
|
36
|
+
data-testid="parent obj.prop4"
|
37
|
+
name="obj.prop4"
|
38
|
+
value="modifiedFromParent"
|
39
|
+
data-wp-on--click="actions.updateContext"
|
40
|
+
>
|
41
|
+
obj.prop4
|
42
|
+
</button>
|
43
|
+
<button
|
44
|
+
data-testid="parent obj.prop5"
|
45
|
+
name="obj.prop5"
|
46
|
+
value="modifiedFromParent"
|
47
|
+
data-wp-on--click="actions.updateContext"
|
48
|
+
>
|
49
|
+
obj.prop5
|
50
|
+
</button>
|
51
|
+
<div
|
52
|
+
data-wp-context='{ "prop2":"child","prop3":"child","obj":{"prop5":"child","prop6":"child"},"array":[4,5,6] }'
|
53
|
+
>
|
54
|
+
<pre
|
55
|
+
data-testid="child context"
|
56
|
+
data-wp-bind--children="derived.renderContext"
|
57
|
+
>
|
58
|
+
<!-- rendered during hydration -->
|
59
|
+
</pre>
|
60
|
+
<button
|
61
|
+
data-testid="child prop1"
|
62
|
+
name="prop1"
|
63
|
+
value="modifiedFromChild"
|
64
|
+
data-wp-on--click="actions.updateContext"
|
65
|
+
>
|
66
|
+
prop1
|
67
|
+
</button>
|
68
|
+
<button
|
69
|
+
data-testid="child prop2"
|
70
|
+
name="prop2"
|
71
|
+
value="modifiedFromChild"
|
72
|
+
data-wp-on--click="actions.updateContext"
|
73
|
+
>
|
74
|
+
prop2
|
75
|
+
</button>
|
76
|
+
<button
|
77
|
+
data-testid="child prop3"
|
78
|
+
name="prop3"
|
79
|
+
value="modifiedFromChild"
|
80
|
+
data-wp-on--click="actions.updateContext"
|
81
|
+
>
|
82
|
+
prop3
|
83
|
+
</button>
|
84
|
+
<button
|
85
|
+
data-testid="child obj.prop4"
|
86
|
+
name="obj.prop4"
|
87
|
+
value="modifiedFromChild"
|
88
|
+
data-wp-on--click="actions.updateContext"
|
89
|
+
>
|
90
|
+
obj.prop4
|
91
|
+
</button>
|
92
|
+
<button
|
93
|
+
data-testid="child obj.prop5"
|
94
|
+
name="obj.prop5"
|
95
|
+
value="modifiedFromChild"
|
96
|
+
data-wp-on--click="actions.updateContext"
|
97
|
+
>
|
98
|
+
obj.prop5
|
99
|
+
</button>
|
100
|
+
<button
|
101
|
+
data-testid="child obj.prop6"
|
102
|
+
name="obj.prop6"
|
103
|
+
value="modifiedFromChild"
|
104
|
+
data-wp-on--click="actions.updateContext"
|
105
|
+
>
|
106
|
+
obj.prop6
|
107
|
+
</button>
|
108
|
+
</div>
|
109
|
+
<br />
|
110
|
+
|
111
|
+
<button
|
112
|
+
data-testid="context & other directives"
|
113
|
+
data-wp-context='{ "text": "Text 1" }'
|
114
|
+
data-wp-text="context.text"
|
115
|
+
data-wp-on--click="actions.toggleContextText"
|
116
|
+
data-wp-bind--value="context.text"
|
117
|
+
>
|
118
|
+
Toggle Context Text
|
119
|
+
</button>
|
120
|
+
</div>
|
121
|
+
</div>
|
@@ -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-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 );
|
@@ -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>
|