Skip to content

Commit 3e07369

Browse files
committed
Test to cover the widgets functionality
1 parent 9d5df26 commit 3e07369

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

0 commit comments

Comments
 (0)