@@ -16,8 +16,6 @@ import { test } from "@jupyterlab/galata";
16
16
import { expect } from "@playwright/test" ;
17
17
import * as path from "path" ;
18
18
19
- test . setTimeout ( 460000 ) ;
20
-
21
19
test . describe ( "Visual Regression" , ( ) => {
22
20
test . beforeEach ( async ( { page, tmpPath } ) => {
23
21
await page . contents . uploadDirectory (
@@ -27,7 +25,7 @@ test.describe("Visual Regression", () => {
27
25
await page . filebrowser . openDirectory ( tmpPath ) ;
28
26
} ) ;
29
27
30
- test ( "Run notebook and capture cell outputs" , async ( {
28
+ test ( "Run notebook, capture cell outputs, and test widgets " , async ( {
31
29
page,
32
30
tmpPath,
33
31
} ) => {
@@ -60,5 +58,80 @@ test.describe("Visual Regression", () => {
60
58
continue ;
61
59
}
62
60
}
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)' ) ;
63
105
} ) ;
64
106
} ) ;
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