Skip to content

Commit 2c55fd8

Browse files
committed
wip: add tests for workspace retries (breaks 2 previous tests
1 parent c3edba7 commit 2c55fd8

File tree

1 file changed

+89
-1
lines changed

1 file changed

+89
-1
lines changed

site/src/pages/WorkspacePage/WorkspacePage.test.tsx

Lines changed: 89 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { rest } from "msw";
66
import {
77
MockTemplate,
88
MockWorkspace,
9+
MockFailedWorkspace,
910
MockWorkspaceBuild,
1011
MockStoppedWorkspace,
1112
MockStartingWorkspace,
@@ -22,7 +23,7 @@ import { renderWithAuth } from "testHelpers/renderHelpers";
2223
import { server } from "testHelpers/server";
2324
import { WorkspacePage } from "./WorkspacePage";
2425

25-
// It renders the workspace page and waits for it be loaded
26+
// Renders the workspace page and waits for it be loaded
2627
const renderWorkspacePage = async (workspace: Workspace) => {
2728
jest.spyOn(api, "getWorkspaceByOwnerAndName").mockResolvedValue(workspace);
2829
jest.spyOn(api, "getTemplate").mockResolvedValueOnce(MockTemplate);
@@ -369,4 +370,91 @@ describe("WorkspacePage", () => {
369370
});
370371
});
371372
});
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 = /^Retry$/i;
379+
const retryDebugButtonRe = /^Retry \(Debug\)$/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+
});
372460
});

0 commit comments

Comments
 (0)