Skip to content

e2e test cases for create and remove existing menu - #2338

Open
pavanpatil1 wants to merge 7 commits into
WordPress:trunkfrom
pavanpatil1:menu-e2e-test
Open

pavanpatil1 wants to merge 7 commits into
WordPress:trunkfrom
pavanpatil1:menu-e2e-test

Conversation

@pavanpatil1

Copy link
Copy Markdown

@JustinyAhin JustinyAhin left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this test @pavanpatil1. I've added a few comments to improve it.

@@ -0,0 +1,59 @@
import { loginUser, visitAdminPage,activateTheme } from '@wordpress/e2e-test-utils';

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might make sense to rename the test file to something like create-remove-menu.test.js or something similar. The idea is to keep consistency with existing tests files names.

Also, I'd move this test to a "Menu" folder as we might have others related tests in the future.

} );


it( 'Add a new menu', async () => {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This only adds a new menu, so it will make sense to add it as a helper function instead of a test.

await visitAdminPage("nav-menus.php");

//check if it's a first menu
await page.waitForSelector(".first-menu-message")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you clarify what this line does exactly? It looks like you are waiting for a selector that does not exist?


await visitAdminPage("nav-menus.php");

const createmenu = await page.$x("//a[normalize-space()='create a new menu']");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of using XPath here, maybe it will be easier to use a CSS selector? I'd do something like:
await page.click('.add-edit-menu-action a').

const createmenu = await page.$x("//a[normalize-space()='create a new menu']");
await createmenu[0].click();

await page.waitForSelector("#menu-name", {timeout: 60000})

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can simply wait for the selector without the timeout.

await page.click("#locations-primary");
await page.click("#save_menu_footer");

await page.waitForSelector("#nav-menu-footer", {timeout: 60000})

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same thing here, we can omit the timeout and just wait for the selector.


await page.waitForSelector(".delete-action",{timeout: 60000});
const deletemenu = await page.$x("//a[normalize-space()='Delete Menu']");
await deletemenu[0].click();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can also use more clear selectors here.

We could do instead: await page.click( 'a.menu-delete' )

await browser.close();
});

await page.waitForSelector(".add-edit-menu-action", {timeout: 60000});

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment for the timeout here.

@pavanpatil1

Copy link
Copy Markdown
Author

Hi @JustinyAhin, I hope you are doing well!.
Thank you so much for reviewing the PR. I have addressed all the shared feedbacks. Could you please take a look at it again?

@pavanpatil1

Copy link
Copy Markdown
Author

Hi @JustinyAhin @hellofromtonya,
I hope you are doing well! Wanted to know if there is any update on this? Do I need to make the changes or can we proceed further?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants