Skip to content

Commit

Permalink
final commit
Browse files Browse the repository at this point in the history
  • Loading branch information
maxcao13 committed Aug 24, 2023
1 parent 9c67de9 commit e691756
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 54 deletions.
15 changes: 15 additions & 0 deletions LOCALIZATION.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
15 changes: 5 additions & 10 deletions src/itest/Dashboard.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
Expand Down Expand Up @@ -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());
});
});
18 changes: 4 additions & 14 deletions src/itest/RecordingWorkflow.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
Expand Down Expand Up @@ -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);
});

Expand Down
70 changes: 40 additions & 30 deletions src/itest/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export async function setupDriver(): Promise<WebDriver> {
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,
Expand Down Expand Up @@ -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<ITestNotification> {
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<string> {
return driver.executeScript<string>(`
return driver.executeScript<string>(
`
const parent = arguments[0];
let child = parent.firstChild;
let ret = "";
Expand All @@ -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;
Expand All @@ -148,41 +157,42 @@ export class Dashboard {
}

async getCards(): Promise<WebElement[]> {
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();
}
}

async removeCard() {
let el: WebElement[] = await this.getCards();
const el: WebElement[] = await this.getCards();
let firstCard;
if (el.length > 0) {
firstCard = el[0];
Expand All @@ -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();
}
}
Expand Down Expand Up @@ -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,
}

0 comments on commit e691756

Please sign in to comment.