-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Add e2e tests for keyboard interactions in DataViews ListView #61648
Conversation
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Size Change: +255 B (+0.01%) Total Size: 1.75 MB
ℹ️ View Unchanged
|
test/e2e/specs/site-editor/dataviews-list-layout-keyboard.spec.js
Outdated
Show resolved
Hide resolved
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 appreciate the follow-up :)
Co-authored-by: Miguel Fonseca <150562+mcsf@users.noreply.github.com>
f767c81
to
21a87ee
Compare
).toBeFocused(); | ||
|
||
// Make sure the items have loaded before reaching for the 1st item in the list. | ||
await page.getByRole( 'grid' ).waitFor(); |
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.
The waitFor
is "anti-pattern" in PW tests, and we should try to avoid it when possible. Can we swap similar calls with toBeVisible()
assertions?
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.
Happy to learn more about this and update it. I followed what we're doing in multiple other places: block directory, autosave, block bindings, multi-entity saving, editing widgets, etc. Could you expand on why is it an anti-pattern and in which situations should we avoid it?
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 think those are all copy pasted from the other tests or util methods. I should probably better to update those before it spreads even further :D
The waitFor
isn't explicit, and it's unclear at a glance that the method also waits for the element to be visible. I think it's OK to use in test utils, where test flow or readability isn't essential.
The following examples do the same thing:
await page.getByRole( 'grid' ).waitFor()
// Explicit asertion. It's clear without a comment what the test is doing.
await expect( page.geByRole( 'grid' ) ).toBeVisible()
This is also highlighter in the e2e test best practices - https://github.com/WordPress/gutenberg/blob/trunk/docs/contributors/code/e2e/README.md#make-explicit-assertions.
cc @WunderBart, @kevin940726, in case I missed something :)
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 don't have an opinion on a way or the other, happy to change it if that's preferred f4b9d6d
It sounds like we should make a lint rule to prevent people from using what our existing tests 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.
Yeah, waitFor
should be really rare, mostly in test utils. In Playwright, if we want to explicitly test the element is visible we should just use toBeVisible()
. If we just want to wait for the element to load for whatever actions below, we shouldn't need to, Playwright auto-waits for us.
I don't think this is a major anti-pattern though, just a good-to-know tip and helps readability in the long term 😄. (Thank you @Mamaduka!)
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.
@WunderBart, thanks for sharing the case.
I personally like the idea. Should we continue discussions in an issue?
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.
What I don't like about the approach is that you no longer can easily run the e2e tests by just providing a URL, you need access to CI and that database which makes running the e2e tests against Core (with the plugin disabled) for instance harder or remote urls or things like that. Thought one solution could be to provide this "reset DB" step as a REST API or something.
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.
@Mamaduka, should I handle creating the issue? 😄
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.
If you don’t mind, @WunderBart 🙇
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.
Follow-up to #60805
What?
Adds a few e2e test for the keyboard interactions merged by #60805
Why?
We want to make sure these don't break.
How?
A few different tests that cover all scenarios targeted in the PR above:
How to test
Make sure tests pass in CI. They can be executed locally by
npm run test:e2e:playwright -- test/e2e/specs/site-editor/dataviews-list-layout-keyboard.spec.js
.