|
| 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