Skip to content

Template settings fixes/kira pilot #3668

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 13 commits into from
Aug 24, 2022
Next Next commit
using hours instead of seconds
  • Loading branch information
Kira-Pilot committed Aug 23, 2022
commit cf85bfe35e6cc7a9f46204c0d72c938f82821b8e
10 changes: 5 additions & 5 deletions site/src/pages/TemplateSettingsPage/TemplateSettingsForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const Language = {
maxTtlLabel: "Auto-stop limit",
iconLabel: "Icon",
// This is the same from the CLI on https://github.com/coder/coder/blob/546157b63ef9204658acf58cb653aa9936b70c49/cli/templateedit.go#L59
maxTtlHelperText: "Edit the template maximum time before shutdown in seconds",
maxTtlHelperText: "Edit the template maximum time before shutdown in hours",
formAriaLabel: "Template settings form",
selectEmoji: "Select emoji",
}
Expand Down Expand Up @@ -154,11 +154,11 @@ export const TemplateSettingsForm: FC<TemplateSettingsForm> = ({
inputProps={{ min: 0, step: 1 }}
label={Language.maxTtlLabel}
variant="outlined"
// Display seconds from ms
value={form.values.max_ttl_ms ? form.values.max_ttl_ms / 1000 : ""}
// Convert ms to seconds
// Display hours from ms
value={form.values.max_ttl_ms ? form.values.max_ttl_ms / 3600000 : ""}
// Convert hours to ms
onChange={(event) =>
form.setFieldValue("max_ttl_ms", Number(event.currentTarget.value) * 1000)
form.setFieldValue("max_ttl_ms", Number(event.currentTarget.value) * 3600000)
}
/>
</Stack>
Expand Down
30 changes: 30 additions & 0 deletions site/src/pages/TemplateSettingsPage/TemplateSettingsPage.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,34 @@ describe("TemplateSettingsPage", () => {

await waitFor(() => expect(API.updateTemplateMeta).toBeCalledTimes(1))
})

test("ttl is converted to and from hours", async () => {
await renderTemplateSettingsPage()

const newTemplateSettings = {
name: "edited-template-name",
description: "Edited description",
max_ttl_ms: 1,
icon: "/icon/code.svg",
}

jest.spyOn(API, "updateTemplateMeta").mockResolvedValueOnce({
...MockTemplate,
...newTemplateSettings,
})

await fillAndSubmitForm(newTemplateSettings)
expect(screen.getByDisplayValue(1)).toBeInTheDocument()
await waitFor(() => expect(API.updateTemplateMeta).toBeCalledTimes(1))

await waitFor(() =>
expect(API.updateTemplateMeta).toBeCalledWith(
"test-template",
expect.objectContaining({
...newTemplateSettings,
max_ttl_ms: 3600000,
}),
),
)
})
})