8000 feat(site): add stop and start batch actions by BrunoQuaresma · Pull Request #10565 · coder/coder · GitHub
[go: up one dir, main page]

Skip to content

feat(site): add stop and start batch actions #10565

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Nov 8, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix tests
  • Loading branch information
BrunoQuaresma committed Nov 7, 2023
commit eebbdd420e20e75685a982ceaa81373a143580e2
70 changes: 68 additions & 2 deletions site/src/pages/WorkspacesPage/WorkspacesPage.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { screen, waitFor, within } from "@testing-library/react";
import { rest } from "msw";
import * as CreateDayString from "utils/createDayString";
import { MockWorkspace, MockWorkspacesResponse } from "testHelpers/entities";
import {
MockStoppedWorkspace,
MockWorkspace,
MockWorkspacesResponse,
} from "testHelpers/entities";
import {
renderWithAuth,
waitForLoaderToBeRemoved,
Expand Down Expand Up @@ -59,7 +63,9 @@ describe("WorkspacesPage", () => {

await user.click(getWorkspaceCheckbox(workspaces[0]));
await user.click(getWorkspaceCheckbox(workspaces[1]));
await user.click(screen.getByRole("button", { name: /delete selected/i }));
await user.click(screen.getByRole("button", { name: /actions/i }));
const deleteButton = await screen.findByText(/delete/i);
await user.click(deleteButton);
await user.type(screen.getByLabelText(/type delete to confirm/i), "DELETE");
await user.click(screen.getByTestId("confirm-button"));

Expand All @@ -69,6 +75,66 @@ describe("WorkspacesPage", () => {
expect(deleteWorkspace).toHaveBeenCalledWith(workspaces[0].id);
expect(deleteWorkspace).toHaveBeenCalledWith(workspaces[1].id);
});

it("stops only the running and selected workspaces", async () => {
const workspaces = [
{ ...MockWorkspace, id: "1" },
{ ...MockWorkspace, id: "2" },
{ ...MockWorkspace, id: "3" },
];
jest
.spyOn(API, "getWorkspaces")
.mockResolvedValue({ workspaces, count: workspaces.length });
const stopWorkspace = jest.spyOn(API, "stopWorkspace");
const user = userEvent.setup();
renderWithAuth(<WorkspacesPage />);
await waitForLoaderToBeRemoved();

await user.click(getWorkspaceCheckbox(workspaces[0]));
await user.click(getWorkspaceCheckbox(workspaces[1]));
await user.click(screen.getByRole("button", { name: /actions/i }));
const stopButton = await screen.findByText(/stop/i);
await user.click(stopButton);

await waitFor(() => {
expect(stopWorkspace).toHaveBeenCalledTimes(2);
});
expect(stopWorkspace).toHaveBeenCalledWith(workspaces[0].id);
expect(stopWorkspace).toHaveBeenCalledWith(workspaces[1].id);
});

it("starts only the stopped and selected workspaces", async () => {
const workspaces = [
{ ...MockStoppedWorkspace, id: "1" },
{ ...MockStoppedWorkspace, id: "2" },
{ ...MockStoppedWorkspace, id: "3" },
];
jest
.spyOn(API, "getWorkspaces")
.mockResolvedValue({ workspaces, count: workspaces.length });
const startWorkspace = jest.spyOn(API, "startWorkspace");
const user = userEvent.setup();
renderWithAuth(<WorkspacesPage />);
await waitForLoaderToBeRemoved();

await user.click(getWorkspaceCheckbox(workspaces[0]));
await user.click(getWorkspaceCheckbox(workspaces[1]));
await user.click(screen.getByRole("button", { name: /actions/i }));
const startButton = await screen.findByText(/start/i);
await user.click(startButton);

await waitFor(() => {
expect(startWorkspace).toHaveBeenCalledTimes(2);
});
expect(startWorkspace).toHaveBeenCalledWith(
workspaces[0].id,
MockStoppedWorkspace.latest_build.template_version_id,
);
expect(startWorkspace).toHaveBeenCalledWith(
workspaces[1].id,
MockStoppedWorkspace.latest_build.template_version_id,
);
});
});

const getWorkspaceCheckbox = (workspace: Workspace) => {
Expand Down
0