Skip to content

Commit

Permalink
E2E: Add test coverage for Navigation block fallback behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
himanshupathak95 committed Feb 11, 2025
1 parent 530c61a commit 74852b3
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions test/e2e/specs/editor/blocks/navigation.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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:
'<!-- wp:navigation-link {"label":"First Link","type":"custom","url":"http://wordpress.org","kind":"custom"} /-->',
} );

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,
Expand Down

0 comments on commit 74852b3

Please sign in to comment.