-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
605eeac
commit 414e15b
Showing
5 changed files
with
104 additions
and
0 deletions.
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
packages/e2e-tests/plugins/interactive-blocks/namespace/block.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"$schema": "https://schemas.wp.org/trunk/block.json", | ||
"apiVersion": 2, | ||
"name": "test-namespace/directive-bind", | ||
"title": "E2E Interactivity tests - directive bind", | ||
"category": "text", | ||
"icon": "heart", | ||
"description": "", | ||
"supports": { | ||
"interactivity": true | ||
}, | ||
"textdomain": "e2e-interactivity", | ||
"viewScriptModule": "file:./view.js", | ||
"render": "file:./render.php" | ||
} |
23 changes: 23 additions & 0 deletions
23
packages/e2e-tests/plugins/interactive-blocks/namespace/render.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?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="empty namespace"></a> | ||
</div> | ||
|
||
<div data-wp-interactive="namespace"> | ||
<a data-wp-bind--href="state.url" data-testid="correct namespace"></a> | ||
</div> | ||
|
||
<div data-wp-interactive="{}"> | ||
<a data-wp-bind--href="state.url" data-testid="object namespace"></a> | ||
</div> | ||
|
||
<div data-wp-interactive> | ||
<a data-wp-bind--href="other::state.url" data-testid="other namespace"></a> | ||
</div> |
1 change: 1 addition & 0 deletions
1
packages/e2e-tests/plugins/interactive-blocks/namespace/view.asset.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<?php return array( 'dependencies' => array( '@wordpress/interactivity' ) ); |
16 changes: 16 additions & 0 deletions
16
packages/e2e-tests/plugins/interactive-blocks/namespace/view.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { store } from '@wordpress/interactivity'; | ||
|
||
store( 'namespace', { | ||
state: { | ||
url: '/some-url', | ||
}, | ||
} ); | ||
|
||
store( 'other', { | ||
state: { | ||
url: '/other-store-url', | ||
}, | ||
} ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import { test, expect } from './fixtures'; | ||
|
||
test.describe( 'Namespaces', () => { | ||
test.beforeAll( async ( { interactivityUtils: utils } ) => { | ||
await utils.activatePlugins(); | ||
await utils.addPostWithBlock( 'test-namespace/directive-bind' ); | ||
} ); | ||
|
||
test.beforeEach( async ( { interactivityUtils: utils, page } ) => { | ||
await page.goto( utils.getLink( 'test-namespace/directive-bind' ) ); | ||
} ); | ||
|
||
test.afterAll( async ( { interactivityUtils: utils } ) => { | ||
await utils.deactivatePlugins(); | ||
await utils.deleteAllPosts(); | ||
} ); | ||
|
||
test( 'Empty string as namespace should not work', async ( { page } ) => { | ||
const el = page.getByTestId( 'empty namespace' ); | ||
await expect( el ).not.toHaveAttribute( 'href', '/some-url' ); | ||
} ); | ||
|
||
test( 'A string as namespace should work', async ( { page } ) => { | ||
const el = page.getByTestId( 'correct namespace' ); | ||
await expect( el ).toHaveAttribute( 'href', '/some-url' ); | ||
} ); | ||
|
||
test( 'An empty object as namespace should work', async ( { page } ) => { | ||
const el = page.getByTestId( 'object namespace' ); | ||
await expect( el ).not.toHaveAttribute( 'href', '/some-url' ); | ||
} ); | ||
|
||
test( 'A wrong namespace should not break the runtime', async ( { | ||
page, | ||
} ) => { | ||
const el = page.getByTestId( 'object namespace' ); | ||
await expect( el ).not.toHaveAttribute( 'href', '/some-url' ); | ||
const correct = page.getByTestId( 'correct namespace' ); | ||
await expect( correct ).toHaveAttribute( 'href', '/some-url' ); | ||
} ); | ||
|
||
test( 'A different store namespace should work', async ( { page } ) => { | ||
const el = page.getByTestId( 'other namespace' ); | ||
await expect( el ).toHaveAttribute( 'href', '/other-store-url' ); | ||
} ); | ||
} ); |