* refactor: 💡 grants tab to use code block * refactor: 💡 update getter comment * test: 💍 fix tests * refactor: 💡 remove language arg for codeblock ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-18757
85 lines
2.7 KiB
JavaScript
85 lines
2.7 KiB
JavaScript
/**
|
|
* Copyright IBM Corp. 2021, 2026
|
|
* SPDX-License-Identifier: BUSL-1.1
|
|
*/
|
|
|
|
import { expect } from '@playwright/test';
|
|
import { nanoid } from 'nanoid';
|
|
|
|
import { BaseResourcePage } from './base-resource.js';
|
|
|
|
export class RolesPage extends BaseResourcePage {
|
|
goToRolesPage({ scope }) {
|
|
scope = scope ?? 'global';
|
|
this.page.goto(`/scopes/${scope}/roles`);
|
|
}
|
|
|
|
/**
|
|
* Creates a new role. Assumes you have selected the desired scope.
|
|
*/
|
|
async createRole() {
|
|
const roleName = 'Role ' + nanoid();
|
|
|
|
await this.page
|
|
.getByRole('navigation', { name: 'Primary' })
|
|
.getByRole('link', { name: 'Roles' })
|
|
.click();
|
|
await this.page.getByRole('link', { name: 'New Role' }).click();
|
|
await this.page.getByLabel('Name').fill(roleName);
|
|
await this.page.getByRole('button', { name: 'Save', exact: true }).click();
|
|
await this.dismissSuccessAlert();
|
|
await expect(
|
|
this.page
|
|
.getByRole('navigation', { name: 'breadcrumbs' })
|
|
.getByText(roleName),
|
|
).toBeVisible();
|
|
|
|
return roleName;
|
|
}
|
|
|
|
/**
|
|
* Adds a principal to a role. Assumes you have selected the desired role.
|
|
* @param {string} principalName Name of the principal that will be added to the role
|
|
*/
|
|
async addPrincipalToRole(principalName) {
|
|
await this.page
|
|
.getByRole('link', { name: 'Principals', exact: true })
|
|
.click();
|
|
await this.page
|
|
.getByRole('link', { name: 'Add Principals', exact: true })
|
|
.click();
|
|
await this.page.getByRole('checkbox', { name: principalName }).click();
|
|
await this.page
|
|
.getByRole('button', { name: 'Add Principals', exact: true })
|
|
.click();
|
|
await this.dismissSuccessAlert();
|
|
await expect(
|
|
this.page.getByRole('table').getByRole('link', { name: principalName }),
|
|
).toBeVisible();
|
|
}
|
|
|
|
/**
|
|
* Adds a grant to the role. Assumes you have selected the desired role.
|
|
* @param {string} grants grants that will be given to the role
|
|
*/
|
|
async addGrantsToRole(grants) {
|
|
await this.page.getByRole('link', { name: 'Grants', exact: true }).click();
|
|
await this.page
|
|
.getByRole('link', { name: 'Edit Grants', exact: true })
|
|
.click();
|
|
await this.page.locator('.hds-code-editor').getByRole('textbox').click();
|
|
await expect(
|
|
this.page.locator('.hds-code-editor').getByRole('textbox'),
|
|
).toBeFocused();
|
|
await this.page
|
|
.locator('.hds-code-editor')
|
|
.getByRole('textbox')
|
|
.fill(grants);
|
|
await this.page.getByRole('button', { name: 'Save', exact: true }).click();
|
|
await this.dismissSuccessAlert();
|
|
await expect(
|
|
this.page.locator('.grant-codeblock .hds-code-block__code'),
|
|
).toHaveText(grants);
|
|
}
|
|
}
|