Skip to content

Commit 38726ab

Browse files
Migrate Child Block Test to Playwright (#55199)
* Migrate Child Block Test to Playwright * Fix Stylelint failing and modified the test case * Fix failed CI * Update locators * Address Feedback * Address feedbacks * Address feedbacks * Update test case * Update test case
1 parent 3e4c053 commit 38726ab

File tree

2 files changed

+97
-66
lines changed

2 files changed

+97
-66
lines changed

packages/e2e-tests/specs/editor/plugins/child-blocks.test.js

Lines changed: 0 additions & 66 deletions
This file was deleted.
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
/**
2+
* WordPress dependencies
3+
*/
4+
const { test, expect } = require( '@wordpress/e2e-test-utils-playwright' );
5+
6+
test.describe( 'Child Blocks', () => {
7+
test.beforeAll( async ( { requestUtils } ) => {
8+
await requestUtils.activatePlugin( 'gutenberg-test-child-blocks' );
9+
} );
10+
11+
test.beforeEach( async ( { admin } ) => {
12+
await admin.createNewPost();
13+
} );
14+
15+
test.afterAll( async ( { requestUtils } ) => {
16+
await requestUtils.deactivatePlugin( 'gutenberg-test-child-blocks' );
17+
} );
18+
19+
test( 'are hidden from the global block inserter', async ( { page } ) => {
20+
const blockInserter = page
21+
.getByRole( 'toolbar', { name: 'Document tools' } )
22+
.getByRole( 'button', { name: 'Toggle block inserter' } );
23+
const blockLibrary = page.getByRole( 'region', {
24+
name: 'Block Library',
25+
} );
26+
27+
await blockInserter.click();
28+
await expect( blockLibrary ).toBeVisible();
29+
expect( blockLibrary.getByRole( 'option' ) ).not.toContain( [
30+
'Child Blocks Child',
31+
] );
32+
} );
33+
34+
test( 'shows up in a parent block', async ( { page, editor } ) => {
35+
await editor.insertBlock( {
36+
name: 'test/child-blocks-unrestricted-parent',
37+
} );
38+
39+
await page
40+
.getByRole( 'document', {
41+
name: 'Block: Child Blocks Unrestricted Parent',
42+
} )
43+
.getByRole( 'button', {
44+
name: 'Add default block',
45+
} )
46+
.click();
47+
48+
const blockInserter = page
49+
.getByRole( 'toolbar', { name: 'Document tools' } )
50+
.getByRole( 'button', { name: 'Toggle block inserter' } );
51+
const blockLibrary = page.getByRole( 'region', {
52+
name: 'Block Library',
53+
} );
54+
55+
await blockInserter.click();
56+
await expect( blockLibrary ).toBeVisible();
57+
await expect( blockLibrary.getByRole( 'option' ) ).toContainText( [
58+
'Child Blocks Child',
59+
] );
60+
expect(
61+
await blockLibrary.getByRole( 'option' ).count()
62+
).toBeGreaterThan( 10 );
63+
} );
64+
65+
test( 'display in a parent block with allowedItems', async ( {
66+
page,
67+
editor,
68+
} ) => {
69+
await editor.insertBlock( {
70+
name: 'test/child-blocks-restricted-parent',
71+
} );
72+
73+
await page
74+
.getByRole( 'document', {
75+
name: 'Block: Child Blocks Restricted Parent',
76+
} )
77+
.getByRole( 'button', {
78+
name: 'Add default block',
79+
} )
80+
.click();
81+
82+
const blockInserter = page
83+
.getByRole( 'toolbar', { name: 'Document tools' } )
84+
.getByRole( 'button', { name: 'Toggle block inserter' } );
85+
const blockLibrary = page.getByRole( 'region', {
86+
name: 'Block Library',
87+
} );
88+
89+
await blockInserter.click();
90+
await expect( blockLibrary ).toBeVisible();
91+
await expect( blockLibrary.getByRole( 'option' ) ).toHaveText( [
92+
'Paragraph',
93+
'Child Blocks Child',
94+
'Image',
95+
] );
96+
} );
97+
} );

0 commit comments

Comments
 (0)