-
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
Refactor Site Editor test utils to the e2e-test-utils
package
#38463
Refactor Site Editor test utils to the e2e-test-utils
package
#38463
Conversation
That didn't seem to be used anywhere. Perhaps a bit of a red flag. Also decided not to go with adding an optional parameter to the existing `getEditedPostContent` because the two functions differed significantly. Perhaps it is not very consistent, however.
Function renamed to `getEditedPageContent` to avoid conflicts with existing functions. Also found instances in which it was used and replaced them.
The function can now wait for opening or closing as required, making the clicking of menu items more stable.
👋 Thanks for your first Pull Request and for helping build the future of Gutenberg and WordPress, @sunyatasattva! In case you missed it, we'd love to have you join us in our Slack community, where we hold regularly weekly meetings open to anyone to coordinate with each other. If you want to learn more about WordPress development in general, check out the Core Handbook full of helpful information. |
packages/e2e-test-utils/README.md
Outdated
@@ -258,6 +271,10 @@ Disable auto-accepting any dialogs. | |||
|
|||
Disables Pre-publish checks. | |||
|
|||
### disableWelcomeGuide |
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.
For the post editor we have a welcome guide as well and instead of a separate function it's an option in createNewPost
. Might be good to do something similar or if we keep the separate function have it work in both contexts?
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 action isn't unique to the Site Editor, and complexity will grow as we introduce more editors.
Let's make it part of the goToSiteEditor
function and disable it by default.
packages/e2e-test-utils/README.md
Outdated
@@ -364,6 +381,14 @@ _Returns_ | |||
|
|||
- `Promise`: Promise resolving with current post content markup. | |||
|
|||
### getEditedPageContent |
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 the name of this function is a bit ambiguous, it's not clear that it's the content of the site editor, a page can also be shown in the post editor. Maybe getSiteEditorCurrentContent
or getSiteEditorContent
or something like that?
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 great to see, extracting these was long overdue. I'm pinging some folks that I know worked on these previously in case they have a say @Addison-Stavlo @andrewserong @Mamaduka
packages/e2e-test-utils/README.md
Outdated
|
||
- `Promise<?ElementHandle>`: The menu item handle or `null` | ||
|
||
### goToSiteEditor |
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.
suggestions (non-blocking): Maybe we follow the general visit*
pattern for similar actions.
/** | ||
* Skips the welcome guide popping up to first time users of the site editor | ||
*/ | ||
export async function disableWelcomeGuide() { |
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 probably don't want to export this function anymore and make it internal.
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.
Mm… do you think so? I thought perhaps it might still be useful for some people to have it separately. Maybe they need to disable the welcome guide after doing some other steps?
I'm actually not sure. I'm confident you know best all the possible workflows, so if you say it would be useless, I'll remove the export and the reference in the docs.
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 that case, let's add site
in the function name. Since it only disables Site Editor welcome guides.
P.S. I don't think failing tests is related to this PR. See #38486 for details.
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.
Good call! Done that.
P.S. I don't think failing tests is related to this PR. See #38486 for details.
Yea, they were passing alright before. Maybe after pushing the new commit they'll run again and work 🤞
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 this is in good shape to land. The feedback got addressed, and all tests are passing.
Great work, @sunyatasattva 🥇
Congratulations on your first merged pull request, @sunyatasattva! We'd like to credit you for your contribution in the post announcing the next WordPress release, but we can't find a WordPress.org profile associated with your GitHub account. When you have a moment, visit the following URL and click "link your GitHub account" under "GitHub Username" to link your accounts: https://profiles.wordpress.org/me/profile/edit/ And if you don't have a WordPress.org account, you can create one on this page: https://login.wordpress.org/register Kudos! |
Thanks for being super welcoming @Mamaduka! Have a great weekend! |
Thank you for making this! Skimming through the diff got me thinking of whether we should encourage doing this though. The original utils are written in a Page Object Model style, which in my opinion is more suitable in our case.
I'd even suggest inlining most utils directly in tests, I don't think it's an anti-pattern to repeat ourselves in tests, as long as the code is straightforward to read. We can make use of labeled block statement and comments to group and document pieces of code. I'm currently trying to migrate from puppeteer to playwright, and refactor some of the testing styles in the meantime. I'll share more insights into what I think could make our tests better to read and write. |
Hey @kevin940726 thanks for the comment. I am totally a fan of the Page Object Model, and do agree 100% that it is the most suitable model. I have even written a small library to work with POs in Puppeteer, which I will open source once I finish the test coverage. So, I'm totally on board with you there. For the scope of this PR, however, I had discussed with @youknowriad and also a few other people involved, and we decided to just follow the current pattern for the utils, and that probably doing a refactor was not worth the cost, and definitely beyond the scope of this PR. You can still see my inspiration to POs in things like grouping
Not that my opinion for this project counts much, but that's the only part where I disagree. I have worked with tests a lot in the past and creating sharable utilities was a huge boon to the entire team. As long as the utilities are readable, discoverable and well documented, I personally don't see a big reason to reinvent the wheel (and, in fact, I would abstract a lot of what I saw here). I'd be totally willing to help on that refactoring project, by the way! |
Yeah, I totally agree we should follow the current style until we finalize a new one. I was just taking the opportunity to share my thoughts here 😆 .
I agree, but it's often hard to make them readable and discoverable in my past experience. For simple things like "querying an element and click on it", I don't think we need utils for them. As long as we have an accessible and readable querying engine, which is what I'm working on right now 😉 . That's just my opinion though and I value yours equally as well!
Awesome! I'll be sharing more progress in the #core-test Slack channel. Join us if you're interested! ❤️ |
Description
Currently, the
e2e-tests
packaged includes some utility functions to test the Site Editor. This, as confirmed through a chat with @youknowriad, was due to the fact that the Site Editor had been in an experimental phase for a long time.Now that the Site Editor has shipped to Core, it is time to graduate those test utils to the appropriate
e2e-test-utils
package and document them, so that they can be shared also in other packages and repositories.This is what this PR does: it extracted most of the utility functions into the
e2e-test-utils
, documented them and added some extra checks.There might be some other functions which might be useful to refactor inside the test cases themselves, but I thought I'd first open a PR for the bulk of them.
More details on what has changed below.
Testing Instructions
This PR only refactors E2E tests. So to test it, just run:
npm run test-e2e
.Types of changes
Mostly refactor. Any change introduced is non breaking. In particular, the following changes have been introduced to the utils API:
toggleMoreMenu
function now accepts an optional parameter calledcontext
(which indicates whether the button is in the Site Editor or Post Editor context). The reason is that the selector is different depending on the context. Perhaps in the future it could be nice to either: (a) have the same aria label for both buttons (b) change the selectors so that they coincide. For now, however, I kept the selector as I didn't want to go over scope with this PR.waitFor
. If set, this allows to wait for the menu to be open or closed, making sure that the menu is in the state it is expected to be. The parameter is optional and if not provided won't wait for anything (previous behavior). I have, however, refactored all the instances of this function I found to make sure the tests were explicit on their expectations.clickOnMoreMenuItem
function also accepts acontext
parameter for the reasons described above in (1).Checklist:
*.native.js
files for terms that need renaming or removal).