diff --git a/packages/e2e-tests/specs/editor/plugins/inner-blocks-prioritized-inserter-blocks.test.js b/packages/e2e-tests/specs/editor/plugins/inner-blocks-prioritized-inserter-blocks.test.js deleted file mode 100644 index 7621fbea12140a..00000000000000 --- a/packages/e2e-tests/specs/editor/plugins/inner-blocks-prioritized-inserter-blocks.test.js +++ /dev/null @@ -1,132 +0,0 @@ -/** - * WordPress dependencies - */ -import { - activatePlugin, - createNewPost, - deactivatePlugin, - getAllBlockInserterItemTitles, - insertBlock, - closeGlobalBlockInserter, - canvas, -} from '@wordpress/e2e-test-utils'; - -const QUICK_INSERTER_RESULTS_SELECTOR = - '.block-editor-inserter__quick-inserter-results'; - -describe( 'Prioritized Inserter Blocks Setting on InnerBlocks', () => { - beforeAll( async () => { - await activatePlugin( - 'gutenberg-test-innerblocks-prioritized-inserter-blocks' - ); - } ); - - beforeEach( async () => { - await createNewPost(); - } ); - - afterAll( async () => { - await deactivatePlugin( - 'gutenberg-test-innerblocks-prioritized-inserter-blocks' - ); - } ); - - describe( 'Quick inserter', () => { - it( 'uses defaulting ordering if prioritzed blocks setting was not set', async () => { - const parentBlockSelector = - '[data-type="test/prioritized-inserter-blocks-unset"]'; - await insertBlock( 'Prioritized Inserter Blocks Unset' ); - await closeGlobalBlockInserter(); - - await page.waitForSelector( parentBlockSelector ); - - await page.click( - `${ parentBlockSelector } .block-list-appender .block-editor-inserter__toggle` - ); - - await page.waitForSelector( QUICK_INSERTER_RESULTS_SELECTOR ); - - await expect( await getAllBlockInserterItemTitles() ).toHaveLength( - 6 - ); - } ); - - it( 'uses the priority ordering if prioritzed blocks setting is set', async () => { - const parentBlockSelector = - '[data-type="test/prioritized-inserter-blocks-set"]'; - await insertBlock( 'Prioritized Inserter Blocks Set' ); - await closeGlobalBlockInserter(); - - await page.waitForSelector( parentBlockSelector ); - - await page.click( - `${ parentBlockSelector } .block-list-appender .block-editor-inserter__toggle` - ); - - await page.waitForSelector( QUICK_INSERTER_RESULTS_SELECTOR ); - - // Should still be only 6 results regardless of the priority ordering. - const inserterItems = await getAllBlockInserterItemTitles(); - - // Should still be only 6 results regardless of the priority ordering. - expect( inserterItems ).toHaveLength( 6 ); - - expect( inserterItems.slice( 0, 3 ) ).toEqual( [ - 'Audio', - 'Spacer', - 'Code', - ] ); - } ); - - it( 'obeys allowed blocks over prioritzed blocks setting if conflicted', async () => { - const parentBlockSelector = - '[data-type="test/prioritized-inserter-blocks-set-with-conflicting-allowed-blocks"]'; - await insertBlock( - 'Prioritized Inserter Blocks Set With Conflicting Allowed Blocks' - ); - await closeGlobalBlockInserter(); - - await page.waitForSelector( parentBlockSelector ); - - await page.click( - `${ parentBlockSelector } .block-list-appender .block-editor-inserter__toggle` - ); - - await page.waitForSelector( QUICK_INSERTER_RESULTS_SELECTOR ); - - const inserterItems = await getAllBlockInserterItemTitles(); - - expect( inserterItems.slice( 0, 3 ) ).toEqual( [ - 'Spacer', - 'Code', - 'Paragraph', - ] ); - expect( inserterItems ).toEqual( - expect.not.arrayContaining( [ 'Audio' ] ) - ); - } ); - } ); - describe( 'Slash inserter', () => { - it( 'uses the priority ordering if prioritzed blocks setting is set', async () => { - await insertBlock( 'Prioritized Inserter Blocks Set' ); - await canvas().click( '[data-type="core/image"]' ); - await page.keyboard.press( 'Enter' ); - await page.keyboard.type( '/' ); - // Wait for the results to display. - await page.waitForSelector( '.components-autocomplete__result' ); - const inserterItemTitles = await page.evaluate( () => { - return Array.from( - document.querySelectorAll( - '.components-autocomplete__result' - ) - ).map( ( { innerText } ) => innerText ); - } ); - expect( inserterItemTitles ).toHaveLength( 9 ); // Default suggested blocks number. - expect( inserterItemTitles.slice( 0, 3 ) ).toEqual( [ - 'Audio', - 'Spacer', - 'Code', - ] ); - } ); - } ); -} ); diff --git a/test/e2e/specs/editor/plugins/inner-blocks-prioritized-inserter-blocks.spec.js b/test/e2e/specs/editor/plugins/inner-blocks-prioritized-inserter-blocks.spec.js new file mode 100644 index 00000000000000..746d27d992bbc7 --- /dev/null +++ b/test/e2e/specs/editor/plugins/inner-blocks-prioritized-inserter-blocks.spec.js @@ -0,0 +1,146 @@ +/** + * WordPress dependencies + */ +const { test, expect } = require( '@wordpress/e2e-test-utils-playwright' ); + +test.describe( 'Prioritized Inserter Blocks Setting on InnerBlocks', () => { + test.beforeAll( async ( { requestUtils } ) => { + await requestUtils.activatePlugin( + 'gutenberg-test-innerblocks-prioritized-inserter-blocks' + ); + } ); + + test.beforeEach( async ( { admin } ) => { + await admin.createNewPost(); + } ); + + test.afterAll( async ( { requestUtils } ) => { + await requestUtils.deactivatePlugin( + 'gutenberg-test-innerblocks-prioritized-inserter-blocks' + ); + } ); + + test.describe( 'Quick Inserter', () => { + test( 'uses defaulting ordering if prioritzed blocks setting was not set', async ( { + editor, + page, + } ) => { + await editor.insertBlock( { + name: 'test/prioritized-inserter-blocks-unset', + } ); + + const block = page.getByRole( 'document', { + name: 'Block: Prioritized Inserter Blocks Unset', + } ); + + await block + .getByRole( 'button', { + name: 'Add block', + } ) + .click(); + + const blockListBox = page.getByRole( 'listbox', { + name: 'Blocks', + } ); + await expect( blockListBox ).toBeVisible(); + await expect( blockListBox.getByRole( 'option' ) ).toHaveCount( 6 ); + } ); + + test( 'uses the priority ordering if prioritzed blocks setting is set', async ( { + editor, + page, + } ) => { + await editor.insertBlock( { + name: 'test/prioritized-inserter-blocks-set', + } ); + + const block = page.getByRole( 'document', { + name: 'Block: Prioritized Inserter Blocks Set', + } ); + + await block + .getByRole( 'button', { + name: 'Add block', + } ) + .click(); + + const blockListBox = page.getByRole( 'listbox', { + name: 'Blocks', + } ); + await expect( blockListBox ).toBeVisible(); + + // Should still be only 6 results regardless of the priority ordering. + await expect( blockListBox.getByRole( 'option' ) ).toHaveCount( 6 ); + await expect( blockListBox.getByRole( 'option' ) ).toContainText( [ + 'Audio', + 'Spacer', + 'Code', + ] ); + } ); + + test( 'obeys allowed blocks over prioritzed blocks setting if conflicted', async ( { + editor, + page, + } ) => { + await editor.insertBlock( { + name: 'test/prioritized-inserter-blocks-set-with-conflicting-allowed-blocks', + } ); + + const block = page.getByRole( 'document', { + name: 'Prioritized Inserter Blocks Set With Conflicting Allowed Blocks', + } ); + + await block + .getByRole( 'button', { + name: 'Add block', + } ) + .click(); + + const blockListBox = page.getByRole( 'listbox', { + name: 'Blocks', + } ); + await expect( blockListBox ).toBeVisible(); + + await expect( blockListBox.getByRole( 'option' ) ).toContainText( [ + 'Spacer', + 'Code', + 'Paragraph', + ] ); + await expect( + blockListBox.getByRole( 'option' ) + ).not.toContainText( [ 'Audio' ] ); + } ); + } ); + + test.describe( 'Slash inserter', () => { + test( 'uses the priority ordering if prioritzed blocks setting is set', async ( { + editor, + page, + } ) => { + await editor.insertBlock( { + name: 'test/prioritized-inserter-blocks-set', + } ); + + const imageBlock = page + .getByRole( 'document', { + name: 'Block: Prioritized Inserter Blocks Set', + } ) + .getByRole( 'document', { name: 'Block: Image' } ); + + await imageBlock.click(); + await page.keyboard.press( 'Enter' ); + await page.keyboard.type( '/' ); + + const blockAutocompleter = page.getByRole( 'listbox' ); + await expect( blockAutocompleter ).toBeVisible(); + + // Default suggested blocks number. + await expect( + blockAutocompleter.getByRole( 'option' ) + ).toHaveCount( 9 ); + await expect( + blockAutocompleter.getByRole( 'option' ) + ).toContainText( [ 'Audio', 'Spacer', 'Code' ] ); + } ); + } ); +} );