Files
threshold-ui/ui/desktop/tests/end2end/targets.spec.js
T

126 lines
4.0 KiB
JavaScript
Raw Normal View History

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: MPL-2.0
*/
2021-10-07 13:28:51 -07:00
/* eslint-disable no-undef */
const { test, expect } = require('@playwright/test');
const { _electron: electron } = require('@playwright/test');
2021-10-18 12:52:39 -07:00
const helpers = require('./test-helpers');
2021-10-07 13:28:51 -07:00
let electronApp = null;
2021-10-22 09:11:10 -07:00
// Subdirectory within tests/end2end/screenshots where the screenshots of this test suite will be stored.
const screenshotsDirectory = 'targets/';
2021-10-22 09:11:10 -07:00
// Path where the Boundary Desktop client binary is generated
2021-10-18 12:52:39 -07:00
const executablePath = helpers.returnExecutablePath(
process.platform,
process.arch
);
2021-10-07 13:28:51 -07:00
2021-10-22 09:11:10 -07:00
// Set login variables
2022-07-27 10:25:01 -07:00
const clusterUrlValue = 'http://localhost:9200';
2021-10-22 09:11:10 -07:00
const loginUsername = 'admin';
const loginPassword = 'password';
2021-10-07 13:28:51 -07:00
test.beforeEach(async () => {
electronApp = await electron.launch({
executablePath: executablePath,
2021-10-07 13:28:51 -07:00
env: {
NODE_ENV: 'test',
BYPASS_APP_UPDATER: true,
},
});
});
test.afterEach(async () => {
electronApp.close();
electronApp = null; // Not sure we should do this.
});
2021-10-22 09:11:10 -07:00
test.describe('Targets end to end test suite', async () => {
2021-10-07 13:28:51 -07:00
test('Connects to a target', async () => {
const boundaryWindow = await electronApp.firstWindow(); // The window that contains the app.
2022-07-27 10:25:01 -07:00
// Override local storage cluster URL
2021-10-07 13:28:51 -07:00
await boundaryWindow.evaluate(() =>
2022-07-27 10:25:01 -07:00
window.localStorage.setItem('desktop:clusterURL', null)
2021-10-07 13:28:51 -07:00
);
// Perform the login
await helpers.login(
boundaryWindow,
2022-07-27 10:25:01 -07:00
clusterUrlValue,
2021-10-22 09:11:10 -07:00
loginUsername,
loginPassword
);
2021-10-07 13:28:51 -07:00
// Check we are in Targets
await boundaryWindow.waitForURL('**/#/scopes/global/projects/targets');
const windowUrl = new URL(await boundaryWindow.url());
expect(windowUrl.hash).toEqual('#/scopes/global/projects/targets');
2021-10-07 13:28:51 -07:00
// Click connect to a target
await boundaryWindow.waitForSelector('table.rose-table');
2021-10-18 12:52:39 -07:00
await helpers.click(
2021-10-14 13:33:52 -07:00
boundaryWindow,
'table.rose-table >> tbody >> tr >> nth=0 >> button >> text=Connect'
2021-10-07 13:28:51 -07:00
);
// The target popup opens
await boundaryWindow.waitForSelector('section.dialog-detail');
// Take screenshot
await boundaryWindow.screenshot({
2021-10-18 12:52:39 -07:00
path: helpers.generateScreenshotPath(
screenshotsDirectory,
'targetConnectionDetails'
),
2021-10-07 13:28:51 -07:00
fullPage: true,
});
// Click copyable in popup
// TODO: read clipboard value. Running into issues reading clipboard, so will take a shortcut for now
2021-10-18 12:52:39 -07:00
await helpers.click(
2021-10-14 13:33:52 -07:00
boundaryWindow,
'section.dialog-detail >> div.rose-dialog-body >> button'
2021-10-07 13:28:51 -07:00
);
// Temporary: persist proxy from target
const persistedProxy = await boundaryWindow.innerText(
'section.dialog-detail >> div.rose-dialog-body >> span.copyable-content'
);
// Click close popup
2021-10-18 12:52:39 -07:00
await helpers.click(
2021-10-14 13:33:52 -07:00
boundaryWindow,
'section.dialog-detail >> footer >> button'
2021-10-07 13:28:51 -07:00
);
// On left nav menu, click Sessions
await boundaryWindow.waitForSelector('section.rose-layout-global >> aside');
2021-10-18 12:52:39 -07:00
await helpers.click(
2021-10-14 13:33:52 -07:00
boundaryWindow,
'section.rose-layout-global >> aside >> nav >> a >> text=Sessions'
2021-10-07 13:28:51 -07:00
);
// Take screenshot
await boundaryWindow.screenshot({
2021-10-18 12:52:39 -07:00
path: helpers.generateScreenshotPath(screenshotsDirectory, 'sessions'),
2021-10-07 13:28:51 -07:00
fullPage: true,
});
// Check the right session has status pending.
await boundaryWindow.waitForSelector(
'main >> div.rose-layout-page-body >> table.rose-table'
);
// Select Proxy
const currentProxy = await boundaryWindow.innerText(
'div.rose-layout-page-body >> table >> tbody >> tr >> nth=0 >> td >> nth=1 >> .copyable-content'
);
const currentStatus = await boundaryWindow.innerText(
2022-11-17 10:44:04 -08:00
'div.rose-layout-page-body >> table >> tbody >> tr >> nth=0 >> td >> nth=3 >> .hds-badge'
2021-10-07 13:28:51 -07:00
);
expect(await persistedProxy).toEqual(await currentProxy);
expect(await currentStatus).toEqual('pending');
// TODO: before closing the app we should terminate sessions.
// TODO: add test to check if sessions are not terminated we promp the confirmation dialog
});
});