From 2fdf62538ded534dcea51b28c7e2b1a498d622da Mon Sep 17 00:00:00 2001 From: himanshupathak95 Date: Tue, 11 Feb 2025 14:11:26 +0530 Subject: [PATCH 1/9] 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 19da69cd27c4aa..c6675958d17dcb 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, From ff845088a7fa11f6e700237be7d890be50d78a4a Mon Sep 17 00:00:00 2001 From: himanshupathak95 Date: Fri, 23 May 2025 13:11:30 +0530 Subject: [PATCH 2/9] E2E: Update page list fallback behaviour for frontend --- .../specs/editor/blocks/navigation.spec.js | 28 ++++++++++++------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/test/e2e/specs/editor/blocks/navigation.spec.js b/test/e2e/specs/editor/blocks/navigation.spec.js index c6675958d17dcb..c4874e6d6234c4 100644 --- a/test/e2e/specs/editor/blocks/navigation.spec.js +++ b/test/e2e/specs/editor/blocks/navigation.spec.js @@ -200,24 +200,32 @@ test.describe( 'Navigation block', () => { } ); test.describe( 'Navigation block fallback behavior', () => { - test( 'falls back to Page List when no menus exist', async ( { + test( 'should fall back to Page List when no menus exist', async ( { admin, editor, + page, } ) => { await admin.createNewPost(); await editor.insertBlock( { name: 'core/navigation' } ); - const pageListBlock = editor.canvas.getByRole( 'document', { - name: 'Block: Page List', - } ); + await expect( + editor.canvas.getByRole( 'document', { + name: 'Block: Page List', + } ) + ).toBeVisible(); - await expect( pageListBlock ).toBeVisible(); + const postId = await editor.publishPost(); + await page.goto( `/?p=${ postId }` ); - await expect.poll( editor.getBlocks ).toMatchObject( [ - { - name: 'core/navigation', - }, - ] ); + 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( 'uses first non-empty menu as fallback', async ( { From ce026a0a609b58bcd40f690a8b434c81422a329f Mon Sep 17 00:00:00 2001 From: himanshupathak95 Date: Fri, 23 May 2025 13:32:45 +0530 Subject: [PATCH 3/9] E2E: Improve fallback behaviour for the first non-empty menu --- .../specs/editor/blocks/navigation.spec.js | 30 +++++++++++-------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/test/e2e/specs/editor/blocks/navigation.spec.js b/test/e2e/specs/editor/blocks/navigation.spec.js index c4874e6d6234c4..af5d6ad66871ef 100644 --- a/test/e2e/specs/editor/blocks/navigation.spec.js +++ b/test/e2e/specs/editor/blocks/navigation.spec.js @@ -199,7 +199,7 @@ test.describe( 'Navigation block', () => { } ); } ); - test.describe( 'Navigation block fallback behavior', () => { + test.describe( 'Navigation block fronted fallback behavior', () => { test( 'should fall back to Page List when no menus exist', async ( { admin, editor, @@ -228,33 +228,39 @@ test.describe( 'Navigation block', () => { ).toBeVisible(); } ); - test( 'uses first non-empty menu as fallback', async ( { + test( 'should use first non-empty menu as fallback', async ( { admin, editor, + page, requestUtils, } ) => { await admin.createNewPost(); - const menu = await requestUtils.createNavigationMenu( { - title: 'First Menu', + await requestUtils.createNavigationMenu( { + title: 'Empty Menu', + content: '', + } ); + const validMenu = await requestUtils.createNavigationMenu( { + title: 'Primary 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( editor.canvas.getByText( 'Home' ) ).toBeVisible(); await expect.poll( editor.getBlocks ).toMatchObject( [ { name: 'core/navigation', - attributes: { ref: menu.id }, + attributes: { ref: validMenu.id }, }, ] ); + + const postId = await editor.publishPost(); + await page.goto( `/?p=${ postId }` ); + await expect( + page.getByRole( 'link', { name: 'Home', exact: true } ) + ).toBeVisible(); } ); } ); From a8a593f12e80147b811e3e4a812937c4a3b8127e Mon Sep 17 00:00:00 2001 From: himanshupathak95 Date: Fri, 23 May 2025 14:02:28 +0530 Subject: [PATCH 4/9] E2E: Test fallback to page list when all menus are empty --- .../specs/editor/blocks/navigation.spec.js | 29 ++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/test/e2e/specs/editor/blocks/navigation.spec.js b/test/e2e/specs/editor/blocks/navigation.spec.js index af5d6ad66871ef..0a71f5c5d7e068 100644 --- a/test/e2e/specs/editor/blocks/navigation.spec.js +++ b/test/e2e/specs/editor/blocks/navigation.spec.js @@ -238,7 +238,7 @@ test.describe( 'Navigation block', () => { await requestUtils.createNavigationMenu( { title: 'Empty Menu', - content: '', + content: '', } ); const validMenu = await requestUtils.createNavigationMenu( { title: 'Primary Menu', @@ -262,6 +262,33 @@ test.describe( 'Navigation block', () => { page.getByRole( 'link', { name: 'Home', exact: true } ) ).toBeVisible(); } ); + + test( 'should fall back to Page List when all navigation posts are empty', async ( { + admin, + editor, + } ) => { + await admin.createNewPost(); + + await editor.insertBlock( { + name: 'core/navigation', + attributes: {}, + } ); + + await expect.poll( editor.getBlocks ).toMatchObject( [ + { + name: 'core/navigation', + attributes: expect.not.objectContaining( { + ref: expect.any( Number ), + } ), + }, + ] ); + + await expect( + editor.canvas.getByRole( 'document', { + name: 'Block: Page List', + } ) + ).toBeVisible(); + } ); } ); test.describe( 'As a user I want to create submenus using the navigation block', () => { From 9106f326c4f0577f79cfb52f15c14e2693eb213a Mon Sep 17 00:00:00 2001 From: himanshupathak95 Date: Fri, 23 May 2025 14:04:53 +0530 Subject: [PATCH 5/9] E2E: Improve test title --- test/e2e/specs/editor/blocks/navigation.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/e2e/specs/editor/blocks/navigation.spec.js b/test/e2e/specs/editor/blocks/navigation.spec.js index 0a71f5c5d7e068..cf86c86cab9c95 100644 --- a/test/e2e/specs/editor/blocks/navigation.spec.js +++ b/test/e2e/specs/editor/blocks/navigation.spec.js @@ -263,7 +263,7 @@ test.describe( 'Navigation block', () => { ).toBeVisible(); } ); - test( 'should fall back to Page List when all navigation posts are empty', async ( { + test( 'should fall back to Page List when all menus are empty', async ( { admin, editor, } ) => { From a05c084c52701d4da8f1cd5c03b679daaad982c1 Mon Sep 17 00:00:00 2001 From: himanshupathak95 Date: Fri, 30 May 2025 14:25:03 +0530 Subject: [PATCH 6/9] E2E: Improve test group name --- test/e2e/specs/editor/blocks/navigation.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/e2e/specs/editor/blocks/navigation.spec.js b/test/e2e/specs/editor/blocks/navigation.spec.js index cf86c86cab9c95..f66bea4eb11875 100644 --- a/test/e2e/specs/editor/blocks/navigation.spec.js +++ b/test/e2e/specs/editor/blocks/navigation.spec.js @@ -199,7 +199,7 @@ test.describe( 'Navigation block', () => { } ); } ); - test.describe( 'Navigation block fronted fallback behavior', () => { + test.describe( 'Fronted fallback behavior', () => { test( 'should fall back to Page List when no menus exist', async ( { admin, editor, From 3ac6ab47818050295354627422d344839ebdaaba Mon Sep 17 00:00:00 2001 From: himanshupathak95 Date: Fri, 20 Jun 2025 11:06:45 +0530 Subject: [PATCH 7/9] E2E: Test page list render on the frontend when no menus exist --- .../specs/editor/blocks/navigation.spec.js | 71 +------------------ 1 file changed, 2 insertions(+), 69 deletions(-) diff --git a/test/e2e/specs/editor/blocks/navigation.spec.js b/test/e2e/specs/editor/blocks/navigation.spec.js index f66bea4eb11875..cae43b743b94c1 100644 --- a/test/e2e/specs/editor/blocks/navigation.spec.js +++ b/test/e2e/specs/editor/blocks/navigation.spec.js @@ -200,7 +200,7 @@ test.describe( 'Navigation block', () => { } ); test.describe( 'Fronted fallback behavior', () => { - test( 'should fall back to Page List when no menus exist', async ( { + test( 'should render a Page List on the frontend when no menus exist', async ( { admin, editor, page, @@ -208,15 +208,10 @@ test.describe( 'Navigation block', () => { await admin.createNewPost(); await editor.insertBlock( { name: 'core/navigation' } ); - await expect( - editor.canvas.getByRole( 'document', { - name: 'Block: Page List', - } ) - ).toBeVisible(); - const postId = await editor.publishPost(); await page.goto( `/?p=${ postId }` ); + await expect( page.locator( '.wp-block-page-list' ) ).toBeVisible(); await expect( page.getByRole( 'link', { name: 'Cat', exact: true } ) ).toBeVisible(); @@ -227,68 +222,6 @@ test.describe( 'Navigation block', () => { page.getByRole( 'link', { name: 'Walrus', exact: true } ) ).toBeVisible(); } ); - - test( 'should use first non-empty menu as fallback', async ( { - admin, - editor, - page, - requestUtils, - } ) => { - await admin.createNewPost(); - - await requestUtils.createNavigationMenu( { - title: 'Empty Menu', - content: '', - } ); - const validMenu = await requestUtils.createNavigationMenu( { - title: 'Primary Menu', - content: - '', - } ); - - await editor.insertBlock( { name: 'core/navigation' } ); - - await expect( editor.canvas.getByText( 'Home' ) ).toBeVisible(); - await expect.poll( editor.getBlocks ).toMatchObject( [ - { - name: 'core/navigation', - attributes: { ref: validMenu.id }, - }, - ] ); - - const postId = await editor.publishPost(); - await page.goto( `/?p=${ postId }` ); - await expect( - page.getByRole( 'link', { name: 'Home', exact: true } ) - ).toBeVisible(); - } ); - - test( 'should fall back to Page List when all menus are empty', async ( { - admin, - editor, - } ) => { - await admin.createNewPost(); - - await editor.insertBlock( { - name: 'core/navigation', - attributes: {}, - } ); - - await expect.poll( editor.getBlocks ).toMatchObject( [ - { - name: 'core/navigation', - attributes: expect.not.objectContaining( { - ref: expect.any( Number ), - } ), - }, - ] ); - - await expect( - editor.canvas.getByRole( 'document', { - name: 'Block: Page List', - } ) - ).toBeVisible(); - } ); } ); test.describe( 'As a user I want to create submenus using the navigation block', () => { From 4821e5138b1e0b173f72583903b2b1039acd6766 Mon Sep 17 00:00:00 2001 From: himanshupathak95 Date: Fri, 20 Jun 2025 11:53:40 +0530 Subject: [PATCH 8/9] E2E: Test rendering first non-empty menu on the frontend --- .../specs/editor/blocks/navigation.spec.js | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/test/e2e/specs/editor/blocks/navigation.spec.js b/test/e2e/specs/editor/blocks/navigation.spec.js index cae43b743b94c1..b33217507279b8 100644 --- a/test/e2e/specs/editor/blocks/navigation.spec.js +++ b/test/e2e/specs/editor/blocks/navigation.spec.js @@ -222,6 +222,44 @@ test.describe( 'Navigation block', () => { 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: + '', + } ); + await requestUtils.createNavigationMenu( { + title: 'Menu A', + content: + '', + } ); + + 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.describe( 'As a user I want to create submenus using the navigation block', () => { From 1e79f92888c2e4b6a42ad5eb750a3fd0d06122de Mon Sep 17 00:00:00 2001 From: himanshupathak95 Date: Fri, 20 Jun 2025 11:58:23 +0530 Subject: [PATCH 9/9] E2E: Test skipping empty menus and rendering the next available menu --- .../specs/editor/blocks/navigation.spec.js | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/test/e2e/specs/editor/blocks/navigation.spec.js b/test/e2e/specs/editor/blocks/navigation.spec.js index b33217507279b8..043997d0f0a155 100644 --- a/test/e2e/specs/editor/blocks/navigation.spec.js +++ b/test/e2e/specs/editor/blocks/navigation.spec.js @@ -260,6 +260,37 @@ test.describe( 'Navigation block', () => { } ) ).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: + '', + } ); + + 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', () => {