Skip to content
94 changes: 94 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,100 @@
} );
} );

test.describe( 'Fronted fallback behavior', () => {
test( 'should render a Page List on the frontend when no menus exist', async ( {
admin,
editor,
page,
} ) => {
await admin.createNewPost();
await editor.insertBlock( { name: 'core/navigation' } );

const postId = await editor.publishPost();
await page.goto( `/?p=${ postId }` );

await expect( page.locator( '.wp-block-page-list' ) ).toBeVisible();

Check failure on line 214 in test/e2e/specs/editor/blocks/navigation.spec.js

View workflow job for this annotation

GitHub Actions / Playwright - 2

[chromium] › test/e2e/specs/editor/blocks/navigation.spec.js:203:3 › Navigation block › Fronted fallback behavior › should render a Page List on the frontend when no menus exist

1) [chromium] › test/e2e/specs/editor/blocks/navigation.spec.js:203:3 › Navigation block › Fronted fallback behavior › should render a Page List on the frontend when no menus exist Error: Timed out 5000ms waiting for expect(locator).toBeVisible() Locator: locator('.wp-block-page-list') Expected: visible Received: <element(s) not found> Call log: - expect.toBeVisible with timeout 5000ms - waiting for locator('.wp-block-page-list') 212 | await page.goto( `/?p=${ postId }` ); 213 | > 214 | await expect( page.locator( '.wp-block-page-list' ) ).toBeVisible(); | ^ 215 | await expect( 216 | page.getByRole( 'link', { name: 'Cat', exact: true } ) 217 | ).toBeVisible(); at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/blocks/navigation.spec.js:214:58
await expect(
page.getByRole( 'link', { name: 'Cat', exact: true } )
).toBeVisible();
await expect(
page.getByRole( 'link', { name: 'Dog', exact: true } )
).toBeVisible();
await expect(
page.getByRole( 'link', { name: 'Walrus', exact: true } )
).toBeVisible();
} );

test( 'should render the first non-empty menu on the frontend', async ( {
admin,
editor,
page,
requestUtils,
} ) => {
// The fallback should pick "Menu A" because it comes first alphabetically.
await requestUtils.createNavigationMenu( {
title: 'Menu B',
content:
'<!-- wp:navigation-link {"label":"Dog","url":"#dog"} /-->',
} );
await requestUtils.createNavigationMenu( {
title: 'Menu A',
content:
'<!-- wp:navigation-link {"label":"Cat","url":"#cat"} /-->',
} );

await admin.createNewPost();
await editor.insertBlock( { name: 'core/navigation' } );

const postId = await editor.publishPost();
await page.goto( `/?p=${ postId }` );

await expect(
page.getByRole( 'link', {
name: 'Cat',
exact: true,
} )
).toBeVisible();
await expect(
page.getByRole( 'link', {
name: 'Dog',
exact: true,
} )
).toBeHidden();
} );

test( 'should skip empty menus and render the next available menu', async ( {
admin,
editor,
page,
requestUtils,
} ) => {
// The fallback should skip empty 'Menu A' and render non-empty 'Menu B'.
await requestUtils.createNavigationMenu( {
title: 'Menu A',
content: '',
} );
await requestUtils.createNavigationMenu( {
title: 'Menu B',
content:
'<!-- wp:navigation-link {"label":"Dog","url":"#dog"} /-->',
} );

await admin.createNewPost();
await editor.insertBlock( { name: 'core/navigation' } );

const postId = await editor.publishPost();
await page.goto( `/?p=${ postId }` );

await expect(
page.getByRole( 'link', {
name: 'Dog',
exact: true,
} )
).toBeVisible();
} );
} );

test.describe( 'As a user I want to create submenus using the navigation block', () => {
test( 'create a submenu', async ( {
admin,
Expand Down
Loading