Skip to content

Commit 1555627

Browse files
committed
fix: update all integration tests
1 parent 527104b commit 1555627

File tree

1 file changed

+41
-74
lines changed

1 file changed

+41
-74
lines changed

site/src/pages/WorkspacesPage/WorkspacesPage.test.tsx

Lines changed: 41 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,11 @@ describe("WorkspacesPage", () => {
123123
{ ...MockOutdatedWorkspace, id: "3" },
124124
// Out of date but running; should issue warning
125125
{
126-
...MockOutdatedWorkspace, id: "4",
126+
...MockOutdatedWorkspace,
127+
id: "4",
127128
latest_build: {
128129
...MockOutdatedWorkspace.latest_build,
129-
status: "running"
130+
status: "running",
130131
},
131132
},
132133
];
@@ -149,12 +150,16 @@ describe("WorkspacesPage", () => {
149150
});
150151
await user.click(dropdownItem);
151152

152-
const modal = await screen.findByRole("dialog", { name: /Review Updates/i });
153+
const modal = await screen.findByRole("dialog", {
154+
name: /Review Updates/i,
155+
});
153156
const confirmCheckbox = within(modal).getByRole("checkbox", {
154157
name: /I acknowledge these consequences\./,
155158
});
156159
await user.click(confirmCheckbox);
157-
const updateModalButton = within(modal).getByRole("button", {name: /Update/});
160+
const updateModalButton = within(modal).getByRole("button", {
161+
name: /Update/,
162+
});
158163
await user.click(updateModalButton);
159164

160165
// `workspaces[0]` was up-to-date, and running
@@ -164,15 +169,16 @@ describe("WorkspacesPage", () => {
164169
expect(updateWorkspace).toHaveBeenCalledWith(workspaces[3], [], false);
165170
});
166171

167-
it("warns about and updates running workspaces", async () => {
168-
const workspaces = [
172+
it("lets user update a running workspace (after user goes through warning)", async () => {
173+
const workspaces: readonly Workspace[] = [
169174
{ ...MockRunningOutdatedWorkspace, id: "1" },
170175
{ ...MockOutdatedWorkspace, id: "2" },
171176
{ ...MockOutdatedWorkspace, id: "3" },
172177
];
173178
jest
174179
.spyOn(API, "getWorkspaces")
175180
.mockResolvedValue({ workspaces, count: workspaces.length });
181+
176182
const updateWorkspace = jest.spyOn(API, "updateWorkspace");
177183
const user = userEvent.setup();
178184
renderWithAuth(<WorkspacesPage />);
@@ -183,20 +189,24 @@ describe("WorkspacesPage", () => {
183189
}
184190

185191
await user.click(screen.getByRole("button", { name: /bulk actions/i }));
186-
const updateButton = await screen.findByTestId("bulk-action-update");
187-
await user.click(updateButton);
188-
189-
// Two clicks: 1 running workspace, no dormant workspaces warning.
190-
const confirmButton = await screen.findByTestId("confirm-button");
191-
const dialog = await screen.findByRole("dialog");
192-
expect(dialog).toHaveTextContent(/1 running workspace/i);
193-
await user.click(confirmButton);
194-
expect(dialog).toHaveTextContent(/used by/i);
195-
await user.click(confirmButton);
196-
197-
await waitFor(() => {
198-
expect(updateWorkspace).toHaveBeenCalledTimes(3);
192+
const dropdownItem = await screen.findByRole("menuitem", {
193+
name: /Update/,
194+
});
195+
await user.click(dropdownItem);
196+
197+
const modal = await screen.findByRole("dialog", {
198+
name: /Review Updates/i,
199+
});
200+
const confirmCheckbox = within(modal).getByRole("checkbox", {
201+
name: /I acknowledge these consequences\./,
202+
});
203+
await user.click(confirmCheckbox);
204+
const updateModalButton = within(modal).getByRole("button", {
205+
name: /Update/,
199206
});
207+
await user.click(updateModalButton);
208+
209+
await waitFor(() => expect(updateWorkspace).toHaveBeenCalledTimes(3));
200210
expect(updateWorkspace).toHaveBeenCalledWith(workspaces[0], [], false);
201211
expect(updateWorkspace).toHaveBeenCalledWith(workspaces[1], [], false);
202212
expect(updateWorkspace).toHaveBeenCalledWith(workspaces[2], [], false);
@@ -221,67 +231,24 @@ describe("WorkspacesPage", () => {
221231
}
222232

223233
await user.click(screen.getByRole("button", { name: /bulk actions/i }));
224-
const updateButton = await screen.findByTestId("bulk-action-update");
225-
await user.click(updateButton);
234+
const dropdownItem = await screen.findByRole("menuitem", {
235+
name: /Update/,
236+
});
237+
await user.click(dropdownItem);
226238

227-
// Two clicks: no running workspaces warning, 1 dormant workspace.
228-
const confirmButton = await screen.findByTestId("confirm-button");
229-
const dialog = await screen.findByRole("dialog");
230-
expect(dialog).toHaveTextContent(/dormant/i);
231-
await user.click(confirmButton);
232-
expect(dialog).toHaveTextContent(/used by/i);
233-
await user.click(confirmButton);
239+
const modal = await screen.findByRole("dialog", {
240+
name: /Review Updates/i,
241+
});
242+
const updateModalButton = within(modal).getByRole("button", {
243+
name: /Update/,
244+
});
245+
await user.click(updateModalButton);
234246

235247
// `workspaces[0]` was dormant
236-
await waitFor(() => {
237-
expect(updateWorkspace).toHaveBeenCalledTimes(2);
238-
});
248+
await waitFor(() => expect(updateWorkspace).toHaveBeenCalledTimes(2));
239249
expect(updateWorkspace).toHaveBeenCalledWith(workspaces[1], [], false);
240250
expect(updateWorkspace).toHaveBeenCalledWith(workspaces[2], [], false);
241251
});
242-
243-
it("warns about running workspaces and then dormant workspaces", async () => {
244-
const workspaces = [
245-
{ ...MockRunningOutdatedWorkspace, id: "1" },
246-
{ ...MockDormantOutdatedWorkspace, id: "2" },
247-
{ ...MockOutdatedWorkspace, id: "3" },
248-
{ ...MockOutdatedWorkspace, id: "4" },
249-
{ ...MockWorkspace, id: "5" },
250-
];
251-
jest
252-
.spyOn(API, "getWorkspaces")
253-
.mockResolvedValue({ workspaces, count: workspaces.length });
254-
const updateWorkspace = jest.spyOn(API, "updateWorkspace");
255-
const user = userEvent.setup();
256-
renderWithAuth(<WorkspacesPage />);
257-
await waitForLoaderToBeRemoved();
258-
259-
for (const workspace of workspaces) {
260-
await user.click(getWorkspaceCheckbox(workspace));
261-
}
262-
263-
await user.click(screen.getByRole("button", { name: /bulk actions/i }));
264-
const updateButton = await screen.findByTestId("bulk-action-update");
265-
await user.click(updateButton);
266-
267-
// Three clicks: 1 running workspace, 1 dormant workspace.
268-
const confirmButton = await screen.findByTestId("confirm-button");
269-
const dialog = await screen.findByRole("dialog");
270-
expect(dialog).toHaveTextContent(/1 running workspace/i);
271-
await user.click(confirmButton);
272-
expect(dialog).toHaveTextContent(/dormant/i);
273-
await user.click(confirmButton);
274-
expect(dialog).toHaveTextContent(/used by/i);
275-
await user.click(confirmButton);
276-
277-
// `workspaces[1]` was dormant, and `workspaces[4]` was up-to-date
278-
await waitFor(() => {
279-
expect(updateWorkspace).toHaveBeenCalledTimes(3);
280-
});
281-
expect(updateWorkspace).toHaveBeenCalledWith(workspaces[0], [], false);
282-
expect(updateWorkspace).toHaveBeenCalledWith(workspaces[2], [], false);
283-
expect(updateWorkspace).toHaveBeenCalledWith(workspaces[3], [], false);
284-
});
285252
});
286253

287254
it("starts only the stopped and selected workspaces", async () => {

0 commit comments

Comments
 (0)