1
1
import { screen } from "@testing-library/react"
2
+ import { rest } from "msw"
2
3
import React from "react"
3
- import { MockTemplate , MockWorkspace , renderWithAuth } from "../../testHelpers"
4
+ import { MockFailedWorkspace , MockStoppedWorkspace , MockTemplate , MockWorkspace , renderWithAuth } from "../../testHelpers"
5
+ import { server } from "../../testHelpers/server"
4
6
import { WorkspacePage } from "./WorkspacePage"
5
7
6
8
describe ( "Workspace Page" , ( ) => {
@@ -11,4 +13,47 @@ describe("Workspace Page", () => {
11
13
expect ( workspaceName ) . toBeDefined ( )
12
14
expect ( templateName ) . toBeDefined ( )
13
15
} )
16
+ it ( "shows the status of the workspace" , async ( ) => {
17
+ renderWithAuth ( < WorkspacePage /> , { route : `/workspaces/${ MockWorkspace . id } ` , path : "/workspaces/:workspace" } )
18
+ const status = await screen . findByRole ( "status" )
19
+ expect ( status ) . toHaveTextContent ( "Running" )
20
+ } )
21
+ it ( "stops the workspace when the user presses Stop" , async ( ) => {
22
+ renderWithAuth ( < WorkspacePage /> , { route : `/workspaces/${ MockWorkspace . id } ` , path : "/workspaces/:workspace" } )
23
+ const status = await screen . findByText ( "Running" )
24
+ expect ( status ) . toBeDefined ( )
25
+ const stopButton = await screen . findByText ( "Stop" )
26
+ stopButton . click ( )
27
+ const laterStatus = await screen . findByText ( "Stopping" )
28
+ expect ( laterStatus ) . toBeDefined ( )
29
+ } )
30
+ it ( "starts the workspace when the user presses Start" , async ( ) => {
31
+ server . use (
32
+ rest . get ( `/api/v2/workspaces/${ MockWorkspace . id } ` , ( req , res , ctx ) => {
33
+ return res ( ctx . status ( 200 ) , ctx . json ( MockStoppedWorkspace ) )
34
+ } ) ,
35
+ )
36
+ renderWithAuth ( < WorkspacePage /> , { route : `/workspaces/${ MockWorkspace . id } ` , path : "/workspaces/:workspace" } )
37
+ const startButton = await screen . findByText ( "Start" )
38
+ const status = await screen . findByText ( "Stopped" )
39
+ expect ( status ) . toBeDefined ( )
40
+ startButton . click ( )
41
+ const laterStatus = await screen . findByText ( "Building" )
42
+ expect ( laterStatus ) . toBeDefined ( )
43
+ } )
44
+ it ( "retries starting the workspace when the user presses Retry" , async ( ) => {
45
+ // MockFailedWorkspace.latest_build.transition is start so Retry will attempt to start
46
+ renderWithAuth ( < WorkspacePage /> , { route : `/workspaces/${ MockWorkspace . id } ` , path : "/workspaces/:workspace" } )
47
+ server . use (
48
+ rest . get ( `/api/v2/workspaces/${ MockWorkspace . id } ` , ( req , res , ctx ) => {
49
+ return res ( ctx . status ( 200 ) , ctx . json ( MockFailedWorkspace ) )
50
+ } ) ,
51
+ )
52
+ const status = await screen . findByText ( "Build Failed" )
53
+ expect ( status ) . toBeDefined ( )
54
+ const retryButton = await screen . findByText ( "Retry" )
55
+ retryButton . click ( )
56
+ const laterStatus = await screen . findByText ( "Building" )
57
+ expect ( laterStatus ) . toBeDefined ( )
58
+ } )
14
59
} )
0 commit comments