Files
threshold-ui/e2e-tests/admin/pages/users.js
T
Lisbet Alvarez 0623d4ad47 Fix e2e test page selectors due to hds refactor (#2610)
* chore: 🤖 fix e2e broken tests due to hds refactor

* chore: 🤖 remove unneeded change & fix another selector

* chore: 🤖 upgrade playwright

* chore: 🤖 remove unneeded dependency in desktop ui
2024-12-10 16:24:25 -08:00

60 lines
1.6 KiB
JavaScript

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: BUSL-1.1
*/
import { expect } from '@playwright/test';
import { nanoid } from 'nanoid';
import { BaseResourcePage } from './base-resource.js';
export class UsersPage extends BaseResourcePage {
/**
* Creates a new user.
* @returns Name of the user
*/
async createUser() {
const userName = 'User ' + nanoid();
await this.page
.getByRole('navigation', { name: 'IAM' })
.getByRole('link', { name: 'Users' })
.click();
await this.page.getByRole('link', { name: 'New', exact: true }).click();
await this.page.getByLabel('Name').fill(userName);
await this.page.getByRole('button', { name: 'Save' }).click();
await this.dismissSuccessAlert();
await expect(
this.page
.getByRole('navigation', { name: 'breadcrumbs' })
.getByText(userName),
).toBeVisible();
return userName;
}
/**
* Adds an account to a user
* Assumes you have selected the desired user.
* Assumes you have created new account.
* @param {string} loginName Login name of the account
*/
async addAccountToUser(loginName) {
await this.page
.getByRole('link', { name: 'Accounts', exact: true })
.click();
await this.page
.getByRole('link', { name: 'Add Accounts', exact: true })
.click();
await this.page
.getByRole('cell', { name: loginName })
.locator('..')
.getByRole('checkbox')
.click({ force: true });
await this.page
.getByRole('button', { name: 'Add Accounts', exact: true })
.click();
await this.dismissSuccessAlert();
}
}