Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Navigation block e2e tests: default to my most recently created menu #48132

Merged
merged 5 commits into from
Mar 13, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -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:
'<!-- wp:navigation-link {"label":"Menu 1 Link","type":"custom","url":"http://localhost:8889/#menu-1-link","kind":"custom","isTopLevelLink":true} /-->',
} );

//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:
'<!-- wp:navigation-link {"label":"Menu 2 Link","type":"custom","url":"http://localhost:8889/#menu-2-link","kind":"custom","isTopLevelLink":true} /-->',
} );

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();
} );
}
);

Expand Down