@@ -6,6 +6,7 @@ import { rest } from "msw";
6
6
import {
7
7
MockTemplate ,
8
8
MockWorkspace ,
9
+ MockFailedWorkspace ,
9
10
MockWorkspaceBuild ,
10
11
MockStoppedWorkspace ,
11
12
MockStartingWorkspace ,
@@ -22,7 +23,7 @@ import { renderWithAuth } from "testHelpers/renderHelpers";
22
23
import { server } from "testHelpers/server" ;
23
24
import { WorkspacePage } from "./WorkspacePage" ;
24
25
25
- // It renders the workspace page and waits for it be loaded
26
+ // Renders the workspace page and waits for it be loaded
26
27
const renderWorkspacePage = async ( workspace : Workspace ) => {
27
28
jest . spyOn ( api , "getWorkspaceByOwnerAndName" ) . mockResolvedValue ( workspace ) ;
28
29
jest . spyOn ( api , "getTemplate" ) . mockResolvedValueOnce ( MockTemplate ) ;
@@ -369,4 +370,91 @@ describe("WorkspacePage", () => {
369
370
} ) ;
370
371
} ) ;
371
372
} ) ;
373
+
374
+ // Tried to get these wired up via describe.each to reduce repetition, but the
375
+ // syntax just got too convoluted because of the variance in what arguments
376
+ // each function gets called with
377
+ describe ( "Retrying failed workspaces" , ( ) => {
378
+ const retryButtonRe = / ^ R e t r y $ / i;
379
+ const retryDebugButtonRe = / ^ R e t r y \( D e b u g \) $ / i;
380
+
381
+ describe ( "Retries a failed 'Start' transition" , ( ) => {
382
+ const mockStart = jest . spyOn ( api , "startWorkspace" ) ;
383
+ const failedStart : Workspace = {
384
+ ...MockFailedWorkspace ,
385
+ latest_build : {
386
+ ...MockFailedWorkspace . latest_build ,
387
+ transition : "start" ,
388
+ } ,
389
+ } ;
390
+
391
+ test ( "Retry with no debug" , async ( ) => {
392
+ await testButton ( failedStart , retryButtonRe , mockStart ) ;
393
+
394
+ expect ( mockStart ) . toBeCalledWith (
395
+ failedStart . id ,
396
+ failedStart . latest_build . template_version_id ,
397
+ undefined ,
398
+ undefined ,
399
+ ) ;
400
+ } ) ;
401
+
402
+ test ( "Retry with debug logs" , async ( ) => {
403
+ await testButton ( failedStart , retryDebugButtonRe , mockStart ) ;
404
+
405
+ expect ( mockStart ) . toBeCalledWith (
406
+ failedStart . id ,
407
+ failedStart . latest_build . template_version_id ,
408
+ "debug" ,
409
+ undefined ,
410
+ ) ;
411
+ } ) ;
412
+ } ) ;
413
+
414
+ describe ( "Retries a failed 'Stop' transition" , ( ) => {
415
+ const mockStop = jest . spyOn ( api , "stopWorkspace" ) ;
416
+ const failedStop : Workspace = {
417
+ ...MockFailedWorkspace ,
418
+ latest_build : {
419
+ ...MockFailedWorkspace . latest_build ,
420
+ transition : "stop" ,
421
+ } ,
422
+ } ;
423
+
424
+ test ( "Retry with no debug" , async ( ) => {
425
+ await testButton ( failedStop , retryButtonRe , mockStop ) ;
426
+ expect ( mockStop ) . toBeCalledWith ( failedStop . id , undefined ) ;
427
+ } ) ;
428
+
429
+ test ( "Retry with debug logs" , async ( ) => {
430
+ await testButton ( failedStop , retryDebugButtonRe , mockStop ) ;
431
+ expect ( mockStop ) . toBeCalledWith ( failedStop . id , "debug" ) ;
432
+ } ) ;
433
+ } ) ;
434
+
435
+ describe ( "Retries a failed 'Delete' transition" , ( ) => {
436
+ const mockDelete = jest . spyOn ( api , "deleteWorkspace" ) ;
437
+ const failedDelete : Workspace = {
438
+ ...MockFailedWorkspace ,
439
+ latest_build : {
440
+ ...MockFailedWorkspace . latest_build ,
441
+ transition : "delete" ,
442
+ } ,
443
+ } ;
444
+
445
+ test ( "Retry with no debug" , async ( ) => {
446
+ await testButton ( failedDelete , retryButtonRe , mockDelete ) ;
447
+ expect ( mockDelete ) . toBeCalledWith ( failedDelete . id , {
448
+ logLevel : undefined ,
449
+ } ) ;
450
+ } ) ;
451
+
452
+ test ( "Retry with debug logs" , async ( ) => {
453
+ await testButton ( failedDelete , retryDebugButtonRe , mockDelete ) ;
454
+ expect ( mockDelete ) . toBeCalledWith ( failedDelete . id , {
455
+ logLevel : "debug" ,
456
+ } ) ;
457
+ } ) ;
458
+ } ) ;
459
+ } ) ;
372
460
} ) ;
0 commit comments