Skip to content

Commit 0c4d52c

Browse files
committed
Fix second test
1 parent cf0b8fd commit 0c4d52c

File tree

3 files changed

+33
-19
lines changed

3 files changed

+33
-19
lines changed

site/src/pages/WorkspaceSchedulePage/WorkspaceSchedulePage.test.tsx

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,14 @@ import {
1111
} from "pages/WorkspaceSchedulePage/schedule"
1212
import { AutoStop, ttlMsToAutoStop } from "pages/WorkspaceSchedulePage/ttl"
1313
import * as TypesGen from "../../api/typesGenerated"
14-
import { WorkspaceScheduleFormValues } from "../../components/WorkspaceScheduleForm/WorkspaceScheduleForm"
14+
import {
15+
WorkspaceScheduleFormValues,
16+
Language as FormLanguage,
17+
} from "../../components/WorkspaceScheduleForm/WorkspaceScheduleForm"
18+
import {
19+
WorkspaceSchedulePage,
20+
Language as PageLanguage,
21+
} from "./WorkspaceSchedulePage"
1522

1623
const validValues: WorkspaceScheduleFormValues = {
1724
autoStartEnabled: true,
@@ -262,6 +269,20 @@ describe("WorkspaceSchedulePage", () => {
262269
expect(dialog).toBeInTheDocument()
263270
})
264271

265-
272+
it("doesn't show if autoStop is not changed", async () => {
273+
renderWithAuth(<WorkspaceSchedulePage />, {
274+
route: `/@${MockUser.username}/${MockWorkspace.name}/schedule`,
275+
path: "/@:username/:workspace/schedule"
276+
})
277+
const user = userEvent.setup()
278+
const autoStartToggle = await screen.findByLabelText(
279+
FormLanguage.startSwitch,
280+
)
281+
await user.click(autoStartToggle)
282+
const submitButton = await screen.findByRole("button", { name: /submit/i })
283+
await user.click(submitButton)
284+
const dialog = screen.queryByText(PageLanguage.dialogTitle)
285+
expect(dialog).not.toBeInTheDocument()
286+
})
266287
})
267288
})

site/src/pages/WorkspaceSchedulePage/WorkspaceSchedulePage.tsx

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { AlertBanner } from "components/AlertBanner/AlertBanner"
33
import { ConfirmDialog } from "components/Dialogs/ConfirmDialog/ConfirmDialog"
44
import { scheduleToAutoStart } from "pages/WorkspaceSchedulePage/schedule"
55
import { ttlMsToAutoStop } from "pages/WorkspaceSchedulePage/ttl"
6-
import React, { useEffect, useState } from "react"
6+
import React, { useEffect } from "react"
77
import { Navigate, useNavigate, useParams } from "react-router-dom"
88
import { scheduleChanged } from "util/schedule"
99
import * as TypesGen from "../../api/typesGenerated"
@@ -28,6 +28,11 @@ export const Language = {
2828
applyLater: "Apply update later",
2929
}
3030

31+
const getAutoStart = (workspace?: TypesGen.Workspace) =>
32+
scheduleToAutoStart(workspace?.autostart_schedule)
33+
const getAutoStop = (workspace?: TypesGen.Workspace) =>
34+
ttlMsToAutoStop(workspace?.ttl_ms)
35+
3136
export const WorkspaceSchedulePage: React.FC = () => {
3237
const { username: usernameQueryParam, workspace: workspaceQueryParam } =
3338
useParams()
@@ -52,19 +57,6 @@ export const WorkspaceSchedulePage: React.FC = () => {
5257
scheduleSend({ type: "GET_WORKSPACE", username, workspaceName })
5358
}, [username, workspaceName, scheduleSend])
5459

55-
const getAutoStart = (workspace?: TypesGen.Workspace) =>
56-
scheduleToAutoStart(workspace?.autostart_schedule)
57-
const getAutoStop = (workspace?: TypesGen.Workspace) =>
58-
ttlMsToAutoStop(workspace?.ttl_ms)
59-
60-
const [autoStart, setAutoStart] = useState(getAutoStart(workspace))
61-
const [autoStop, setAutoStop] = useState(getAutoStop(workspace))
62-
63-
useEffect(() => {
64-
setAutoStart(getAutoStart(workspace))
65-
setAutoStop(getAutoStop(workspace))
66-
}, [workspace])
67-
6860
if (!username || !workspaceName) {
6961
return <Navigate to="/workspaces" />
7062
}
@@ -108,7 +100,7 @@ export const WorkspaceSchedulePage: React.FC = () => {
108100
return (
109101
<WorkspaceScheduleForm
110102
submitScheduleError={submitScheduleError}
111-
initialValues={{ ...autoStart, ...autoStop }}
103+
initialValues={{ ...getAutoStart(workspace), ...getAutoStop(workspace) }}
112104
isLoading={scheduleState.tags.has("loading")}
113105
onCancel={() => {
114106
navigate(`/@${username}/${workspaceName}`)
@@ -118,8 +110,8 @@ export const WorkspaceSchedulePage: React.FC = () => {
118110
type: "SUBMIT_SCHEDULE",
119111
autoStart: formValuesToAutoStartRequest(values),
120112
ttl: formValuesToTTLRequest(values),
121-
autoStartChanged: scheduleChanged(autoStart, values),
122-
autoStopChanged: scheduleChanged(autoStop, values),
113+
autoStartChanged: scheduleChanged(getAutoStart(workspace), values),
114+
autoStopChanged: scheduleChanged(getAutoStop(workspace), values),
123115
})
124116
}}
125117
/>

site/src/xServices/workspaceSchedule/workspaceScheduleXService.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ export const workspaceSchedule =
214214
}
215215
},
216216
submitSchedule: async (context, event) => {
217+
console.log(event)
217218
if (!context.workspace?.id) {
218219
// This state is theoretically impossible, but helps TS
219220
throw new Error("Failed to load workspace.")

0 commit comments

Comments
 (0)