Add/application password e2e tests#1746
Add/application password e2e tests#1746JustinyAhin wants to merge 22 commits intoWordPress:masterfrom
Conversation
|
@kevin940726 and @tellthemachines this PR is ready for your review. Once approved, I'll get it committed. |
kevin940726
left a comment
There was a problem hiding this comment.
Nice work! Mostly looks good to me. Just some nitpickings and some practices we can discuss for our first e2e test. :)
| const testApplicationName = 'Test Application'; | ||
|
|
||
| beforeEach(async() => { | ||
| await revokeAllApplicationPasswords(); |
There was a problem hiding this comment.
While we do need a test to manually revoke all passwords, I don't think we have to do it for every test just to clear the states. Is it possible to call APIs to clear the states here instead of repeating this for every test? It could potentially speed up our tests too.
There was a problem hiding this comment.
Yeah, interesting. It saves 1 to 1.5 seconds for the whole test.
How far we want to go with optimizations? I guess we could try the same thing with creating a password? As the creation feature is already tested.
There was a problem hiding this comment.
Yeah, I'd say the rule of thumb is to avoid testing the same thing manually repeatedly when there are alternatives. E2E tests are already super slow by its nature, don't waste time on making it unnecessarily slower.
| await page.type('#new_application_password_name', `${applicationName}`); | ||
| await page.click('#do_new_application_password'); | ||
|
|
||
| await page.waitForSelector('.notice'); |
There was a problem hiding this comment.
Nit: It isn't really clear what notice we're waiting for here. What if there're some other notices happening at the same time? I don't really have the knowledge for this feature so I'm not sure if this is a legitimate concern though 😅.
There was a problem hiding this comment.
Yeah, this makes sense. I've now added a new selector to all the waiting for notice message like this #application-passwords-section .notice.
There was a problem hiding this comment.
There's something weird, though. When creating a new app password, the notice message has these class names notice notice-success is-dismissible new-application-password-notice.
But when I do await page.waitForSelector('.new-application-password-notice');, it results in a timeout error and the selector is not found 🤔. Do you have any ideas of where this could come from?
There was a problem hiding this comment.
I haven't tested it myself, but you can debug it with the --puppeteer-interactive launch flag when running wp-scripts test-e2e. Not sure if it's implemented in core though?
There was a problem hiding this comment.
You're using createApplicationPassword twice in the 'should not allows to create two applications passwords with the same name' test, but the second time around you're passing the same name, so it'll error. The '.new-application-password-notice' class is only present on the success notice, not the error one, so I'm guessing that's where the timeout is happening.
There are at least two ways we can approach this:
If createApplicationPassword is meant to successfully complete the password creation flow, then checking for the presence of '.new-application-password-notice' is the only meaningful option, because '#application-passwords-section .notice' will display in case of error too. But if this is just a helper to fill in the password creation form, then we needn't do any check in the function itself - we can instead do the most relevant check (for success or error) in the test itself, after running the function.
If we go with the first, then in the 'should not allows to create two applications passwords with the same name' test we should just repeat the password creation steps manually for the second time, instead of calling the function.
In terms of test readability, I'm a little more inclined towards the second option, but fine with either.
There was a problem hiding this comment.
I just tested it and it works for successful creations of application passwords, but not for failures. That's because the failure notices don't have the new-application-password-notice class. #application-passwords-section .notice seems like a good enough solution for this 👍 .
There was a problem hiding this comment.
@kevin940726 did you see my comment above? I'm not sure we should just let createApplicationPassword fail silently when the password isn't created for some reason.
There was a problem hiding this comment.
Oops, nope! GitHub failed to update it when I was commenting 😅 .
Though I think it's not a problem, this function is just a utility helper used in this test, so I think it makes sense to customize it for the needs of the tests. This helper is just an intermediate step towards where the assertions happen, and the actual assertions are done in each test for both successful and failed results.
|
Just found out there's a console error warning in the test output: https://github.com/WordPress/wordpress-develop/pull/1746/checks?check_run_id=3902891514#step:13:17 I don't think it's a big deal, but would be great if we could get rid of it somehow. |
|
Thanks for all the reviews @kevin940726. This is exactly the kind of feedback I was hoping :). |
|
One more thing I noticed, I think we should follow the coding style guide in tests as well? Not sure why eslint isn't picking those up. Might worth to fix that too in another PR. |
tellthemachines
left a comment
There was a problem hiding this comment.
Thanks for working on this! I left a few comments below.
@kevin940726 I haven't figured out yet where the console error came from. I remember though it started when making API calls. |
kevin940726
left a comment
There was a problem hiding this comment.
I think this looks good! Great work!
Still some places not following the style guide though but we can tackle them in another PR (which should fix the eslint issue).
What is needed for the ESLint PR @kevin940726? |
|
Committed via changeset https://core.trac.wordpress.org/changeset/51966. Thank you everyone for your contribution 🎉 |
Oops, totally missed this. We should configure ESLint so that it'll correctly use the |
Related Trac ticket: https://core.trac.wordpress.org/ticket/54241.
Test scenarios
Create a new application password
Given that a test user exists
When I go to Users > Profile, and I create a new application password
I see the new application password success message
And the application name appears in the app password table
And the application password information are present in the response of
GET /wp/v2/users/<user_id>/application-passwordsCreate an application password with an existing name
Given that a test user exists
And has an existing application password
When I go to Users > Profile, and I create a new application password with the same name
I should receive an error message, and the new application password should not be created
Revoke a single application password
Given that a test user exists
And has an existing application password
When I go to Users > Profile
And I click on the Revoke button
The application password should be revoked with a displayed success message
And the application password information should not be present in the response of
GET /wp/v2/users/<user_id>/application-passwordsBulk revoke applications passwords
Given that a test user exists
And has two existing applications passwords
When I go to Users > Profile
And I click on the Revoke all application passwords button
Then all applications passwords should be removed with a displayed success message
And the applications passwords information should not be present in the response of
GET /wp/v2/users/<user_id>/application-passwords