diff --git a/packages/e2e-tests/specs/editor/plugins/allowed-blocks.test.js b/packages/e2e-tests/specs/editor/plugins/allowed-blocks.test.js deleted file mode 100644 index 804e062fa725b..0000000000000 --- a/packages/e2e-tests/specs/editor/plugins/allowed-blocks.test.js +++ /dev/null @@ -1,59 +0,0 @@ -/** - * WordPress dependencies - */ -import { - activatePlugin, - clickOnMoreMenuItem, - createNewPost, - deactivatePlugin, - searchForBlock, -} from '@wordpress/e2e-test-utils'; - -describe( 'Allowed Blocks Filter', () => { - beforeAll( async () => { - await activatePlugin( 'gutenberg-test-allowed-blocks' ); - } ); - - beforeEach( async () => { - await createNewPost(); - } ); - - afterAll( async () => { - await deactivatePlugin( 'gutenberg-test-allowed-blocks' ); - } ); - - it( 'should restrict the allowed blocks in the inserter', async () => { - // The paragraph block is available. - await searchForBlock( 'Paragraph' ); - const paragraphBlockButton = ( - await page.$x( `//button//span[contains(text(), 'Paragraph')]` ) - )[ 0 ]; - expect( paragraphBlockButton ).not.toBeNull(); - - // The gallery block is not available. - await searchForBlock( 'Gallery' ); - - const galleryBlockButton = ( - await page.$x( `//button//span[contains(text(), 'Gallery')]` ) - )[ 0 ]; - expect( galleryBlockButton ).toBeUndefined(); - } ); - - it( 'should remove not allowed blocks from the block manager', async () => { - await clickOnMoreMenuItem( 'Preferences' ); - const [ blocksTab ] = await page.$x( - `//button[contains(text(), "Blocks")]` - ); - await blocksTab.click(); - - const BLOCK_LABEL_SELECTOR = - '.edit-post-block-manager__checklist-item .components-checkbox-control__label'; - await page.waitForSelector( BLOCK_LABEL_SELECTOR ); - const blocks = await page.evaluate( ( selector ) => { - return Array.from( document.querySelectorAll( selector ) ) - .map( ( element ) => ( element.innerText || '' ).trim() ) - .sort(); - }, BLOCK_LABEL_SELECTOR ); - expect( blocks ).toEqual( [ 'Image', 'Paragraph' ] ); - } ); -} ); diff --git a/test/e2e/specs/editor/plugins/allowed-blocks.spec.js b/test/e2e/specs/editor/plugins/allowed-blocks.spec.js new file mode 100644 index 0000000000000..4211e42823821 --- /dev/null +++ b/test/e2e/specs/editor/plugins/allowed-blocks.spec.js @@ -0,0 +1,70 @@ +/** + * WordPress dependencies + */ +const { test, expect } = require( '@wordpress/e2e-test-utils-playwright' ); + +test.describe( 'Allowed Blocks Filter', () => { + test.beforeAll( async ( { requestUtils } ) => { + await requestUtils.activatePlugin( 'gutenberg-test-allowed-blocks' ); + } ); + + test.beforeEach( async ( { admin } ) => { + await admin.createNewPost(); + } ); + + test.afterAll( async ( { requestUtils } ) => { + await requestUtils.deactivatePlugin( 'gutenberg-test-allowed-blocks' ); + } ); + + test( 'should restrict the allowed blocks in the inserter', async ( { + page, + } ) => { + // The paragraph block is available. + await page + .getByRole( 'button', { name: 'Toggle block inserter' } ) + .click(); + + const searchbox = page + .getByRole( 'region', { name: 'Block Library' } ) + .getByRole( 'searchbox', { + name: 'Search for blocks and patterns', + } ); + + await searchbox.fill( 'Paragraph' ); + + await expect( + page.getByRole( 'option', { name: 'Paragraph' } ) + ).toBeVisible(); + + // The gallery block is not available. + await searchbox.click( { + clickCount: 3, + } ); + await page.keyboard.press( 'Backspace' ); + + await searchbox.fill( 'Gallery' ); + + await expect( + page.getByRole( 'option', { name: 'Gallery' } ) + ).toBeHidden(); + } ); + + test( 'should remove not allowed blocks from the block manager', async ( { + page, + } ) => { + await page + .getByRole( 'region', { name: 'Editor top bar' } ) + .getByRole( 'button', { name: 'Options' } ) + .click(); + + await page.getByRole( 'menuitem', { name: 'Preferences' } ).click(); + + await page.getByRole( 'tab', { name: 'Blocks' } ).click(); + + await expect( + page + .getByRole( 'region', { name: 'Available block types' } ) + .getByRole( 'listitem' ) + ).toHaveText( [ 'Paragraph', 'Image' ] ); + } ); +} );