Skip to content

Add/application password e2e tests#1746

Closed
JustinyAhin wants to merge 22 commits intoWordPress:masterfrom
JustinyAhin:add/application-password-e2e-tests
Closed

Add/application password e2e tests#1746
JustinyAhin wants to merge 22 commits intoWordPress:masterfrom
JustinyAhin:add/application-password-e2e-tests

Conversation

@JustinyAhin
Copy link
Copy Markdown
Member

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-passwords

Create 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-passwords

Bulk 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

Comment thread tests/e2e/specs/settings/applications-passwords.test.js Outdated
@hellofromtonya
Copy link
Copy Markdown
Contributor

@kevin940726 and @tellthemachines this PR is ready for your review. Once approved, I'll get it committed.

Comment thread tests/e2e/specs/settings/applications-passwords.test.js Outdated
Copy link
Copy Markdown
Member

@kevin940726 kevin940726 left a comment

Choose a reason for hiding this comment

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

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();
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.

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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.

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.

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.

Comment thread tests/e2e/specs/settings/applications-passwords.test.js Outdated
await page.type('#new_application_password_name', `${applicationName}`);
await page.click('#do_new_application_password');

await page.waitForSelector('.notice');
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.

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 😅.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yeah, this makes sense. I've now added a new selector to all the waiting for notice message like this #application-passwords-section .notice.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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?

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 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?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

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 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 👍 .

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@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.

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.

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.

Comment thread tests/e2e/specs/settings/applications-passwords.test.js Outdated
@kevin940726
Copy link
Copy Markdown
Member

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.

@JustinyAhin
Copy link
Copy Markdown
Member Author

Thanks for all the reviews @kevin940726. This is exactly the kind of feedback I was hoping :).

@kevin940726
Copy link
Copy Markdown
Member

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.

Comment thread tests/e2e/specs/settings/applications-passwords.test.js Outdated
Comment thread tests/e2e/specs/settings/applications-passwords.test.js Outdated
Comment thread tests/e2e/specs/settings/applications-passwords.test.js Outdated
Copy link
Copy Markdown
Contributor

@tellthemachines tellthemachines left a comment

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! I left a few comments below.

Comment thread tests/e2e/specs/settings/applications-passwords.test.js Outdated
Comment thread tests/e2e/specs/settings/applications-passwords.test.js Outdated
Comment thread tests/e2e/specs/profile/applications-passwords.test.js Outdated
Comment thread tests/e2e/specs/profile/applications-passwords.test.js Outdated
@JustinyAhin
Copy link
Copy Markdown
Member Author

JustinyAhin commented Oct 20, 2021

Just found out there's a console error warning in the test output:

@kevin940726 I haven't figured out yet where the console error came from. I remember though it started when making API calls.

Copy link
Copy Markdown
Member

@kevin940726 kevin940726 left a comment

Choose a reason for hiding this comment

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

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).

@JustinyAhin
Copy link
Copy Markdown
Member Author

JustinyAhin commented Oct 21, 2021

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?
I can have a look maybe

@hellofromtonya
Copy link
Copy Markdown
Contributor

Committed via changeset https://core.trac.wordpress.org/changeset/51966.

Thank you everyone for your contribution 🎉

@kevin940726
Copy link
Copy Markdown
Member

What is needed for the ESLint PR @kevin940726? I can have a look maybe

Oops, totally missed this. We should configure ESLint so that it'll correctly use the @wordpress/eslint-plugin rulesets and lint the test files. I'm not sure if it's been done before in core though, but it's standard in gutenberg.

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.

6 participants