mirror of
https://github.com/coder/coder.git
synced 2026-09-22 05:05:20 +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 { server } from "testHelpers/server";
|
||||
import { screen } from "@testing-library/react";
|
||||
@@ -301,6 +305,41 @@ describe("WorkspaceSchedulePage", () => {
|
||||
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 () => {
|
||||
renderWithWorkspaceSettingsLayout(<WorkspaceSchedulePage />, {
|
||||
route: `/@${MockUserOwner.username}/${MockWorkspace.name}/schedule`,
|
||||
|
||||
+5
-5
@@ -66,9 +66,8 @@ const WorkspaceSchedulePage: FC = () => {
|
||||
const isLoading = !template;
|
||||
|
||||
const [isConfirmingApply, setIsConfirmingApply] = useState(false);
|
||||
const { mutate: updateWorkspace } = useMutation({
|
||||
mutationFn: () =>
|
||||
API.startWorkspace(workspace.id, workspace.template_active_version_id),
|
||||
const { mutate: restartWorkspace } = useMutation({
|
||||
mutationFn: () => API.restartWorkspace({ workspace }),
|
||||
});
|
||||
|
||||
return (
|
||||
@@ -139,7 +138,8 @@ const WorkspaceSchedulePage: FC = () => {
|
||||
|
||||
if (
|
||||
data.autostopChanged &&
|
||||
getAutostop(workspace).autostopEnabled
|
||||
getAutostop(workspace).autostopEnabled &&
|
||||
workspace.latest_build.status === "running"
|
||||
) {
|
||||
setIsConfirmingApply(true);
|
||||
}
|
||||
@@ -155,7 +155,7 @@ const WorkspaceSchedulePage: FC = () => {
|
||||
cancelText="Apply later"
|
||||
hideCancel={false}
|
||||
onConfirm={() => {
|
||||
updateWorkspace();
|
||||
restartWorkspace();
|
||||
navigate(`/@${username}/${workspaceName}`);
|
||||
}}
|
||||
onClose={() => {
|
||||
|
||||
Reference in New Issue
Block a user