From e69175610e018c80ffd74297ebd4e8991ce3b9cc Mon Sep 17 00:00:00 2001 From: Max Cao Date: Thu, 24 Aug 2023 14:15:55 -0700 Subject: [PATCH] final commit --- LOCALIZATION.md | 15 +++++++ src/itest/Dashboard.test.ts | 15 +++---- src/itest/RecordingWorkflow.test.ts | 18 ++------ src/itest/util.ts | 70 ++++++++++++++++------------- 4 files changed, 64 insertions(+), 54 deletions(-) diff --git a/LOCALIZATION.md b/LOCALIZATION.md index ddc23bdafc..82520fda56 100644 --- a/LOCALIZATION.md +++ b/LOCALIZATION.md @@ -1,3 +1,18 @@ +/* +Copyright The Cryostat Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ ## Localization with react-i18next Cryostat-web uses [i18next](https://www.i18next.com/) as an internationalization-framework. The react-i18next package is used to integrate i18next with React. To add new user strings to the project, they must be handled in the manner below. diff --git a/src/itest/Dashboard.test.ts b/src/itest/Dashboard.test.ts index d551100a59..f662f70e43 100644 --- a/src/itest/Dashboard.test.ts +++ b/src/itest/Dashboard.test.ts @@ -14,13 +14,8 @@ * limitations under the License. */ import assert from 'assert'; -import { By, WebDriver, until } from 'selenium-webdriver'; -import { - CardType, - Cryostat, - Dashboard, - setupDriver, -} from './util'; +import { WebDriver } from 'selenium-webdriver'; +import { CardType, Cryostat, Dashboard, setupDriver } from './util'; describe('Dashboard route functionalities', function () { let driver: WebDriver; @@ -30,7 +25,7 @@ describe('Dashboard route functionalities', function () { beforeAll(async function () { driver = await setupDriver(); - cryostat = Cryostat.getInstance(driver); + cryostat = Cryostat.getInstance(driver); dashboard = await cryostat.navigateToDashboard(); await cryostat.skipTour(); @@ -59,11 +54,11 @@ describe('Dashboard route functionalities', function () { await dashboard.addCard(CardType.MBEAN_METRICS_CHART); assert.equal((await dashboard.getCards()).length, 3); - + while ((await dashboard.getCards()).length > 0) { await dashboard.removeCard(); } - + assert.ok(await dashboard.isEmpty()); }); }); diff --git a/src/itest/RecordingWorkflow.test.ts b/src/itest/RecordingWorkflow.test.ts index 13b30449e3..be33400a7e 100644 --- a/src/itest/RecordingWorkflow.test.ts +++ b/src/itest/RecordingWorkflow.test.ts @@ -14,19 +14,9 @@ * limitations under the License. */ import assert from 'assert'; -import { By, WebDriver, until } from 'selenium-webdriver'; -import { - Cryostat, - Dashboard, - Recordings, - getElementByCSS, - getElementById, - getElementByLinkText, - getElementByXPath, - setupDriver, - sleep, -} from './util'; import { RecordingState } from '@app/Shared/Services/Api.service'; +import { WebDriver } from 'selenium-webdriver'; +import { Cryostat, Recordings, setupDriver, sleep } from './util'; describe('Recording workflow steps', function () { let driver: WebDriver; @@ -36,7 +26,7 @@ describe('Recording workflow steps', function () { beforeAll(async function () { driver = await setupDriver(); - cryostat = Cryostat.getInstance(driver); + cryostat = Cryostat.getInstance(driver); recordings = await cryostat.navigateToRecordings(); await cryostat.skipTour(); @@ -89,7 +79,7 @@ describe('Recording workflow steps', function () { assert.equal(active.length, 1); await recordings.deleteRecording(active[0]); - await sleep(10000) + await sleep(10000); assert.equal((await recordings.getRecordings()).length, 0); }); diff --git a/src/itest/util.ts b/src/itest/util.ts index 3a9a4c8b89..31f0ef753f 100644 --- a/src/itest/util.ts +++ b/src/itest/util.ts @@ -45,7 +45,7 @@ export async function setupDriver(): Promise { options.headless(); } options.setAcceptInsecureCerts(true); - options.addArguments("--width=1920", "--height=1080"); + options.addArguments('--width=1920', '--height=1080'); const driver = new Builder().forBrowser('firefox').setFirefoxOptions(options).build(); await driver.manage().setTimeouts({ implicit: DEFAULT_FIND_ELEMENT_TIMEOUT, @@ -82,30 +82,37 @@ export class Cryostat { const targetName = 'Fake Target'; const targetSelect = await this.driver.wait(until.elementLocated(By.css(`[aria-label="Options menu"]`))); await targetSelect.click(); - const targetOption = await this.driver.wait(until.elementLocated(By.xpath(`//*[contains(text(), '${targetName}')]`))); + const targetOption = await this.driver.wait( + until.elementLocated(By.xpath(`//*[contains(text(), '${targetName}')]`)) + ); await targetOption.click(); } - + async skipTour() { const skipButton = await this.driver - .wait(until.elementLocated(By.css('button[data-action="skip"]'))) - .catch(() => null); + .wait(until.elementLocated(By.css('button[data-action="skip"]'))) + .catch(() => null); if (skipButton) await skipButton.click(); } async getLatestNotification(): Promise { - const latestNotification = await this.driver - .wait(until.elementLocated(By.className('pf-c-alert-group pf-m-toast'))) + const latestNotification = await this.driver.wait( + until.elementLocated(By.className('pf-c-alert-group pf-m-toast')) + ); return { - title: await getDirectTextContent(this.driver, await latestNotification.findElement(By.css('li:last-of-type .pf-c-alert__title'))), - description: await latestNotification.findElement(By.css('li:last-of-type .pf-c-alert__description')).getText() - } + title: await getDirectTextContent( + this.driver, + await latestNotification.findElement(By.css('li:last-of-type .pf-c-alert__title')) + ), + description: await latestNotification.findElement(By.css('li:last-of-type .pf-c-alert__description')).getText(), + }; } } // from here: https://stackoverflow.com/a/19040341/22316240 async function getDirectTextContent(driver: WebDriver, el: WebElement): Promise { - return driver.executeScript(` + return driver.executeScript( + ` const parent = arguments[0]; let child = parent.firstChild; let ret = ""; @@ -116,13 +123,15 @@ async function getDirectTextContent(driver: WebDriver, el: WebElement): Promise< child = child.nextSibling; } return ret; - `, el); + `, + el + ); } interface ITestNotification { - title: string, - description: string -} + title: string; + description: string; +} export class Dashboard { private driver: WebDriver; @@ -148,33 +157,34 @@ export class Dashboard { } async getCards(): Promise { - return (await this.driver.findElements(By.className('dashboard-card'))); + return await this.driver.findElements(By.className('dashboard-card')); } async addCard(cardType: CardType) { - let finishButton; const addCardButton = await getElementByCSS(this.driver, `[aria-label="Add card"]`); await addCardButton.click(); - const twoPartCards = [CardType.AUTOMATED_ANALYSIS, CardType.JFR_METRICS_CHART, CardType.MBEAN_METRICS_CHART] + const twoPartCards = [CardType.AUTOMATED_ANALYSIS, CardType.JFR_METRICS_CHART, CardType.MBEAN_METRICS_CHART]; - switch(cardType) { - case CardType.AUTOMATED_ANALYSIS: + switch (cardType) { + case CardType.AUTOMATED_ANALYSIS: { const aaCard = await getElementById(this.driver, `AutomatedAnalysisCard.CARD_TITLE`); await aaCard.click(); break; + } case CardType.JFR_METRICS_CHART: break; - case CardType.TARGET_JVM_DETAILS: + case CardType.TARGET_JVM_DETAILS: { const detailsCard = await getElementById(this.driver, `JvmDetailsCard.CARD_TITLE`); await detailsCard.click(); break; - case CardType.MBEAN_METRICS_CHART: + } + case CardType.MBEAN_METRICS_CHART: { const mbeanCard = await getElementById(this.driver, `CHART_CARD.MBEAN_METRICS_CARD_TITLE`); await mbeanCard.click(); break; + } } - - finishButton = await getElementByCSS(this.driver, 'button.pf-c-button.pf-m-primary[type="submit"]'); + const finishButton = await getElementByCSS(this.driver, 'button.pf-c-button.pf-m-primary[type="submit"]'); await finishButton.click(); if (twoPartCards.includes(cardType)) { await finishButton.click(); @@ -182,7 +192,7 @@ export class Dashboard { } async removeCard() { - let el: WebElement[] = await this.getCards(); + const el: WebElement[] = await this.getCards(); let firstCard; if (el.length > 0) { firstCard = el[0]; @@ -191,10 +201,10 @@ export class Dashboard { return; } - let actionsButton = await getElementByCSS(this.driver, 'button[aria-label="Actions"]'); + const actionsButton = await getElementByCSS(this.driver, 'button[aria-label="Actions"]'); await actionsButton.click(); - let removeButton = await getElementByLinkText(this.driver, 'Remove'); + const removeButton = await getElementByLinkText(this.driver, 'Remove'); await removeButton.click(); } } @@ -253,15 +263,15 @@ export class Recordings { // async removeAllLabels(recording: WebElement) { // await recording.findElement(By.xpath(`.//input[@data-quickstart-id='active-recordings-checkbox']`)).click(); - // } + // } } // utility function for integration test debugging -export const sleep = (ms = 0) => new Promise(resolve => setTimeout(resolve, ms)); +export const sleep = (ms = 0) => new Promise((resolve) => setTimeout(resolve, ms)); export enum CardType { TARGET_JVM_DETAILS, AUTOMATED_ANALYSIS, JFR_METRICS_CHART, - MBEAN_METRICS_CHART + MBEAN_METRICS_CHART, }