From 9e22260397097414925428bfdf01f33b54a4c26e Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Tue, 22 Jun 2021 22:32:24 +0200 Subject: [PATCH 1/9] Typo --- packages/e2e-test-utils/src/create-user.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/e2e-test-utils/src/create-user.js b/packages/e2e-test-utils/src/create-user.js index 3d9935eb5467b..8c10e32f32b72 100644 --- a/packages/e2e-test-utils/src/create-user.js +++ b/packages/e2e-test-utils/src/create-user.js @@ -15,7 +15,7 @@ import { visitAdminPage } from './visit-admin-page'; * * @param {string} username User name. * @param {string?} firstName First name. - * @param {string?} lastName Larst name. + * @param {string?} lastName Last name. */ export async function createUser( username, firstName, lastName ) { await switchUserToAdmin(); From a66eb69d5838148481e7f668629b7b6e8c7e6753 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Tue, 22 Jun 2021 22:33:29 +0200 Subject: [PATCH 2/9] Allow setting user role --- packages/e2e-test-utils/src/create-user.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/packages/e2e-test-utils/src/create-user.js b/packages/e2e-test-utils/src/create-user.js index 8c10e32f32b72..e83be96f22e66 100644 --- a/packages/e2e-test-utils/src/create-user.js +++ b/packages/e2e-test-utils/src/create-user.js @@ -10,14 +10,21 @@ import { switchUserToAdmin } from './switch-user-to-admin'; import { switchUserToTest } from './switch-user-to-test'; import { visitAdminPage } from './visit-admin-page'; +/** + * @typedef {'Subscriber' | 'Contributor' | 'Author' | 'Editor' | 'Administrator'} Role + */ + /** * Create a new user account. * * @param {string} username User name. * @param {string?} firstName First name. * @param {string?} lastName Last name. + * @param {string?} role Role. + * + * @return {string} Password for the newly created user account */ -export async function createUser( username, firstName, lastName ) { +export async function createUser( username, firstName, lastName, role ) { await switchUserToAdmin(); await visitAdminPage( 'user-new.php' ); @@ -29,11 +36,18 @@ export async function createUser( username, firstName, lastName ) { if ( lastName ) { await page.type( '#last_name', lastName ); } + if ( role ) { + await page.select( '#role', role ); + } + await page.click( '#send_user_notification' ); + const password = await page.$eval( `#pass1`, ( element ) => element.value ); + await Promise.all( [ page.click( '#createusersub' ), page.waitForNavigation( { waitUntil: 'networkidle0' } ), ] ); await switchUserToTest(); + return password; } From 8eb02f9d07bf159b507bf2770f6a33db2102a5c8 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Thu, 24 Jun 2021 20:16:36 +0200 Subject: [PATCH 3/9] deleteUser: Delete content owned by the user, if any --- packages/e2e-test-utils/src/delete-user.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/packages/e2e-test-utils/src/delete-user.js b/packages/e2e-test-utils/src/delete-user.js index 499cf9504598c..5bea271bbfc7a 100644 --- a/packages/e2e-test-utils/src/delete-user.js +++ b/packages/e2e-test-utils/src/delete-user.js @@ -35,6 +35,14 @@ export async function deleteUser( username ) { page.waitForNavigation( { waitUntil: 'networkidle0' } ), ] ); + // If there's content owned by this user, delete it. + const deleteContentRadioButton = await page.$( + 'input[type="radio"][name="delete_option"][value="delete"]' + ); + if ( deleteContentRadioButton ) { + await deleteContentRadioButton.click(); + } + // Confirm await Promise.all( [ page.click( 'input#submit' ), From 8a0e8090e29db8a98ffb7abd93cce663a25d29e9 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Thu, 24 Jun 2021 21:16:25 +0200 Subject: [PATCH 4/9] createUser: Update README to mention role arg and pwd return value --- packages/e2e-test-utils/README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/e2e-test-utils/README.md b/packages/e2e-test-utils/README.md index c4cca972fc0e3..9b50504987d7b 100644 --- a/packages/e2e-test-utils/README.md +++ b/packages/e2e-test-utils/README.md @@ -181,7 +181,12 @@ _Parameters_ - _username_ `string`: User name. - _firstName_ `string?`: First name. -- _lastName_ `string?`: Larst name. +- _lastName_ `string?`: Last name. +- _role_ `string?`: Role. + +_Returns_ + +- `string`: Password for the newly created user account # **deactivatePlugin** From ee26ce27d8c4f2473c13a2fed8a8a85ee1e4acd4 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Fri, 25 Jun 2021 11:34:20 +0200 Subject: [PATCH 5/9] createUser: Use Role type for role arg --- packages/e2e-test-utils/README.md | 2 +- packages/e2e-test-utils/src/create-user.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/e2e-test-utils/README.md b/packages/e2e-test-utils/README.md index 9b50504987d7b..44ffe3e73c8cb 100644 --- a/packages/e2e-test-utils/README.md +++ b/packages/e2e-test-utils/README.md @@ -182,7 +182,7 @@ _Parameters_ - _username_ `string`: User name. - _firstName_ `string?`: First name. - _lastName_ `string?`: Last name. -- _role_ `string?`: Role. +- _role_ `Role?`: Role. _Returns_ diff --git a/packages/e2e-test-utils/src/create-user.js b/packages/e2e-test-utils/src/create-user.js index e83be96f22e66..7e2528629f60c 100644 --- a/packages/e2e-test-utils/src/create-user.js +++ b/packages/e2e-test-utils/src/create-user.js @@ -20,7 +20,7 @@ import { visitAdminPage } from './visit-admin-page'; * @param {string} username User name. * @param {string?} firstName First name. * @param {string?} lastName Last name. - * @param {string?} role Role. + * @param {Role?} role Role. * * @return {string} Password for the newly created user account */ From 82509f97a52035afe7300477991fbbea47e1addf Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Fri, 25 Jun 2021 11:37:22 +0200 Subject: [PATCH 6/9] createUser: Use object for optional args --- packages/e2e-test-utils/README.md | 7 ++++--- packages/e2e-test-utils/src/create-user.js | 14 +++++++++----- .../specs/editor/various/mentions.test.js | 2 +- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/packages/e2e-test-utils/README.md b/packages/e2e-test-utils/README.md index 44ffe3e73c8cb..009a356e83194 100644 --- a/packages/e2e-test-utils/README.md +++ b/packages/e2e-test-utils/README.md @@ -180,9 +180,10 @@ Create a new user account. _Parameters_ - _username_ `string`: User name. -- _firstName_ `string?`: First name. -- _lastName_ `string?`: Last name. -- _role_ `Role?`: Role. +- _object_ `Object?`: Optional Settings for the new user account. +- _object.firstName_ `[string]`: First name. +- _object.lastName_ `[string]`: Last name. +- _object.role_ `[Role]`: Role. _Returns_ diff --git a/packages/e2e-test-utils/src/create-user.js b/packages/e2e-test-utils/src/create-user.js index 7e2528629f60c..38b8eac0a6f15 100644 --- a/packages/e2e-test-utils/src/create-user.js +++ b/packages/e2e-test-utils/src/create-user.js @@ -17,14 +17,18 @@ import { visitAdminPage } from './visit-admin-page'; /** * Create a new user account. * - * @param {string} username User name. - * @param {string?} firstName First name. - * @param {string?} lastName Last name. - * @param {Role?} role Role. + * @param {string} username User name. + * @param {Object?} object Optional Settings for the new user account. + * @param {string} [object.firstName] First name. + * @param {string} [object.lastName] Last name. + * @param {Role} [object.role] Role. * * @return {string} Password for the newly created user account */ -export async function createUser( username, firstName, lastName, role ) { +export async function createUser( + username, + { firstName, lastName, role } = {} +) { await switchUserToAdmin(); await visitAdminPage( 'user-new.php' ); diff --git a/packages/e2e-tests/specs/editor/various/mentions.test.js b/packages/e2e-tests/specs/editor/various/mentions.test.js index 5787edb832940..458449a1b30d4 100644 --- a/packages/e2e-tests/specs/editor/various/mentions.test.js +++ b/packages/e2e-tests/specs/editor/various/mentions.test.js @@ -12,7 +12,7 @@ import { describe( 'autocomplete mentions', () => { beforeAll( async () => { - await createUser( 'testuser', 'Jane', 'Doe' ); + await createUser( 'testuser', { firstName: 'Jane', lastName: 'Doe' } ); } ); beforeEach( async () => { From a7e86e053165cb36928519a1f39d590d1e16e6d9 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Wed, 30 Jun 2021 12:27:48 +0200 Subject: [PATCH 7/9] Change role type to string, and document that it defaults to Administrator --- packages/e2e-test-utils/README.md | 2 +- packages/e2e-test-utils/src/create-user.js | 6 +----- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/packages/e2e-test-utils/README.md b/packages/e2e-test-utils/README.md index 009a356e83194..d986e6adc646f 100644 --- a/packages/e2e-test-utils/README.md +++ b/packages/e2e-test-utils/README.md @@ -183,7 +183,7 @@ _Parameters_ - _object_ `Object?`: Optional Settings for the new user account. - _object.firstName_ `[string]`: First name. - _object.lastName_ `[string]`: Last name. -- _object.role_ `[Role]`: Role. +- _object.role_ `[string]`: Role. Defaults to Administrator. _Returns_ diff --git a/packages/e2e-test-utils/src/create-user.js b/packages/e2e-test-utils/src/create-user.js index 38b8eac0a6f15..d889876b921bc 100644 --- a/packages/e2e-test-utils/src/create-user.js +++ b/packages/e2e-test-utils/src/create-user.js @@ -10,10 +10,6 @@ import { switchUserToAdmin } from './switch-user-to-admin'; import { switchUserToTest } from './switch-user-to-test'; import { visitAdminPage } from './visit-admin-page'; -/** - * @typedef {'Subscriber' | 'Contributor' | 'Author' | 'Editor' | 'Administrator'} Role - */ - /** * Create a new user account. * @@ -21,7 +17,7 @@ import { visitAdminPage } from './visit-admin-page'; * @param {Object?} object Optional Settings for the new user account. * @param {string} [object.firstName] First name. * @param {string} [object.lastName] Last name. - * @param {Role} [object.role] Role. + * @param {string} [object.role] Role. Defaults to Administrator. * * @return {string} Password for the newly created user account */ From d9d961a44dfc087f90775611332b5dc2ee0fc4ce Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Wed, 30 Jun 2021 17:56:26 +0200 Subject: [PATCH 8/9] Trailing period Co-authored-by: Nik Tsekouras --- packages/e2e-test-utils/src/create-user.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/e2e-test-utils/src/create-user.js b/packages/e2e-test-utils/src/create-user.js index d889876b921bc..63fdcee42ca57 100644 --- a/packages/e2e-test-utils/src/create-user.js +++ b/packages/e2e-test-utils/src/create-user.js @@ -19,7 +19,7 @@ import { visitAdminPage } from './visit-admin-page'; * @param {string} [object.lastName] Last name. * @param {string} [object.role] Role. Defaults to Administrator. * - * @return {string} Password for the newly created user account + * @return {string} Password for the newly created user account. */ export async function createUser( username, From a7e9cdf6f696dd16c586dc64839328316a9d6cc8 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Wed, 30 Jun 2021 18:48:43 +0200 Subject: [PATCH 9/9] Trailing period in README :rolleyes: --- packages/e2e-test-utils/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/e2e-test-utils/README.md b/packages/e2e-test-utils/README.md index d986e6adc646f..73bd854890561 100644 --- a/packages/e2e-test-utils/README.md +++ b/packages/e2e-test-utils/README.md @@ -187,7 +187,7 @@ _Parameters_ _Returns_ -- `string`: Password for the newly created user account +- `string`: Password for the newly created user account. # **deactivatePlugin**