@@ -16,8 +16,6 @@ import { test } from "@jupyterlab/galata";
1616import { expect } from "@playwright/test" ;
1717import * as path from "path" ;
1818
19- test . setTimeout ( 460000 ) ;
20-
2119test . describe ( "Visual Regression" , ( ) => {
2220 test . beforeEach ( async ( { page, tmpPath } ) => {
2321 await page . contents . uploadDirectory (
@@ -27,7 +25,7 @@ test.describe("Visual Regression", () => {
2725 await page . filebrowser . openDirectory ( tmpPath ) ;
2826 } ) ;
2927
30- test ( "Run notebook and capture cell outputs" , async ( {
28+ test ( "Run notebook, capture cell outputs, and test widgets " , async ( {
3129 page,
3230 tmpPath,
3331 } ) => {
@@ -60,5 +58,80 @@ test.describe("Visual Regression", () => {
6058 continue ;
6159 }
6260 }
61+
62+ const widgetCellIndex = 3 ;
63+
64+ await waitForWidget ( page , widgetCellIndex , 'input[type="checkbox"]' ) ;
65+ await waitForWidget ( page , widgetCellIndex , 'button:has-text("Cluster Down")' ) ;
66+ await waitForWidget ( page , widgetCellIndex , 'button:has-text("Cluster Up")' ) ;
67+
68+ await interactWithWidget ( page , widgetCellIndex , 'input[type="checkbox"]' , async ( checkbox ) => {
69+ await checkbox . click ( ) ;
70+ const isChecked = await checkbox . isChecked ( ) ;
71+ expect ( isChecked ) . toBe ( true ) ;
72+ } ) ;
73+
74+ await interactWithWidget ( page , widgetCellIndex , 'button:has-text("Cluster Down")' , async ( button ) => {
75+ await button . click ( ) ;
76+ const clusterDownMessage = await page . waitForSelector ( 'text=No instances found, nothing to be done.' , { timeout : 5000 } ) ;
77+ expect ( clusterDownMessage ) . not . toBeNull ( ) ;
78+ } ) ;
79+
80+ await interactWithWidget ( page , widgetCellIndex , 'button:has-text("Cluster Up")' , async ( button ) => {
81+ await button . click ( ) ;
82+
83+ const successMessage = await page . waitForSelector ( 'text=Ray Cluster: \'raytest\' has successfully been created' , { timeout : 10000 } ) ;
84+ expect ( successMessage ) . not . toBeNull ( ) ;
85+
86+ const resourcesMessage = await page . waitForSelector ( 'text=Waiting for requested resources to be set up...' ) ;
87+ expect ( resourcesMessage ) . not . toBeNull ( ) ;
88+
89+ const upAndRunningMessage = await page . waitForSelector ( 'text=Requested cluster is up and running!' ) ;
90+ expect ( upAndRunningMessage ) . not . toBeNull ( ) ;
91+
92+ const dashboardReadyMessage = await page . waitForSelector ( 'text=Dashboard is ready!' ) ;
93+ expect ( dashboardReadyMessage ) . not . toBeNull ( ) ;
94+ } ) ;
95+
96+ await runPreviousCell ( page , cellCount , '(<CodeFlareClusterStatus.READY: 1>, True)' ) ;
97+
98+ await interactWithWidget ( page , widgetCellIndex , 'button:has-text("Cluster Down")' , async ( button ) => {
99+ await button . click ( ) ;
100+ const clusterDownMessage = await page . waitForSelector ( 'text=Ray Cluster: \'raytest\' has successfully been deleted' , { timeout : 5000 } ) ;
101+ expect ( clusterDownMessage ) . not . toBeNull ( ) ;
102+ } ) ;
103+
104+ await runPreviousCell ( page , cellCount , '(<CodeFlareClusterStatus.UNKNOWN: 6>, False)' ) ;
63105 } ) ;
64106} ) ;
107+
108+ async function waitForWidget ( page , cellIndex : number , widgetSelector : string , timeout = 5000 ) {
109+ const widgetCell = await page . notebook . getCellOutput ( cellIndex ) ;
110+
111+ if ( widgetCell ) {
112+ await widgetCell . waitForSelector ( widgetSelector , { timeout } ) ;
113+ }
114+ }
115+
116+ async function interactWithWidget ( page , cellIndex : number , widgetSelector : string , action : ( widget ) => Promise < void > ) {
117+ const widgetCell = await page . notebook . getCellOutput ( cellIndex ) ;
118+
119+ if ( widgetCell ) {
120+ const widget = await widgetCell . $ ( widgetSelector ) ;
121+ if ( widget ) {
122+ await action ( widget ) ;
123+ }
124+ }
125+ }
126+
127+ async function runPreviousCell ( page , cellCount , expectedMessage ) {
128+ const runSuccess = await page . notebook . runCell ( cellCount - 1 ) ; expect ( runSuccess ) . toBe ( true ) ;
129+ const lastCellOutput = await page . notebook . getCellOutput ( cellCount - 1 ) ;
130+ const newOutput = await lastCellOutput . evaluate ( ( output ) => output . textContent ) ;
131+
132+ if ( expectedMessage ) {
133+ expect ( newOutput ) . toContain ( expectedMessage ) ;
134+ }
135+
136+ return lastCellOutput ;
137+ }
0 commit comments