diff --git a/test/e2e/specs/editor/blocks/navigation.spec.js b/test/e2e/specs/editor/blocks/navigation.spec.js index b6e0b832eab5a4..db7cfa3082ed81 100644 --- a/test/e2e/specs/editor/blocks/navigation.spec.js +++ b/test/e2e/specs/editor/blocks/navigation.spec.js @@ -130,6 +130,57 @@ test.describe( ) ).toBeVisible(); } ); + + test( 'default to my most recently created menu', async ( { + admin, + page, + editor, + requestUtils, + } ) => { + await admin.createNewPost(); + await requestUtils.createNavigationMenu( { + title: 'Test Menu 1', + content: + '', + } ); + + //FIXME this is needed because if the two menus are created at the same time, the API will return them in the wrong order. + //https://core.trac.wordpress.org/ticket/57914 + await editor.page.waitForTimeout( 1000 ); + + const latestMenu = await requestUtils.createNavigationMenu( { + title: 'Test Menu 2', + content: + '', + } ); + + await editor.insertBlock( { name: 'core/navigation' } ); + + // Check the markup of the block is correct. + await editor.publishPost(); + await expect.poll( editor.getBlocks ).toMatchObject( [ + { + name: 'core/navigation', + attributes: { ref: latestMenu.id }, + }, + ] ); + await page.locator( 'role=button[name="Close panel"i]' ).click(); + + // Check the block in the canvas. + await expect( + editor.canvas.locator( + `role=textbox[name="Navigation link text"i] >> text="Menu 2 Link"` + ) + ).toBeVisible(); + + // Check the block in the frontend. + await page.goto( '/' ); + await expect( + page.locator( + `role=navigation >> role=link[name="Menu 2 Link"i]` + ) + ).toBeVisible(); + } ); } );