Skip to content

Commit

Permalink
Test to cover the widgets functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
Ygnas committed Sep 23, 2024
1 parent 3b4c878 commit be9b9a5
Showing 1 changed file with 76 additions and 3 deletions.
79 changes: 76 additions & 3 deletions ui-tests/tests/widget_notebook_example.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ import { test } from "@jupyterlab/galata";
import { expect } from "@playwright/test";
import * as path from "path";

test.setTimeout(460000);

test.describe("Visual Regression", () => {
test.beforeEach(async ({ page, tmpPath }) => {
await page.contents.uploadDirectory(
Expand All @@ -27,7 +25,7 @@ test.describe("Visual Regression", () => {
await page.filebrowser.openDirectory(tmpPath);
});

test("Run notebook and capture cell outputs", async ({
test("Run notebook, capture cell outputs, and test widgets", async ({
page,
tmpPath,
}) => {
Expand Down Expand Up @@ -60,5 +58,80 @@ test.describe("Visual Regression", () => {
continue;
}
}

const widgetCellIndex = 3;

await waitForWidget(page, widgetCellIndex, 'input[type="checkbox"]');
await waitForWidget(page, widgetCellIndex, 'button:has-text("Cluster Down")');
await waitForWidget(page, widgetCellIndex, 'button:has-text("Cluster Up")');

await interactWithWidget(page, widgetCellIndex, 'input[type="checkbox"]', async (checkbox) => {
await checkbox.click();
const isChecked = await checkbox.isChecked();
expect(isChecked).toBe(true);
});

await interactWithWidget(page, widgetCellIndex, 'button:has-text("Cluster Down")', async (button) => {
await button.click();
const clusterDownMessage = await page.waitForSelector('text=No instances found, nothing to be done.', { timeout: 5000 });
expect(clusterDownMessage).not.toBeNull();
});

await interactWithWidget(page, widgetCellIndex, 'button:has-text("Cluster Up")', async (button) => {
await button.click();

const successMessage = await page.waitForSelector('text=Ray Cluster: \'raytest\' has successfully been created', { timeout: 10000 });
expect(successMessage).not.toBeNull();

const resourcesMessage = await page.waitForSelector('text=Waiting for requested resources to be set up...');
expect(resourcesMessage).not.toBeNull();

const upAndRunningMessage = await page.waitForSelector('text=Requested cluster is up and running!');
expect(upAndRunningMessage).not.toBeNull();

const dashboardReadyMessage = await page.waitForSelector('text=Dashboard is ready!');
expect(dashboardReadyMessage).not.toBeNull();
});

await runPreviousCell(page, cellCount, '(<CodeFlareClusterStatus.READY: 1>, True)');

await interactWithWidget(page, widgetCellIndex, 'button:has-text("Cluster Down")', async (button) => {
await button.click();
const clusterDownMessage = await page.waitForSelector('text=Ray Cluster: \'raytest\' has successfully been deleted', { timeout: 5000 });
expect(clusterDownMessage).not.toBeNull();
});

await runPreviousCell(page, cellCount, '(<CodeFlareClusterStatus.UNKNOWN: 6>, False)');
});
});

async function waitForWidget(page, cellIndex: number, widgetSelector: string, timeout = 5000) {
const widgetCell = await page.notebook.getCellOutput(cellIndex);

if (widgetCell) {
await widgetCell.waitForSelector(widgetSelector, { timeout });
}
}

async function interactWithWidget(page, cellIndex: number, widgetSelector: string, action: (widget) => Promise<void>) {
const widgetCell = await page.notebook.getCellOutput(cellIndex);

if (widgetCell) {
const widget = await widgetCell.$(widgetSelector);
if (widget) {
await action(widget);
}
}
}

async function runPreviousCell(page, cellCount, expectedMessage) {
const runSuccess = await page.notebook.runCell(cellCount - 1); expect(runSuccess).toBe(true);
const lastCellOutput = await page.notebook.getCellOutput(cellCount - 1);
const newOutput = await lastCellOutput.evaluate((output) => output.textContent);

if (expectedMessage) {
expect(newOutput).toContain(expectedMessage);
}

return lastCellOutput;
}

0 comments on commit be9b9a5

Please sign in to comment.