Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interactivity API: Add missing directives and move e2e tests #51194

Merged
merged 42 commits into from
Jun 27, 2023
Merged
Show file tree
Hide file tree
Changes from 41 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
b62f532
Add show and text directives
DAreRodz May 30, 2023
599e907
Move directive bind tests
DAreRodz Jun 1, 2023
dc57fc0
Move the rest of e2e tests (except csn-related)
DAreRodz Jun 1, 2023
f9b9480
Merge branch 'interactivity' into interactivity-full-runtime
DAreRodz Jun 15, 2023
88c9738
Add interactive-blocks plugin for e2e tests
DAreRodz Jun 15, 2023
83da07a
Move test plugins one folder up
DAreRodz Jun 15, 2023
3b9aef0
Add plugin to .wp-env.json
DAreRodz Jun 15, 2023
f2a283c
Change directive-bind spec file to use new plugin
DAreRodz Jun 15, 2023
52430d7
Move plugin to e2e-tests package
DAreRodz Jun 15, 2023
4f56e74
Move HTML for directive-bind to plugin
DAreRodz Jun 15, 2023
e672b6f
Update exposed properties from preact
DAreRodz Jun 15, 2023
3af13c0
Refactor directive-bind spec file
DAreRodz Jun 15, 2023
a2898b4
Create directive-effect block for e2e testing
DAreRodz Jun 15, 2023
fd01e31
Update directive-effect spec file
DAreRodz Jun 15, 2023
29fe334
Remove unnecessary files
DAreRodz Jun 15, 2023
683a444
Fix e2e tests for bind and effect directives
DAreRodz Jun 15, 2023
3d9212f
Refactor fixtures and use them for bind and effect
DAreRodz Jun 15, 2023
a885754
Remove unnecessary editorScript
DAreRodz Jun 15, 2023
ee5ac6a
Fix e2e test for directive priorities
DAreRodz Jun 15, 2023
3b6e2dc
Remove unnecessary files
DAreRodz Jun 15, 2023
35fdc76
Fix negation operator
DAreRodz Jun 15, 2023
8375a69
Refactor store-tag e2e tests
DAreRodz Jun 15, 2023
33e8b60
Refactor directive-class e2e tests
DAreRodz Jun 15, 2023
ae56d32
Remove extra spaces
DAreRodz Jun 15, 2023
6e5b17e
Add util for removing all created posts
DAreRodz Jun 15, 2023
faa6387
Add block for context directive
DAreRodz Jun 15, 2023
3f6e3fe
Add block for directive show testing
DAreRodz Jun 15, 2023
5d5ff0d
Remove unintentionally added artifact
DAreRodz Jun 15, 2023
8fceb9b
Ignore artifacts generated inside /test/e2e
DAreRodz Jun 15, 2023
954c1dd
Remove unused html
DAreRodz Jun 15, 2023
bc22001
Add block for directive text testing
DAreRodz Jun 15, 2023
04bc4d1
Add blocks for tovdom testing
DAreRodz Jun 15, 2023
c1901c5
Update directives syntax in e2e tests
DAreRodz Jun 15, 2023
936e164
Add getLink to InteractivityUtils
DAreRodz Jun 15, 2023
3c36867
Fix php lint errors
DAreRodz Jun 15, 2023
93478d8
Merge branch 'interactivity' into interactivity-full-runtime
DAreRodz Jun 15, 2023
4a36007
Merge branch 'interactivity' into interactivity-full-runtime
DAreRodz Jun 15, 2023
ed57c3e
Add disable_directives_ssr param
DAreRodz Jun 15, 2023
728865f
Fix phpcs errors
DAreRodz Jun 15, 2023
3ca1eaf
Fix missing phpcs error and warnings
DAreRodz Jun 15, 2023
ff97eef
Merge branch 'interactivity' into interactivity-full-runtime
luisherranz Jun 23, 2023
fca9057
Remove `wp-interactivity` from `viewScript`
DAreRodz Jun 27, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ coverage
*.log
yarn.lock
/artifacts
/test/e2e/artifacts
/perf-envs
/composer.lock

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export interface Post {
id: number;
content: string;
status: 'publish' | 'future' | 'draft' | 'pending' | 'private';
link: string;
}

export interface CreatePostPayload {
Expand Down
48 changes: 48 additions & 0 deletions packages/e2e-tests/plugins/interactive-blocks.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php
/**
* Plugin Name: Gutenberg Test Interactive Blocks
* Plugin URI: https://github.com/WordPress/gutenberg
* Author: Gutenberg Team
*
* @package gutenberg-test-interactive-blocks
*/

add_action(
'init',
function() {
// Register all blocks found in the `interactive-blocks` folder.
if ( file_exists( __DIR__ . '/interactive-blocks/' ) ) {
$block_json_files = glob( __DIR__ . '/interactive-blocks/**/block.json' );

// Auto register all blocks that were found.
foreach ( $block_json_files as $filename ) {
$block_folder = dirname( $filename );
$name = basename( $block_folder );

$view_file = plugin_dir_url( $block_folder ) . $name . '/' . 'view.js';

wp_register_script(
$name . '-view',
$view_file,
array( 'wp-interactivity' ),
filemtime( $view_file ),
true
);

register_block_type_from_metadata( $block_folder );
};
};

// Temporary fix to disable SSR of directives during E2E testing. This
// is required at this moment, as SSR for directives is not stabilized
// yet and we need to ensure hydration works, even when the rendered
// HTML is not correct or malformed.
if ( 'true' === $_GET['disable_directives_ssr'] ) {
remove_filter(
'render_block',
'gutenberg_interactivity_process_directives_in_root_blocks'
);
}

}
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"apiVersion": 2,
"name": "test/directive-bind",
"title": "E2E Interactivity tests - directive bind",
"category": "text",
"icon": "heart",
"description": "",
"supports": {
"interactivity": true
},
"textdomain": "e2e-interactivity",
"viewScript": ["directive-bind-view", "wp-interactivity"],
luisherranz marked this conversation as resolved.
Show resolved Hide resolved
"render": "file:./render.php"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php
/**
* HTML for testing the directive `data-wp-bind`.
*
* @package gutenberg-test-interactive-blocks
*/

?>
<div data-wp-interactive>
<a
data-wp-bind--href="state.url"
data-testid="add missing href at hydration"
></a>

<a
href="/other-url"
data-wp-bind--href="state.url"
data-testid="change href at hydration"
></a>

<input
type="checkbox"
data-wp-bind--checked="state.checked"
data-testid="add missing checked at hydration"
/>

<input
type="checkbox"
checked
data-wp-bind--checked="!state.checked"
data-testid="remove existing checked at hydration"
/>

<a
href="/other-url"
data-wp-bind--href="state.url"
data-testid="nested binds - 1"
>
<img
width="1"
data-wp-bind--width="state.width"
data-testid="nested binds - 2"
/>
</a>

<button data-testid="toggle" data-wp-on--click="actions.toggle">
Update
</button>

<p
data-wp-bind--hidden="!state.show"
data-wp-bind--aria-hidden="!state.show"
data-wp-bind--aria-expanded="state.show"
data-wp-bind--data-some-value="state.show"
data-testid="check enumerated attributes with true/false exist and have a string value"
>
Some Text
</p>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
( ( { wp } ) => {
const { store } = wp.interactivity;

store( {
state: {
url: '/some-url',
checked: true,
show: false,
width: 1,
},
foo: {
bar: 1,
},
actions: {
toggle: ( { state, foo } ) => {
state.url = '/some-other-url';
state.checked = ! state.checked;
state.show = ! state.show;
state.width += foo.bar;
},
},
} );
} )( window );
luisherranz marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"apiVersion": 2,
"name": "test/directive-class",
"title": "E2E Interactivity tests - directive class",
"category": "text",
"icon": "heart",
"description": "",
"supports": {
"interactivity": true
},
"textdomain": "e2e-interactivity",
"viewScript": ["directive-class-view", "wp-interactivity"],
"render": "file:./render.php"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php
/**
* HTML for testing the directive `data-wp-class`.
*
* @package gutenberg-test-interactive-blocks
*/

?>
<div data-wp-interactive>
<button
data-wp-on--click="actions.toggleTrueValue"
data-testid="toggle trueValue"
>
Toggle trueValue
</button>

<button
data-wp-on--click="actions.toggleFalseValue"
data-testid="toggle falseValue"
>
Toggle falseValue
</button>

<div
class="foo bar"
data-wp-class--foo="state.falseValue"
data-testid="remove class if callback returns falsy value"
></div>

<div
class="foo"
data-wp-class--bar="state.trueValue"
data-testid="add class if callback returns truthy value"
></div>

<div
class="foo bar"
data-wp-class--foo="state.falseValue"
data-wp-class--bar="state.trueValue"
data-wp-class--baz="state.trueValue"
data-testid="handles multiple classes and callbacks"
></div>

<div
class="foo foo-bar"
data-wp-class--foo="state.falseValue"
data-wp-class--foo-bar="state.trueValue"
data-testid="handles class names that are contained inside other class names"
></div>

<div
class="foo bar baz"
data-wp-class--bar="state.trueValue"
data-testid="can toggle class in the middle"
></div>

<div
data-wp-class--foo="state.falseValue"
data-testid="can toggle class when class attribute is missing"
></div>

<div data-wp-context='{ "falseValue": false }'>
<div
class="foo"
data-wp-class--foo="context.falseValue"
data-testid="can use context values"
></div>
<button
data-wp-on--click="actions.toggleContextFalseValue"
data-testid="toggle context false value"
>
Toggle context falseValue
</button>
</div>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
( ( { wp } ) => {
const { store } = wp.interactivity;

store( {
state: {
trueValue: true,
falseValue: false,
},
actions: {
toggleTrueValue: ( { state } ) => {
state.trueValue = ! state.trueValue;
},
toggleFalseValue: ( { state } ) => {
state.falseValue = ! state.falseValue;
},
toggleContextFalseValue: ( { context } ) => {
context.falseValue = ! context.falseValue;
},
},
} );
} )( window );
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"apiVersion": 2,
"name": "test/directive-context",
"title": "E2E Interactivity tests - directive context",
"category": "text",
"icon": "heart",
"description": "",
"supports": {
"interactivity": true
},
"textdomain": "e2e-interactivity",
"viewScript": ["directive-context-view", "wp-interactivity"],
"render": "file:./render.php"
}
Loading