2024-08-06 13:15:00 -04:00
|
|
|
/**
|
2026-01-28 17:09:06 -08:00
|
|
|
* Copyright IBM Corp. 2021, 2026
|
2024-08-06 13:15:00 -04:00
|
|
|
* SPDX-License-Identifier: BUSL-1.1
|
|
|
|
|
*/
|
|
|
|
|
|
2024-08-19 16:00:16 -04:00
|
|
|
import { expect } from '@playwright/test';
|
|
|
|
|
import { nanoid } from 'nanoid';
|
2024-08-06 13:15:00 -04:00
|
|
|
|
2024-11-12 11:21:37 -05:00
|
|
|
import { BaseResourcePage } from './base-resource.js';
|
2024-08-06 13:15:00 -04:00
|
|
|
|
2024-08-19 16:00:16 -04:00
|
|
|
export class RolesPage extends BaseResourcePage {
|
2025-06-23 14:27:36 -04:00
|
|
|
goToRolesPage({ scope }) {
|
|
|
|
|
scope = scope ?? 'global';
|
|
|
|
|
this.page.goto(`/scopes/${scope}/roles`);
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-06 13:15:00 -04:00
|
|
|
/**
|
|
|
|
|
* Creates a new role. Assumes you have selected the desired scope.
|
|
|
|
|
*/
|
|
|
|
|
async createRole() {
|
|
|
|
|
const roleName = 'Role ' + nanoid();
|
|
|
|
|
|
|
|
|
|
await this.page
|
2026-02-25 13:55:36 -08:00
|
|
|
.getByRole('navigation', { name: 'Primary' })
|
2024-08-06 13:15:00 -04:00
|
|
|
.getByRole('link', { name: 'Roles' })
|
|
|
|
|
.click();
|
|
|
|
|
await this.page.getByRole('link', { name: 'New Role' }).click();
|
|
|
|
|
await this.page.getByLabel('Name').fill(roleName);
|
2025-12-23 12:32:16 -05:00
|
|
|
await this.page.getByRole('button', { name: 'Save', exact: true }).click();
|
2024-08-06 13:15:00 -04:00
|
|
|
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();
|
2026-05-11 14:08:42 -07:00
|
|
|
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);
|
2024-08-06 13:15:00 -04:00
|
|
|
await this.page.getByRole('button', { name: 'Save', exact: true }).click();
|
2024-08-23 10:17:10 -04:00
|
|
|
await this.dismissSuccessAlert();
|
2024-08-06 13:15:00 -04:00
|
|
|
await expect(
|
2026-05-11 14:08:42 -07:00
|
|
|
this.page.locator('.grant-codeblock .hds-code-block__code'),
|
|
|
|
|
).toHaveText(grants);
|
2024-08-06 13:15:00 -04:00
|
|
|
}
|
|
|
|
|
}
|