diff --git a/test/e2e/specs/editor/blocks/navigation.spec.js b/test/e2e/specs/editor/blocks/navigation.spec.js new file mode 100644 index 0000000000000..3388a8f818012 --- /dev/null +++ b/test/e2e/specs/editor/blocks/navigation.spec.js @@ -0,0 +1,62 @@ +/** + * WordPress dependencies + */ +const { + test, + expect, + Editor, +} = require( '@wordpress/e2e-test-utils-playwright' ); + +test.use( { + editor: async ( { page }, use ) => { + await use( new Editor( { page, hasIframe: true } ) ); + }, +} ); + +test.describe( + 'As a user I want the navigation block to fallback to the best possible default', + () => { + test.beforeAll( async ( { requestUtils } ) => { + await requestUtils.activateTheme( 'emptytheme' ); + } ); + + test.beforeEach( async ( { admin } ) => { + await admin.createNewPost(); + } ); + + test.afterAll( async ( { requestUtils } ) => { + await requestUtils.activateTheme( 'twentytwentyone' ); + } ); + + test.afterEach( async ( { requestUtils } ) => { + await requestUtils.deleteAllPosts(); + } ); + + test( 'default to a list of pages if there are no menus', async ( { + editor, + } ) => { + await editor.insertBlock( { name: 'core/navigation' } ); + + const pageListBlock = editor.canvas.getByRole( 'document', { + name: 'Block: Page List', + } ); + + await expect( pageListBlock ).toBeVisible( { + // Wait for the Nav and Page List block API requests to resolve. + // Note: avoid waiting on network requests as these are not perceivable + // to the user. + // See: https://github.com/WordPress/gutenberg/pull/45070#issuecomment-1373712007. + timeout: 10000, + } ); + + // Check the markup of the block is correct. + await editor.publishPost(); + const content = await editor.getEditedPostContent(); + expect( content ).toBe( + ` + +` + ); + } ); + } +);