mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
fix(site): use restartWorkspace instead of startWorkspace in schedule dialog (#23658)
This commit is contained in:
+40
-1
@@ -1,4 +1,8 @@
|
|||||||
import { MockUserOwner, MockWorkspace } from "testHelpers/entities";
|
import {
|
||||||
|
MockUserOwner,
|
||||||
|
MockWorkspace,
|
||||||
|
MockWorkspaceBuild,
|
||||||
|
} from "testHelpers/entities";
|
||||||
import { renderWithWorkspaceSettingsLayout } from "testHelpers/renderHelpers";
|
import { renderWithWorkspaceSettingsLayout } from "testHelpers/renderHelpers";
|
||||||
import { server } from "testHelpers/server";
|
import { server } from "testHelpers/server";
|
||||||
import { screen } from "@testing-library/react";
|
import { screen } from "@testing-library/react";
|
||||||
@@ -301,6 +305,41 @@ describe("WorkspaceSchedulePage", () => {
|
|||||||
expect(dialog).toBeInTheDocument();
|
expect(dialog).toBeInTheDocument();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("doesn't show if workspace is stopped", async () => {
|
||||||
|
server.use(
|
||||||
|
http.get("/api/v2/users/:userId/workspace/:workspaceName", () => {
|
||||||
|
return HttpResponse.json({
|
||||||
|
...MockWorkspace,
|
||||||
|
latest_build: { ...MockWorkspaceBuild, status: "stopped" },
|
||||||
|
});
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
renderWithWorkspaceSettingsLayout(<WorkspaceSchedulePage />, {
|
||||||
|
route: `/@${MockUserOwner.username}/${MockWorkspace.name}/schedule`,
|
||||||
|
path: "/:username/:workspace/schedule",
|
||||||
|
extraRoutes: [
|
||||||
|
{ path: "/:username/:workspace", element: <div>Workspace</div> },
|
||||||
|
],
|
||||||
|
});
|
||||||
|
const user = userEvent.setup();
|
||||||
|
const autostopToggle = await screen.findByLabelText(
|
||||||
|
FormLanguage.stopSwitch,
|
||||||
|
);
|
||||||
|
await user.click(autostopToggle);
|
||||||
|
const submitButton = await screen.findByRole("button", {
|
||||||
|
name: /save/i,
|
||||||
|
});
|
||||||
|
await user.click(submitButton);
|
||||||
|
|
||||||
|
const notification = await screen.findByText(
|
||||||
|
`Schedule for workspace "Test-Workspace" updated successfully.`,
|
||||||
|
);
|
||||||
|
expect(notification).toBeInTheDocument();
|
||||||
|
|
||||||
|
const dialog = screen.queryByText("Restart workspace?");
|
||||||
|
expect(dialog).not.toBeInTheDocument();
|
||||||
|
});
|
||||||
|
|
||||||
it("doesn't show if autostop is not changed", async () => {
|
it("doesn't show if autostop is not changed", async () => {
|
||||||
renderWithWorkspaceSettingsLayout(<WorkspaceSchedulePage />, {
|
renderWithWorkspaceSettingsLayout(<WorkspaceSchedulePage />, {
|
||||||
route: `/@${MockUserOwner.username}/${MockWorkspace.name}/schedule`,
|
route: `/@${MockUserOwner.username}/${MockWorkspace.name}/schedule`,
|
||||||
|
|||||||
+5
-5
@@ -66,9 +66,8 @@ const WorkspaceSchedulePage: FC = () => {
|
|||||||
const isLoading = !template;
|
const isLoading = !template;
|
||||||
|
|
||||||
const [isConfirmingApply, setIsConfirmingApply] = useState(false);
|
const [isConfirmingApply, setIsConfirmingApply] = useState(false);
|
||||||
const { mutate: updateWorkspace } = useMutation({
|
const { mutate: restartWorkspace } = useMutation({
|
||||||
mutationFn: () =>
|
mutationFn: () => API.restartWorkspace({ workspace }),
|
||||||
API.startWorkspace(workspace.id, workspace.template_active_version_id),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -139,7 +138,8 @@ const WorkspaceSchedulePage: FC = () => {
|
|||||||
|
|
||||||
if (
|
if (
|
||||||
data.autostopChanged &&
|
data.autostopChanged &&
|
||||||
getAutostop(workspace).autostopEnabled
|
getAutostop(workspace).autostopEnabled &&
|
||||||
|
workspace.latest_build.status === "running"
|
||||||
) {
|
) {
|
||||||
setIsConfirmingApply(true);
|
setIsConfirmingApply(true);
|
||||||
}
|
}
|
||||||
@@ -155,7 +155,7 @@ const WorkspaceSchedulePage: FC = () => {
|
|||||||
cancelText="Apply later"
|
cancelText="Apply later"
|
||||||
hideCancel={false}
|
hideCancel={false}
|
||||||
onConfirm={() => {
|
onConfirm={() => {
|
||||||
updateWorkspace();
|
restartWorkspace();
|
||||||
navigate(`/@${username}/${workspaceName}`);
|
navigate(`/@${username}/${workspaceName}`);
|
||||||
}}
|
}}
|
||||||
onClose={() => {
|
onClose={() => {
|
||||||
|
|||||||
Reference in New Issue
Block a user