Files
threshold-ui/e2e-tests/admin/pages/aliases.js
T
Zhihe Li 7c1814118d refactor: 💡 Move e2e tests to new folder (#2546)
* refactor: 💡 Move e2e tests to new folder

* refactor: 💡 Convert desktop tests to mjs and use es6 imports

* refactor: 💡 Use module setting for e2e directory and remove mjs

* refactor: 💡 Remove "e2e" in all scripts in package.json
2024-11-12 11:21:37 -05:00

58 lines
1.7 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 AliasesPage extends BaseResourcePage {
/**
* Creates an alias
* @param {string} alias Value of the alias
* @param {string} targetId ID of the target
* @returns Name of the alias
*/
async createAliasForTarget(alias, targetId) {
const aliasName = 'Alias ' + nanoid();
await this.page.getByRole('link', { name: 'Orgs', exact: true }).click();
await this.page.getByRole('link', { name: 'Aliases' }).click();
await expect(
this.page
.getByRole('navigation', { name: 'breadcrumbs' })
.getByText('Aliases'),
).toBeVisible();
const newButtonIsVisible = await this.page
.getByRole('link', { name: 'Create a new alias', exact: true })
.isVisible();
if (newButtonIsVisible) {
await this.page
.getByRole('link', { name: 'Create a new alias', exact: true })
.click();
} else {
await this.page
.getByRole('link', { name: 'New Alias', exact: true })
.click();
}
await this.page.getByLabel('Name').fill(aliasName);
await this.page.getByLabel('Description').fill('This is an automated test');
await this.page.getByLabel('Alias Value').fill(alias);
await this.page.getByLabel('Target ID').fill(targetId);
await this.page.getByRole('button', { name: 'Save' }).click();
await this.dismissSuccessAlert();
await expect(
this.page
.getByRole('navigation', { name: 'breadcrumbs' })
.getByText(aliasName),
).toBeVisible();
return aliasName;
}
}