Skip to content
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

E2E Test Utils: Add some functionality to createUser and deleteUser #33067

Merged
merged 9 commits into from
Jun 30, 2021
10 changes: 8 additions & 2 deletions packages/e2e-test-utils/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,14 @@ Create a new user account.
_Parameters_

- _username_ `string`: User name.
- _firstName_ `string?`: First name.
- _lastName_ `string?`: Larst name.
- _object_ `Object?`: Optional Settings for the new user account.
- _object.firstName_ `[string]`: First name.
- _object.lastName_ `[string]`: Last name.
- _object.role_ `[string]`: Role. Defaults to Administrator.

_Returns_

- `string`: Password for the newly created user account.

<a name="deactivatePlugin" href="#deactivatePlugin">#</a> **deactivatePlugin**

Expand Down
22 changes: 18 additions & 4 deletions packages/e2e-test-utils/src/create-user.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,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 Larst name.
* @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 {string} [object.role] Role. Defaults to Administrator.
*
* @return {string} Password for the newly created user account.
*/
export async function createUser( username, firstName, lastName ) {
export async function createUser(
ntsekouras marked this conversation as resolved.
Show resolved Hide resolved
username,
{ firstName, lastName, role } = {}
) {
await switchUserToAdmin();
await visitAdminPage( 'user-new.php' );

Expand All @@ -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;
}
8 changes: 8 additions & 0 deletions packages/e2e-test-utils/src/delete-user.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' ),
Expand Down
2 changes: 1 addition & 1 deletion packages/e2e-tests/specs/editor/various/mentions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {

describe( 'autocomplete mentions', () => {
beforeAll( async () => {
await createUser( 'testuser', 'Jane', 'Doe' );
await createUser( 'testuser', { firstName: 'Jane', lastName: 'Doe' } );
} );

beforeEach( async () => {
Expand Down