Files
threshold-ui/e2e-tests/admin/pages/targets.js
T
d469f305de Replace Rose::CodeEditor with Hds::CodeEditor (#2679)
* chore: 🤖 replace Rose::CodeEditor with Hds::CodeEditor

- Remove CodeEditor 5 dependency

* chore: 🤖 Replace CodeMirror5 dep

remove CodeMirror5 and replace existing editors with HDS::CodeEditor

* chore: 🤖 deleting old codeeditor styles

* feat: 🎸 changing code editor

changing code editor

✅ Closes: 0

* removed unused export

* pr cleanup

* updating tests for new code editor

* responding to PR feedback

* added whitespace

* fixing linting violations

* chore: 🤖 self-review PR

self-review PR in the course of switching to new HDS code editor

* fix: 🐛 fix linting bug

* fix: 🐛 unneeded dependency

remove jslint dependency as this is handled in the new code editor from
HDS

* fix: 🐛 Fixing import bug

Fix import bug caused by importing scss modules that no longer exist

* Fix and refactor code editor acceptance test

* Fix and refactor code editor acceptance test

* chore: 🤖 remove codemirror dependency

* refactor: 💡 fix merge conflict issues

* test: 💍 update e2e test selectors

* test: 💍 fix target spec click event

* refactor: 💡 clean up test selectors for code editor

* refactor: 💡 clean up storage bucket test selectors

* chore: 🤖 remove code mirror modifiers

---------

Co-authored-by: calcaide <ccorvo@hashicorp.com>
Co-authored-by: cameronperera <cameron.perera@hashicorp.com>
2026-05-14 15:21:27 -04:00

326 lines
10 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 TargetsPage extends BaseResourcePage {
/**
* Creates a new target with address and alias. Assumes you have selected the desired project.
* @param {string} targetType Type of target (ssh, rdp, tcp)
* @param {string} address Address of the target
* @param {string} port Port of the target
* @param {string} alias alias used for the target
* @returns Name of the target
*/
async createTarget({ targetType, port, address, alias }) {
const targetName = 'Target ' + nanoid();
let targetTypeLabel;
switch (targetType) {
case 'ssh': {
targetTypeLabel = 'SSH';
break;
}
case 'rdp': {
targetTypeLabel = 'RDP';
break;
}
case 'tcp': {
targetTypeLabel = 'Generic TCP';
break;
}
}
await this.page
.getByRole('navigation', { name: 'Primary' })
.getByRole('link', { name: 'Targets' })
.click();
await this.page.getByRole('link', { name: 'New', exact: true }).click();
await this.page.getByLabel('Name').fill(targetName);
await this.page.getByLabel('Description').fill('This is an automated test');
if (targetType) {
if (targetTypeLabel) {
await this.page
.getByRole('group', { name: 'Type' })
.getByLabel(targetTypeLabel)
.click();
} else {
throw new Error(`Unsupported target type: ${targetType}`);
}
}
if (address) await this.page.getByLabel('Target Address').fill(address);
if (port) await this.page.getByLabel('Default Port').fill(port);
if (alias) {
await this.page
.getByRole('group', { name: 'Aliases' })
.getByLabel('value')
.last()
.fill(alias);
await this.page.getByRole('button', { name: 'Add' }).click();
}
await this.page.getByRole('button', { name: 'Save', exact: true }).click();
await this.dismissSuccessAlert();
await expect(
this.page
.getByRole('navigation', { name: 'breadcrumbs' })
.getByText(targetName),
).toBeVisible();
return targetName;
}
/**
* Adds a host source to a target. Assume you have selected the desired target.
* @param {string} hostSourceName Name of host source that will be attached to the target
*/
async addHostSourceToTarget(hostSourceName) {
await this.page
.getByRole('link', { name: 'Host Sources', exact: true })
.click();
await expect(
this.page
.getByRole('navigation', { name: 'breadcrumbs' })
.getByText('Host Sources'),
).toBeVisible();
const emptyLinkIsVisible = await this.page
.getByRole('link', { name: 'Add Host Sources', exact: true })
.isVisible();
if (!emptyLinkIsVisible) {
await this.page.getByText('Manage').click();
}
await this.page
.getByRole('link', { name: 'Add Host Sources', exact: true })
.click();
await this.page
.getByRole('row')
.filter({ has: this.page.getByRole('cell', { name: hostSourceName }) })
.getByRole('checkbox')
.click({ force: true });
await this.page.getByRole('button', { name: 'Add Host Sources' }).click();
await this.dismissSuccessAlert();
await expect(
this.page.getByRole('link', { name: hostSourceName }),
).toBeVisible();
}
async removeHostSourceFromTarget(hostSourceName) {
await this.page
.getByRole('row')
.filter({ has: this.page.getByRole('link', { name: hostSourceName }) })
.getByRole('button', { name: 'Manage' })
.click();
await this.page.getByRole('button', { name: 'Remove' }).click();
await this.page.getByRole('button', { name: 'OK', exact: true }).click();
await this.dismissSuccessAlert();
}
/**
* Adds an ingress worker filter to a target. Assume you have selected the desired target.
* @param {string} filter Ingress worker filter to be added to the target
*/
async addIngressWorkerFilterToTarget(filter) {
await this.page.getByRole('link', { name: 'Workers', exact: true }).click();
await expect(
this.page
.getByRole('navigation', { name: 'breadcrumbs' })
.getByText('Workers'),
).toBeVisible();
await this.page
.getByText('Ingress workers')
.locator('..')
.getByRole('link', { name: 'Add worker filter' })
.click();
await expect(
this.page
.getByRole('navigation', { name: 'breadcrumbs' })
.getByText('Edit Ingress Worker Filter'),
).toBeVisible();
await this.page
.locator('.hds-code-editor')
.getByRole('textbox')
.fill(filter);
await this.page.getByRole('button', { name: 'Save', exact: true }).click();
await this.dismissSuccessAlert();
}
/**
* Adds an egress worker filter to a target. Assume you have selected the desired target.
* @param {string} filter Egress worker filter to be added to the target
*/
async addEgressWorkerFilterToTarget(filter) {
await this.page.getByRole('link', { name: 'Workers', exact: true }).click();
await expect(
this.page
.getByRole('navigation', { name: 'breadcrumbs' })
.getByText('Workers'),
).toBeVisible();
await this.page
.getByText('Egress workers')
.locator('..')
.getByRole('link', { name: 'Add worker filter' })
.click();
await expect(
this.page
.getByRole('navigation', { name: 'breadcrumbs' })
.getByText('Edit Egress Worker Filter'),
).toBeVisible();
await this.page
.locator('.hds-code-editor')
.getByRole('textbox')
.fill(filter);
await this.page.getByRole('button', { name: 'Save', exact: true }).click();
await this.dismissSuccessAlert();
}
/**
* Adds brokered credentials to a target
* @param {string} targetName Name of the target associated with the session
* @param {string} credentialName Name of the credentials to be added to the target
*/
async addBrokeredCredentialsToTarget(targetName, credentialName) {
await this.page
.getByRole('navigation', { name: 'Primary' })
.getByRole('link', { name: 'Targets' })
.click();
await expect(
this.page.getByRole('heading', { name: 'Targets' }),
).toBeVisible();
await this.page.getByRole('link', { name: targetName }).click();
await this.page
.getByRole('link', { name: 'Brokered Credentials', exact: true })
.click();
await expect(
this.page
.getByRole('navigation', { name: 'breadcrumbs' })
.getByText('Brokered Credentials'),
).toBeVisible();
const addBrokeredCredentialsButtonIsVisible = await this.page
.getByRole('link', { name: 'Add Brokered Credentials', exact: true })
.isVisible();
if (!addBrokeredCredentialsButtonIsVisible) {
await this.page.getByText('Manage').click();
}
await this.page
.getByRole('link', { name: 'Add Brokered Credentials', exact: true })
.click();
await this.page
.getByRole('row')
.filter({ has: this.page.getByRole('cell', { name: credentialName }) })
.getByRole('checkbox')
.click({ force: true });
await this.page
.getByRole('button', { name: 'Add Brokered Credentials', exact: true })
.click();
await this.dismissSuccessAlert();
await expect(
this.page.getByRole('link', { name: credentialName }),
).toBeVisible();
}
/**
* Adds injected credentials to a target
* @param {string} targetName Name of the target associated with the session
* @param {string} credentialName Name of the credentials to be added to the target
*/
async addInjectedCredentialsToTarget(targetName, credentialName) {
await this.page
.getByRole('navigation', { name: 'Primary' })
.getByRole('link', { name: 'Targets' })
.click();
await expect(
this.page.getByRole('heading', { name: 'Targets' }),
).toBeVisible();
await this.page.getByRole('link', { name: targetName }).click();
await this.page
.getByRole('link', {
name: 'Injected Application Credentials',
exact: true,
})
.click();
await expect(
this.page
.getByRole('navigation', { name: 'breadcrumbs' })
.getByText('Injected Application Credentials'),
).toBeVisible();
const addInjectedCredentialsButtonIsVisible = await this.page
.getByRole('link', {
name: 'Add Injected Application Credentials',
exact: true,
})
.isVisible();
if (!addInjectedCredentialsButtonIsVisible) {
await this.page.getByText('Manage').click();
}
await this.page
.getByRole('link', {
name: 'Add Injected Application Credentials',
exact: true,
})
.click();
await this.page
.getByRole('row')
.filter({ has: this.page.getByRole('cell', { name: credentialName }) })
.getByRole('checkbox')
.click({ force: true });
await this.page
.getByRole('button', {
name: 'Add Injected Application Credentials',
exact: true,
})
.click();
await this.dismissSuccessAlert();
await expect(
this.page.getByRole('link', { name: credentialName }),
).toBeVisible();
}
/**
* Enables session recording for a target. Assumes you have selected the desired target.
* @param {string} storageBucketName name of the Storage Bucket used for session recording
*/
async enableSessionRecording(storageBucketName) {
await this.page.getByText('Enable recording').click();
await this.page.getByLabel('Record sessions for this target').click();
await this.page
.getByLabel('Storage buckets')
.selectOption({ label: storageBucketName });
await this.page.getByRole('button', { name: 'Save', exact: true }).click();
await this.dismissSuccessAlert();
await expect(
this.page.getByRole('listitem').getByText(storageBucketName),
).toBeVisible();
}
/**
* Detaches storage bucket from target. Assumes you have selected the desired target.
*/
async detachStorageBucket() {
await this.page
.getByRole('link', { name: 'Session Recording settings' })
.click();
await this.page.getByLabel('Record sessions for this target').uncheck();
await this.page.getByRole('button', { name: 'Save', exact: true }).click();
await this.dismissSuccessAlert();
}
}