@@ -173,52 +173,79 @@ describe("WorkspacePage", () => {
173
173
174
174
expect ( cancelWorkspaceMock ) . toBeCalled ( )
175
175
} )
176
- it ( "requests a template when the user presses Update" , async ( ) => {
177
- const getTemplateMock = jest
178
- . spyOn ( api , "getTemplate" )
179
- . mockResolvedValueOnce ( MockTemplate )
180
- server . use (
181
- rest . get (
182
- `/api/v2/users/:userId/workspace/:workspaceName` ,
183
- ( req , res , ctx ) => {
184
- return res ( ctx . status ( 200 ) , ctx . json ( MockOutdatedWorkspace ) )
185
- } ,
186
- ) ,
187
- )
188
176
189
- await renderWorkspacePage ( )
190
- const buttonText = t ( "actionButton.update" , { ns : "workspacePage" } )
191
- const button = await screen . findByText ( buttonText , { exact : true } )
192
- await userEvent . setup ( ) . click ( button )
177
+ it ( "requests an update when the user presses Update" , async ( ) => {
178
+ jest
179
+ . spyOn ( api , "getWorkspaceByOwnerAndName" )
180
+ . mockResolvedValueOnce ( MockOutdatedWorkspace )
181
+ const updateWorkspaceMock = jest
182
+ . spyOn ( api , "updateWorkspace" )
183
+ . mockResolvedValueOnce ( MockWorkspaceBuild )
193
184
194
- // getTemplate is called twice: once when the machine starts, and once after the user requests to update
195
- expect ( getTemplateMock ) . toBeCalledTimes ( 2 )
185
+ await testButton (
186
+ t ( "actionButton.update" , { ns : "workspacePage" } ) ,
187
+ updateWorkspaceMock ,
188
+ )
196
189
} )
197
- it ( "after an update postWorkspaceBuild is called with the latest template active version id" , async ( ) => {
198
- jest . spyOn ( api , "getTemplate" ) . mockResolvedValueOnce ( MockTemplate ) // active_version_id = "test-template-version"
199
- jest . spyOn ( api , "startWorkspace" ) . mockResolvedValueOnce ( {
200
- ...MockWorkspaceBuild ,
201
- } )
202
190
203
- server . use (
204
- rest . get (
205
- `/api/v2/users/:userId/workspace/:workspaceName` ,
206
- ( req , res , ctx ) => {
207
- return res ( ctx . status ( 200 ) , ctx . json ( MockOutdatedWorkspace ) )
208
- } ,
209
- ) ,
191
+ it ( "updates the parameters when they are missing during update" , async ( ) => {
192
+ // Setup mocks
193
+ const user = userEvent . setup ( )
194
+ jest
195
+ . spyOn ( api , "getWorkspaceByOwnerAndName" )
196
+ . mockResolvedValueOnce ( MockOutdatedWorkspace )
197
+ const updateWorkspaceSpy = jest
198
+ . spyOn ( api , "updateWorkspace" )
199
+ . mockRejectedValueOnce (
200
+ new api . MissingBuildParameters ( [
201
+ MockTemplateVersionParameter1 ,
202
+ MockTemplateVersionParameter2 ,
203
+ ] ) ,
204
+ )
205
+ // Render page and wait for it to be loaded
206
+ renderWithAuth ( < WorkspacePage /> , {
207
+ route : `/@${ MockWorkspace . owner_name } /${ MockWorkspace . name } ` ,
208
+ path : "/@:username/:workspace" ,
209
+ } )
210
+ await waitForLoaderToBeRemoved ( )
211
+ // Click on the update button
212
+ const workspaceActions = screen . getByTestId ( "workspace-actions" )
213
+ await user . click (
214
+ within ( workspaceActions ) . getByRole ( "button" , { name : "Update" } ) ,
210
215
)
211
- await renderWorkspacePage ( )
212
- const buttonText = t ( "actionButton.update" , { ns : "workspacePage" } )
213
- const button = await screen . findByText ( buttonText , { exact : true } )
214
- await userEvent . setup ( ) . click ( button )
215
-
216
- await waitFor ( ( ) =>
217
- expect ( api . startWorkspace ) . toBeCalledWith (
218
- "test-outdated-workspace" ,
219
- "test-template-version" ,
220
- ) ,
216
+ await waitFor ( ( ) => {
217
+ expect ( api . updateWorkspace ) . toBeCalled ( )
218
+ // We want to clear this mock to use it later
219
+ updateWorkspaceSpy . mockClear ( )
220
+ } )
221
+ // Fill the parameters and send the form
222
+ const dialog = await screen . findByTestId ( "dialog" )
223
+ const firstParameterInput = within ( dialog ) . getByLabelText (
224
+ MockTemplateVersionParameter1 . name ,
225
+ { exact : false } ,
221
226
)
227
+ await user . clear ( firstParameterInput )
228
+ await user . type ( firstParameterInput , "some-value" )
229
+ const secondParameterInput = within ( dialog ) . getByLabelText (
230
+ MockTemplateVersionParameter2 . name ,
231
+ { exact : false } ,
232
+ )
233
+ await user . clear ( secondParameterInput )
234
+ await user . type ( secondParameterInput , "2" )
235
+ await user . click ( within ( dialog ) . getByRole ( "button" , { name : "Update" } ) )
236
+ // Check if the update was called using the values from the form
237
+ await waitFor ( ( ) => {
238
+ expect ( api . updateWorkspace ) . toBeCalledWith ( MockOutdatedWorkspace , [
239
+ {
240
+ name : MockTemplateVersionParameter1 . name ,
241
+ value : "some-value" ,
242
+ } ,
243
+ {
244
+ name : MockTemplateVersionParameter2 . name ,
245
+ value : "2" ,
246
+ } ,
247
+ ] )
248
+ } )
222
249
} )
223
250
224
251
it ( "shows the Stopping status when the workspace is stopping" , async ( ) => {
@@ -227,126 +254,72 @@ describe("WorkspacePage", () => {
227
254
t ( "workspaceStatus.stopping" , { ns : "common" } ) ,
228
255
)
229
256
} )
257
+
230
258
it ( "shows the Stopped status when the workspace is stopped" , async ( ) => {
231
259
await testStatus (
232
260
MockStoppedWorkspace ,
233
261
t ( "workspaceStatus.stopped" , { ns : "common" } ) ,
234
262
)
235
263
} )
264
+
236
265
it ( "shows the Building status when the workspace is starting" , async ( ) => {
237
266
await testStatus (
238
267
MockStartingWorkspace ,
239
268
t ( "workspaceStatus.starting" , { ns : "common" } ) ,
240
269
)
241
270
} )
271
+
242
272
it ( "shows the Running status when the workspace is running" , async ( ) => {
243
273
await testStatus (
244
274
MockWorkspace ,
245
275
t ( "workspaceStatus.running" , { ns : "common" } ) ,
246
276
)
247
277
} )
278
+
248
279
it ( "shows the Failed status when the workspace is failed or canceled" , async ( ) => {
249
280
await testStatus (
250
281
MockFailedWorkspace ,
251
282
t ( "workspaceStatus.failed" , { ns : "common" } ) ,
252
283
)
253
284
} )
285
+
254
286
it ( "shows the Canceling status when the workspace is canceling" , async ( ) => {
255
287
await testStatus (
256
288
MockCancelingWorkspace ,
257
289
t ( "workspaceStatus.canceling" , { ns : "common" } ) ,
258
290
)
259
291
} )
292
+
260
293
it ( "shows the Canceled status when the workspace is canceling" , async ( ) => {
261
294
await testStatus (
262
295
MockCanceledWorkspace ,
263
296
t ( "workspaceStatus.canceled" , { ns : "common" } ) ,
264
297
)
265
298
} )
299
+
266
300
it ( "shows the Deleting status when the workspace is deleting" , async ( ) => {
267
301
await testStatus (
268
302
MockDeletingWorkspace ,
269
303
t ( "workspaceStatus.deleting" , { ns : "common" } ) ,
270
304
)
271
305
} )
306
+
272
307
it ( "shows the Deleted status when the workspace is deleted" , async ( ) => {
273
308
await testStatus (
274
309
MockDeletedWorkspace ,
275
310
t ( "workspaceStatus.deleted" , { ns : "common" } ) ,
276
311
)
277
312
} )
278
313
279
- describe ( "Timeline" , ( ) => {
280
- it ( "shows the timeline build" , async ( ) => {
281
- await renderWorkspacePage ( )
282
- const table = await screen . findByTestId ( "builds-table" )
283
-
284
- // Wait for the results to be loaded
285
- await waitFor ( async ( ) => {
286
- const rows = table . querySelectorAll ( "tbody > tr" )
287
- // Added +1 because of the date row
288
- expect ( rows ) . toHaveLength ( MockBuilds . length + 1 )
289
- } )
290
- } )
291
- } )
314
+ it ( "shows the timeline build" , async ( ) => {
315
+ await renderWorkspacePage ( )
316
+ const table = await screen . findByTestId ( "builds-table" )
292
317
293
- it ( "Workspace update when having new parameters on the template version" , async ( ) => {
294
- // Setup mocks
295
- const user = userEvent . setup ( )
296
- jest
297
- . spyOn ( api , "getWorkspaceByOwnerAndName" )
298
- . mockResolvedValueOnce ( MockOutdatedWorkspace )
299
- const updateWorkspaceSpy = jest
300
- . spyOn ( api , "updateWorkspace" )
301
- . mockRejectedValueOnce (
302
- new api . MissingBuildParameters ( [
303
- MockTemplateVersionParameter1 ,
304
- MockTemplateVersionParameter2 ,
305
- ] ) ,
306
- )
307
- // Render page and wait for it to be loaded
308
- renderWithAuth ( < WorkspacePage /> , {
309
- route : `/@${ MockWorkspace . owner_name } /${ MockWorkspace . name } ` ,
310
- path : "/@:username/:workspace" ,
311
- } )
312
- await waitForLoaderToBeRemoved ( )
313
- // Click on the update button
314
- const workspaceActions = screen . getByTestId ( "workspace-actions" )
315
- await user . click (
316
- within ( workspaceActions ) . getByRole ( "button" , { name : "Update" } ) ,
317
- )
318
- await waitFor ( ( ) => {
319
- expect ( api . updateWorkspace ) . toBeCalled ( )
320
- // We want to clear this mock to use it later
321
- updateWorkspaceSpy . mockClear ( )
322
- } )
323
- // Fill the parameters and send the form
324
- const dialog = await screen . findByTestId ( "dialog" )
325
- const firstParameterInput = within ( dialog ) . getByLabelText (
326
- MockTemplateVersionParameter1 . name ,
327
- { exact : false } ,
328
- )
329
- await user . clear ( firstParameterInput )
330
- await user . type ( firstParameterInput , "some-value" )
331
- const secondParameterInput = within ( dialog ) . getByLabelText (
332
- MockTemplateVersionParameter2 . name ,
333
- { exact : false } ,
334
- )
335
- await user . clear ( secondParameterInput )
336
- await user . type ( secondParameterInput , "2" )
337
- await user . click ( within ( dialog ) . getByRole ( "button" , { name : "Update" } ) )
338
- // Check if the update was called using the values from the form
339
- await waitFor ( ( ) => {
340
- expect ( api . updateWorkspace ) . toBeCalledWith ( MockOutdatedWorkspace , [
341
- {
342
- name : MockTemplateVersionParameter1 . name ,
343
- value : "some-value" ,
344
- } ,
345
- {
346
- name : MockTemplateVersionParameter2 . name ,
347
- value : "2" ,
348
- } ,
349
- ] )
318
+ // Wait for the results to be loaded
319
+ await waitFor ( async ( ) => {
320
+ const rows = table . querySelectorAll ( "tbody > tr" )
321
+ // Added +1 because of the date row
322
+ expect ( rows ) . toHaveLength ( MockBuilds . length + 1 )
350
323
} )
351
324
} )
352
325
} )
0 commit comments