-
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.
Test: Add e2e test that ensures that filters can be added after block…
… registration
- Loading branch information
Showing
3 changed files
with
90 additions
and
0 deletions.
There are no files selected for viewing
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,26 @@ | ||
<?php | ||
/** | ||
* Plugin Name: Gutenberg Test Block API | ||
* Plugin URI: https://github.com/WordPress/gutenberg | ||
* Author: Gutenberg Team | ||
* | ||
* @package gutenberg-test-block-api | ||
*/ | ||
|
||
/** | ||
* Registers a custom script for the plugin. | ||
*/ | ||
function enqueue_block_api_plugin_script() { | ||
wp_enqueue_script( | ||
'gutenberg-test-block-api', | ||
plugins_url( 'block-api/index.js', __FILE__ ), | ||
array( | ||
'wp-blocks', | ||
'wp-hooks', | ||
), | ||
filemtime( plugin_dir_path( __FILE__ ) . 'block-api/index.js' ), | ||
true | ||
); | ||
} | ||
|
||
add_action( 'init', 'enqueue_block_api_plugin_script' ); |
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,31 @@ | ||
( function () { | ||
const { registerBlockType } = wp.blocks; | ||
const { addFilter } = wp.hooks; | ||
|
||
registerBlockType( 'e2e-tests/hello-world', { | ||
title: 'Hello World', | ||
description: 'Hello World test block.', | ||
category: 'widgets', | ||
edit() { | ||
return 'Hello Editor!'; | ||
}, | ||
save() { | ||
return 'Hello Frontend!'; | ||
}, | ||
} ); | ||
|
||
addFilter( | ||
'blocks.registerBlockType', | ||
'e2e-tests/hello-world/filter-added-after-registration', | ||
( blockType, name ) => { | ||
if ( name === 'e2e-tests/hello-world' ) { | ||
return { | ||
...blockType, | ||
title: 'Filtered Hello World', | ||
}; | ||
} | ||
|
||
return blockType; | ||
} | ||
); | ||
} )(); |
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,33 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { | ||
activatePlugin, | ||
createNewPost, | ||
deactivatePlugin, | ||
insertBlock, | ||
} from '@wordpress/e2e-test-utils'; | ||
|
||
describe( 'Using Block API', () => { | ||
beforeAll( async () => { | ||
await activatePlugin( 'gutenberg-test-block-api' ); | ||
} ); | ||
|
||
afterAll( async () => { | ||
await deactivatePlugin( 'gutenberg-test-block-api' ); | ||
} ); | ||
|
||
beforeEach( async () => { | ||
await createNewPost(); | ||
} ); | ||
|
||
test( 'Inserts the filtered hello world block even when filter added after block registration', async () => { | ||
await insertBlock( 'Filtered Hello World' ); | ||
|
||
const blockContent = await page.$eval( | ||
'div[data-type="e2e-tests/hello-world"]', | ||
( element ) => element.textContent | ||
); | ||
expect( blockContent ).toEqual( 'Hello Editor!' ); | ||
} ); | ||
} ); |