@@ -35,6 +35,10 @@ const { t } = i18next
35
35
const renderWorkspacePage = async ( ) => {
36
36
jest . spyOn ( api , "getTemplate" ) . mockResolvedValueOnce ( MockTemplate )
37
37
jest . spyOn ( api , "getTemplateVersionRichParameters" ) . mockResolvedValueOnce ( [ ] )
38
+ jest . spyOn ( api , "watchStartupLogs" ) . mockImplementation ( ( _ , options ) => {
39
+ options . onDone ( )
40
+ return new WebSocket ( "" )
41
+ } )
38
42
renderWithAuth ( < WorkspacePage /> , {
39
43
route : `/@${ MockWorkspace . owner_name } /${ MockWorkspace . name } ` ,
40
44
path : "/@:username/:workspace" ,
@@ -188,22 +192,32 @@ describe("WorkspacePage", () => {
188
192
} )
189
193
190
194
it ( "requests an update when the user presses Update" , async ( ) => {
195
+ // Mocks
191
196
jest
192
197
. spyOn ( api , "getWorkspaceByOwnerAndName" )
193
198
. mockResolvedValueOnce ( MockOutdatedWorkspace )
199
+
194
200
const updateWorkspaceMock = jest
195
201
. spyOn ( api , "updateWorkspace" )
196
202
. mockResolvedValueOnce ( MockWorkspaceBuild )
197
203
198
- await testButton (
199
- t ( "actionButton.update" , { ns : "workspacePage" } ) ,
200
- updateWorkspaceMock ,
201
- )
204
+ // Render
205
+ await renderWorkspacePage ( )
206
+
207
+ // Actions
208
+ const user = userEvent . setup ( )
209
+ await user . click ( screen . getByTestId ( "workspace-update-button" ) )
210
+ const confirmButton = await screen . findByTestId ( "confirm-button" )
211
+ await user . click ( confirmButton )
212
+
213
+ // Assertions
214
+ await waitFor ( ( ) => {
215
+ expect ( updateWorkspaceMock ) . toBeCalled ( )
216
+ } )
202
217
} )
203
218
204
219
it ( "updates the parameters when they are missing during update" , async ( ) => {
205
- // Setup mocks
206
- const user = userEvent . setup ( )
220
+ // Mocks
207
221
jest
208
222
. spyOn ( api , "getWorkspaceByOwnerAndName" )
209
223
. mockResolvedValueOnce ( MockOutdatedWorkspace )
@@ -215,23 +229,24 @@ describe("WorkspacePage", () => {
215
229
MockTemplateVersionParameter2 ,
216
230
] ) ,
217
231
)
218
- // Render page and wait for it to be loaded
219
- renderWithAuth ( < WorkspacePage /> , {
220
- route : `/@ ${ MockWorkspace . owner_name } / ${ MockWorkspace . name } ` ,
221
- path : "/@:username/:workspace" ,
222
- } )
223
- await waitForLoaderToBeRemoved ( )
224
- // Click on the update button
225
- const workspaceActions = screen . getByTestId ( "workspace-actions ")
226
- await user . click (
227
- within ( workspaceActions ) . getByRole ( "button" , { name : "Update" } ) ,
228
- )
232
+
233
+ // Render
234
+ await renderWorkspacePage ( )
235
+
236
+ // Actions
237
+ const user = userEvent . setup ( )
238
+ await user . click ( screen . getByTestId ( "workspace- update- button" ) )
239
+ const confirmButton = await screen . findByTestId ( "confirm-button ")
240
+ await user . click ( confirmButton )
241
+
242
+ // The update was called
229
243
await waitFor ( ( ) => {
230
244
expect ( api . updateWorkspace ) . toBeCalled ( )
231
- // We want to clear this mock to use it later
232
245
updateWorkspaceSpy . mockClear ( )
233
246
} )
234
- // Fill the parameters and send the form
247
+
248
+ // After trying to update, a new dialog asking for missed parameters should
249
+ // be displayed and filled
235
250
const dialog = await screen . findByTestId ( "dialog" )
236
251
const firstParameterInput = within ( dialog ) . getByLabelText (
237
252
MockTemplateVersionParameter1 . name ,
@@ -246,6 +261,7 @@ describe("WorkspacePage", () => {
246
261
await user . clear ( secondParameterInput )
247
262
await user . type ( secondParameterInput , "2" )
248
263
await user . click ( within ( dialog ) . getByRole ( "button" , { name : "Update" } ) )
264
+
249
265
// Check if the update was called using the values from the form
250
266
await waitFor ( ( ) => {
251
267
expect ( api . updateWorkspace ) . toBeCalledWith ( MockOutdatedWorkspace , [
0 commit comments