Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Prev Previous commit
Next Next commit
E2E Tests: Add Child Blocks tests and test plugin
  • Loading branch information
noisysocks committed Jun 18, 2020
commit 3bb29adfc4c32738f8a09f1f54c8c16edf650e62
28 changes: 28 additions & 0 deletions packages/e2e-tests/plugins/child-blocks.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php
/**
* Plugin Name: Gutenberg Test Child Blocks
* Plugin URI: https://github.com/WordPress/gutenberg
* Author: Gutenberg Team
*
* @package gutenberg-test-child-blocks
*/

/**
* Registers a custom script for the plugin.
*/
function enqueue_child_blocks_script() {
wp_enqueue_script(
'gutenberg-test-child-blocks',
plugins_url( 'child-blocks/index.js', __FILE__ ),
array(
'wp-blocks',
'wp-block-editor',
'wp-element',
'wp-i18n',
),
filemtime( plugin_dir_path( __FILE__ ) . 'child-blocks/index.js' ),
true
);
}

add_action( 'init', 'enqueue_child_blocks_script' );
79 changes: 79 additions & 0 deletions packages/e2e-tests/plugins/child-blocks/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
( function() {
const { InnerBlocks } = wp.blockEditor;
const { createElement: el } = wp.element;
const { registerBlockType } = wp.blocks;

registerBlockType( 'test/child-blocks-unrestricted-parent', {
title: 'Child Blocks Unrestricted Parent',
icon: 'carrot',
category: 'text',

edit() {
return el(
'div',
{},
el( InnerBlocks )
);
},

save() {
return el(
'div',
{},
el( InnerBlocks.Content )
);
},
} );

registerBlockType( 'test/child-blocks-restricted-parent', {
title: 'Child Blocks Restricted Parent',
icon: 'carrot',
category: 'text',

edit() {
return el(
'div',
{},
el(
InnerBlocks,
{ allowedBlocks: [ 'core/paragraph', 'core/image' ] }
)
);
},

save() {
return el(
'div',
{},
el( InnerBlocks.Content )
);
},
} );

registerBlockType( 'test/child-blocks-child', {
title: 'Child Blocks Child',
icon: 'carrot',
category: 'text',

parent: [
'test/child-blocks-unrestricted-parent',
'test/child-blocks-restricted-parent',
],

edit() {
return el(
'div',
{},
'Child'
);
},

save() {
return el(
'div',
{},
'Child'
);
},
} );
} )();
65 changes: 65 additions & 0 deletions packages/e2e-tests/specs/editor/plugins/child-blocks.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/**
* WordPress dependencies
*/
import {
activatePlugin,
closeGlobalBlockInserter,
createNewPost,
deactivatePlugin,
getAllBlockInserterItemTitles,
insertBlock,
openGlobalBlockInserter,
} from '@wordpress/e2e-test-utils';

describe( 'Child Blocks', () => {
beforeAll( async () => {
await activatePlugin( 'gutenberg-test-child-blocks' );
} );

beforeEach( async () => {
await createNewPost();
} );

afterAll( async () => {
await deactivatePlugin( 'gutenberg-test-child-blocks' );
} );

it( 'are hidden from the global block inserter', async () => {
await openGlobalBlockInserter();
await expect( await getAllBlockInserterItemTitles() ).not.toContain(
'Child Blocks Child'
);
} );

it( 'shows up in a parent block', async () => {
await insertBlock( 'Child Blocks Unrestricted Parent' );
await closeGlobalBlockInserter();
await page.waitForSelector(
'[data-type="test/child-blocks-unrestricted-parent"] .block-editor-default-block-appender'
);
await page.click(
'[data-type="test/child-blocks-unrestricted-parent"] .block-editor-default-block-appender'
);
await openGlobalBlockInserter();
const inserterItemTitles = await getAllBlockInserterItemTitles();
expect( inserterItemTitles ).toContain( 'Child Blocks Child' );
expect( inserterItemTitles.length ).toBeGreaterThan( 20 );
} );

it( 'display in a parent block with allowedItems', async () => {
await insertBlock( 'Child Blocks Restricted Parent' );
await closeGlobalBlockInserter();
await page.waitForSelector(
'[data-type="test/child-blocks-restricted-parent"] .block-editor-default-block-appender'
);
await page.click(
'[data-type="test/child-blocks-restricted-parent"] .block-editor-default-block-appender'
);
await openGlobalBlockInserter();
expect( await getAllBlockInserterItemTitles() ).toEqual( [
'Child Blocks Child',
'Image',
'Paragraph',
] );
} );
} );