Skip to content

Commit be97842

Browse files
committed
Test to cover the widgets functionality
1 parent 3b689b6 commit be97842

File tree

1 file changed

+76
-1
lines changed

1 file changed

+76
-1
lines changed

ui-tests/tests/widget_notebook_example.test.ts

+76-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ test.describe("Visual Regression", () => {
2727
await page.filebrowser.openDirectory(tmpPath);
2828
});
2929

30-
test("Run notebook and capture cell outputs", async ({
30+
test("Run notebook, capture cell outputs, and test widgets", async ({
3131
page,
3232
tmpPath,
3333
}) => {
@@ -59,5 +59,80 @@ test.describe("Visual Regression", () => {
5959
continue;
6060
}
6161
}
62+
63+
const widgetCellIndex = 4;
64+
65+
await waitForWidget(page, widgetCellIndex, 'input[type="checkbox"]');
66+
await waitForWidget(page, widgetCellIndex, 'button:has-text("Cluster Down")');
67+
await waitForWidget(page, widgetCellIndex, 'button:has-text("Cluster Up")');
68+
69+
await interactWithWidget(page, widgetCellIndex, 'input[type="checkbox"]', async (checkbox) => {
70+
await checkbox.click();
71+
const isChecked = await checkbox.isChecked();
72+
expect(isChecked).toBe(true);
73+
});
74+
75+
await interactWithWidget(page, widgetCellIndex, 'button:has-text("Cluster Down")', async (button) => {
76+
await button.click();
77+
const clusterDownMessage = await page.waitForSelector('text=No instances found, nothing to be done.', { timeout: 5000 });
78+
expect(clusterDownMessage).not.toBeNull();
79+
});
80+
81+
await interactWithWidget(page, widgetCellIndex, 'button:has-text("Cluster Up")', async (button) => {
82+
await button.click();
83+
84+
const successMessage = await page.waitForSelector('text=Ray Cluster: \'raytest\' has successfully been created', { timeout: 10000 });
85+
expect(successMessage).not.toBeNull();
86+
87+
const resourcesMessage = await page.waitForSelector('text=Waiting for requested resources to be set up...');
88+
expect(resourcesMessage).not.toBeNull();
89+
90+
const upAndRunningMessage = await page.waitForSelector('text=Requested cluster is up and running!');
91+
expect(upAndRunningMessage).not.toBeNull();
92+
93+
const dashboardReadyMessage = await page.waitForSelector('text=Dashboard is ready!');
94+
expect(dashboardReadyMessage).not.toBeNull();
95+
});
96+
97+
await runLastCell(page, cellCount, '(<CodeFlareClusterStatus.READY: 1>, True)');
98+
99+
await interactWithWidget(page, widgetCellIndex, 'button:has-text("Cluster Down")', async (button) => {
100+
await button.click();
101+
const clusterDownMessage = await page.waitForSelector('text=Ray Cluster: \'raytest\' has successfully been deleted', { timeout: 5000 });
102+
expect(clusterDownMessage).not.toBeNull();
103+
});
104+
105+
await runLastCell(page, cellCount, '(<CodeFlareClusterStatus.UNKNOWN: 6>, False)');
62106
});
63107
});
108+
109+
async function waitForWidget(page, cellIndex: number, widgetSelector: string, timeout = 5000) {
110+
const widgetCell = await page.notebook.getCellOutput(cellIndex);
111+
112+
if (widgetCell) {
113+
await widgetCell.waitForSelector(widgetSelector, { timeout });
114+
}
115+
}
116+
117+
async function interactWithWidget(page, cellIndex: number, widgetSelector: string, action: (widget) => Promise<void>) {
118+
const widgetCell = await page.notebook.getCellOutput(cellIndex);
119+
120+
if (widgetCell) {
121+
const widget = await widgetCell.$(widgetSelector);
122+
if (widget) {
123+
await action(widget);
124+
}
125+
}
126+
}
127+
128+
async function runLastCell(page, cellCount, expectedMessage) {
129+
const runSuccess = await page.notebook.runCell(cellCount - 1); expect(runSuccess).toBe(true);
130+
const lastCellOutput = await page.notebook.getCellOutput(cellCount - 1);
131+
const newOutput = await lastCellOutput.evaluate((output) => output.textContent);
132+
133+
if (expectedMessage) {
134+
expect(newOutput).toContain(expectedMessage);
135+
}
136+
137+
return lastCellOutput;
138+
}

0 commit comments

Comments
 (0)