-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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: e2e tests: default to classic menu #47867
Conversation
Size Change: +11.9 kB (+1%) Total Size: 1.33 MB
ℹ️ View Unchanged
|
Flaky tests detected in 4d4d736. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/4162741815
|
c39ac92
to
6e73320
Compare
Co-authored-by: Kai Hao <kevin830726@gmail.com>
9599509
to
6f78851
Compare
title: string; | ||
content: string; | ||
} | ||
export interface Menu { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we use the name Navigation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
navigationMenus
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I chose menu because it is used both for classic and navigation menus, but I think we can go with NavigationMenu too.
export async function createClassicMenu( this: RequestUtils, name: string ) { | ||
const menuItems = [ | ||
{ | ||
title: 'Home', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is quite a generic name. Is it possible that the test could pass but because it found a different navigation with a "Home" option? Maybe its safer to use a less generic name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense. This function was way more complicated on the puppeteer tests, so I made it much simpler for this test, and maybe we can refactor it later if it's useful for other tests too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI I've found this to be a problem in the past. I agree with Ben it should use a page name that is unusual and quite long.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed it to "Custom link", shall I make it longer?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That should be good enough 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This works well and looks good to me. It would be good to get a review from someone like @kevin940726 who knows a bit more than I do...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the late review! I noticed some minor errors (especially the page.pause(), we should add a lint rule for that 😅 ). I'd be nice to create a follow-up on this. Thanks!
}, | ||
} ); | ||
|
||
if ( menuItems?.length ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure why this is needed? Isn't menuItems
statically defined above?
/** | ||
* Create a navigation menu | ||
* | ||
* @param {Object} menuData navigation menu post data. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Prefer TS types than JSDoc types. I think we can just omit the type here.
* @param menuData navigation menu post data.
path: `/wp/v2/navigation/`, | ||
} ); | ||
|
||
if ( navMenus?.length ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: It's always going to return an array so let's remove the optional chaining here :)
path: `/wp/v2/menus/`, | ||
} ); | ||
|
||
if ( classicMenus?.length ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here.
] ); | ||
|
||
// Check the block in the canvas. | ||
await editor.page.pause(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Forgot to delete?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ugh, again!
|
||
// Check the block in the frontend. | ||
await navBlockUtils.selectNavigationItemOnFrontend( 'Custom link' ); | ||
await editor.page.pause(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto.
); | ||
async selectNavigationItemOnFrontend( name ) { | ||
await this.page.goto( '/' ); | ||
await this.editor.page.pause(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto.
...menuData, | ||
}, | ||
} ); | ||
async selectNavigationItemOnCanvas( name ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prefer inlining one-liner assertions like this, makes the test a bit easier to read. selectNavigationItemOnCanvas
doesn't really select anything here anyway 😆 .
path: `/wp/v2/navigation/${ menu.id }?force=true`, | ||
} ) ) | ||
); | ||
async selectNavigationItemOnFrontend( name ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto.
Hi, @MaggieCabrera The new test has been failing from time to time. See #48033. |
It's also mentioned in #48071 (comment). I'm sure it's already on @MaggieCabrera 's list. But we're also happy to help if needed! ❤️ |
Thanks for the reminder! do you have any ideas to make it more consistent? we could go without checking if the link is visible in the editor I suppose. I don't know how we could check it any other way, we are already looking at the selector in the canvas. |
It seems like it just takes a long time to finish. Could possibly be solved by just increasing the timeout for the assertion. The real question is why it is taking so long to load the navigation menu? |
What?
This is part of the effort to re work all the navigation block e2e tests and migration to playwright. This is one of the user stories described in #45199
This test checks that when only one classic menu exists, inserting a Navigation block will default correctly to using said menu.
Testing Instructions
Run
npm run test:e2e:playwright -- editor/blocks/navigation.spec.js