-
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: Add warning test #45207
Navigation: Add warning test #45207
Conversation
Size Change: 0 B Total Size: 1.33 MB ℹ️ View Unchanged
|
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.
LGTM 👍
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.
Thanks for starting on these e2e tests!
I have an older PR where I started working on this in the past - #42695. Some of the utils there may be useful, so feel free to use it as a reference.
*/ | ||
const { test, expect } = require( '@wordpress/e2e-test-utils-playwright' ); | ||
|
||
test.describe( |
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.
It'd be great to wrap all the tests in a top level test.describe( 'Navigation block', () => {} )
description, so that the console generates the right output.
await editor.page.locator( '[aria-label="List View"i]' ).click(); | ||
// Click the Navigation block expander, we need to use force because it has aria-hidden set to true. | ||
await editor.page | ||
.locator( | ||
`//a[.//span[text()='Navigation']]/span[contains(@class, 'block-editor-list-view__expander')]` | ||
) | ||
.click( { force: true } ); | ||
// Find the Page list selector inside the navigation block. | ||
const pageListSelector = await editor.page.locator( | ||
`//table[contains(@aria-label,'Block navigation structure')]//a[.//span[text()='Page List']]` | ||
); | ||
|
||
expect( pageListSelector ).toBeTruthy(); |
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 personally don't think there's any need to check List View here, checking the editor content is enough, and there could be (or are) separate tests for List View checking that its content matches the block editor content. It'll also help the tests be less flaky if there are fewer steps.
|
||
// Find the warning message | ||
const warningMessage = await editor.page.locator( | ||
'class=wp-navigation-block', |
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.
It's be great to use role selectors where possible over class names—it helps ensure the UI has accessible markup.
For the block it'd be role=document[name="Block: Navigation"i]
(the document role for blocks is a bit unusual, but that was apparently necessary). The easiest way to get the right values is to inspect the element in the browser and check the accessibility tab's computed properties.
There's also a shorter way of selecting text role=document[name="Block: Navigation"i] >> text="Navigation menu has been deleted or is unavailable."
. (there is a subtle difference, this will select the text node, and hasText
selects the navigation block, but I don't think the difference matters here).
I think you should be able to shorten the whole thing to this:
await expect( `role=document[name="Block: Navigation"i] >> text="Navigation menu has been deleted or is unavailable." ).toBeVisible();
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.
Everything @talldan said 😆, plus a couple of things:
- You can use
page
directly rather than referencingeditor.page
.editor.page
isn't supposed to be a public API and might be marked private in the future. - Locator doesn't return a promise, so no need to
await
it. - Playwright deletes the doc for role selectors 😞 , but thankfully the alternative
getByRole
is basically the same thing but more friendly if you're familiar with testing-library's API.
Hence, the whole thing could be:
const warningMessage = page.getByRole( 'document', { name: 'Block: Navigation' } )
.getByText( 'Navigation menu has been deleted or is unavailable.' );
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.
page
didn't work ( ReferenceError: page is not defined
) but editor.canvas
does, which is what we use in other other test.
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.
In order to use page
you'll have to specify it in the test callback parameter:
test( '...', async ( { page } ) => {
But yeah, since that now post editor is rendered inside an iframe we can just use editor.canvas
instead.
8d30d04
to
8916e2b
Compare
'Navigation menu has been deleted or is unavailable.', | ||
} | ||
); | ||
expect( warningMessage ).toBeTruthy(); |
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.
Also, locator is always truthy as it always returns a locator instance. Instead, we should do something like toBeVisible()
.
await expect( warningMessage ).toBeVisible();
It also follows more closely to how users interpret it too.
0c3af1c
to
79b0b5b
Compare
@@ -146,3 +146,39 @@ class NavigationBlockUtils { | |||
); | |||
} | |||
} | |||
|
|||
test.describe( 'Navigation block', () => { |
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.
We should wrap all tests in this, in another PR!
I think this is ready for another review. |
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.
LGTM 👍 , thanks!
Flaky tests detected in b198fc8261d5a58c6af90e121fa17a880e53bfa1. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/4143816138
|
b198fc8
to
5a01992
Compare
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.
LGTM 👍
This adds a test to ensure that the user gets a warning message when the ref of their block points to an unknown wp_navigation menu.
Fixes #45204
Testing instructions:
Run npm run test:e2e:playwright -- editor/blocks/navigation.spec.js