From 74852b35e8f3e62c095c6029072b88b3c3a55c93 Mon Sep 17 00:00:00 2001 From: himanshupathak95 Date: Tue, 11 Feb 2025 14:11:26 +0530 Subject: [PATCH] E2E: Add test coverage for Navigation block fallback behavior --- .../specs/editor/blocks/navigation.spec.js | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/test/e2e/specs/editor/blocks/navigation.spec.js b/test/e2e/specs/editor/blocks/navigation.spec.js index 769e30c99dab3..32ff2eac76d17 100644 --- a/test/e2e/specs/editor/blocks/navigation.spec.js +++ b/test/e2e/specs/editor/blocks/navigation.spec.js @@ -199,6 +199,57 @@ test.describe( 'Navigation block', () => { } ); } ); + test.describe( 'Navigation block fallback behavior', () => { + test( 'falls back to Page List when no menus exist', async ( { + admin, + editor, + } ) => { + await admin.createNewPost(); + await editor.insertBlock( { name: 'core/navigation' } ); + + const pageListBlock = editor.canvas.getByRole( 'document', { + name: 'Block: Page List', + } ); + + await expect( pageListBlock ).toBeVisible(); + + await expect.poll( editor.getBlocks ).toMatchObject( [ + { + name: 'core/navigation', + }, + ] ); + } ); + + test( 'uses first non-empty menu as fallback', async ( { + admin, + editor, + requestUtils, + } ) => { + await admin.createNewPost(); + + const menu = await requestUtils.createNavigationMenu( { + title: 'First Menu', + content: + '', + } ); + + await editor.insertBlock( { name: 'core/navigation' } ); + + await expect( + editor.canvas.locator( + `role=textbox[name="Navigation link text"i] >> text="First Link"` + ) + ).toBeVisible(); + + await expect.poll( editor.getBlocks ).toMatchObject( [ + { + name: 'core/navigation', + attributes: { ref: menu.id }, + }, + ] ); + } ); + } ); + test.describe( 'As a user I want to create submenus using the navigation block', () => { test( 'create a submenu', async ( { admin,