1
- import { fireEvent , screen , waitFor , within } from "@testing-library/react"
1
+ import { screen , waitFor , within } from "@testing-library/react"
2
2
import userEvent from "@testing-library/user-event"
3
3
import EventSourceMock from "eventsourcemock"
4
4
import i18next from "i18next"
@@ -48,9 +48,11 @@ const renderWorkspacePage = async () => {
48
48
* workspaceStatus was calculated correctly.
49
49
*/
50
50
const testButton = async ( label : string , actionMock : jest . SpyInstance ) => {
51
+ const user = userEvent . setup ( )
52
+
51
53
await renderWorkspacePage ( )
52
54
const button = await screen . findByRole ( "button" , { name : label } )
53
- fireEvent . click ( button )
55
+ await user . click ( button )
54
56
expect ( actionMock ) . toBeCalled ( )
55
57
}
56
58
@@ -65,7 +67,7 @@ const testStatus = async (ws: Workspace, label: string) => {
65
67
)
66
68
await renderWorkspacePage ( )
67
69
const header = screen . getByTestId ( "header" )
68
- const status = await within ( header ) . findByRole ( "status" )
70
+ const status = within ( header ) . getByRole ( "status" )
69
71
expect ( status ) . toHaveTextContent ( label )
70
72
}
71
73
@@ -88,6 +90,7 @@ afterAll(() => {
88
90
describe ( "WorkspacePage" , ( ) => {
89
91
it ( "requests a delete job when the user presses Delete and confirms" , async ( ) => {
90
92
const user = userEvent . setup ( )
93
+
91
94
const deleteWorkspaceMock = jest
92
95
. spyOn ( api , "deleteWorkspace" )
93
96
. mockResolvedValueOnce ( MockWorkspaceBuild )
@@ -160,7 +163,7 @@ describe("WorkspacePage", () => {
160
163
name : "cancel action" ,
161
164
} )
162
165
163
- fireEvent . click ( cancelButton )
166
+ await userEvent . setup ( ) . click ( cancelButton )
164
167
165
168
expect ( cancelWorkspaceMock ) . toBeCalled ( )
166
169
} )
@@ -180,7 +183,7 @@ describe("WorkspacePage", () => {
180
183
await renderWorkspacePage ( )
181
184
const buttonText = t ( "actionButton.update" , { ns : "workspacePage" } )
182
185
const button = await screen . findByText ( buttonText , { exact : true } )
183
- fireEvent . click ( button )
186
+ await userEvent . setup ( ) . click ( button )
184
187
185
188
// getTemplate is called twice: once when the machine starts, and once after the user requests to update
186
189
expect ( getTemplateMock ) . toBeCalledTimes ( 2 )
@@ -202,7 +205,7 @@ describe("WorkspacePage", () => {
202
205
await renderWorkspacePage ( )
203
206
const buttonText = t ( "actionButton.update" , { ns : "workspacePage" } )
204
207
const button = await screen . findByText ( buttonText , { exact : true } )
205
- fireEvent . click ( button )
208
+ await userEvent . setup ( ) . click ( button )
206
209
207
210
await waitFor ( ( ) =>
208
211
expect ( api . startWorkspace ) . toBeCalledWith (
@@ -211,6 +214,7 @@ describe("WorkspacePage", () => {
211
214
) ,
212
215
)
213
216
} )
217
+
214
218
it ( "shows the Stopping status when the workspace is stopping" , async ( ) => {
215
219
await testStatus (
216
220
MockStoppingWorkspace ,
0 commit comments