diff --git a/site/src/pages/TemplateSettingsPage/TemplateGeneralSettingsPage/TemplateSettingsForm.tsx b/site/src/pages/TemplateSettingsPage/TemplateGeneralSettingsPage/TemplateSettingsForm.tsx index 8fec6f6b1a808..3af9f674efe20 100644 --- a/site/src/pages/TemplateSettingsPage/TemplateGeneralSettingsPage/TemplateSettingsForm.tsx +++ b/site/src/pages/TemplateSettingsPage/TemplateGeneralSettingsPage/TemplateSettingsForm.tsx @@ -236,24 +236,11 @@ export const TemplateSettingsForm: FC = ({ description="Deprecating a template prevents any new workspaces from being created. Existing workspaces will continue to function." > - - - Deprecation Message - - - Leave the message empty to keep the template active. Any message - provided will mark the template as deprecated. Use this message to - inform users of the deprecation and how to migrate to a new - template. - - { renderWithTemplateSettingsLayout(, { route: `/templates/${MockTemplate.name}/settings`, path: `/templates/:template/settings`, + extraRoutes: [ + { path: "/templates/:template", element:
Template
}, + ], }); await waitForLoaderToBeRemoved(); }; @@ -126,4 +131,68 @@ describe("TemplateSettingsPage", () => { const validate = () => getValidationSchema().validateSync(values); expect(validate).toThrowError(); }); + + describe("Deprecate template", () => { + it("deprecates a template when has access control", async () => { + server.use( + http.get("/api/v2/entitlements", () => { + return HttpResponse.json({ + ...MockEntitlements, + features: API.withDefaultFeatures({ + access_control: { enabled: true, entitlement: "entitled" }, + }), + }); + }), + ); + const updateTemplateMetaSpy = jest.spyOn(API, "updateTemplateMeta"); + const deprecationMessage = "This template is deprecated"; + + await renderTemplateSettingsPage(); + await deprecateTemplate(MockTemplate, deprecationMessage); + + const [templateId, data] = updateTemplateMetaSpy.mock.calls[0]; + + expect(templateId).toEqual(MockTemplate.id); + expect(data).toEqual( + expect.objectContaining({ deprecation_message: deprecationMessage }), + ); + }); + + it("does not deprecate a template when does not have access control", async () => { + server.use( + http.get("/api/v2/entitlements", () => { + return HttpResponse.json({ + ...MockEntitlements, + features: API.withDefaultFeatures({ + access_control: { enabled: false, entitlement: "not_entitled" }, + }), + }); + }), + ); + const updateTemplateMetaSpy = jest.spyOn(API, "updateTemplateMeta"); + + await renderTemplateSettingsPage(); + await deprecateTemplate( + MockTemplate, + "This template should not be able to deprecate", + ); + + const [templateId, data] = updateTemplateMetaSpy.mock.calls[0]; + + expect(templateId).toEqual(MockTemplate.id); + expect(data).toEqual( + expect.objectContaining({ deprecation_message: "" }), + ); + }); + }); }); + +async function deprecateTemplate(template: Template, message: string) { + const deprecationField = screen.getByLabelText("Deprecation Message"); + await userEvent.type(deprecationField, message); + + const submitButton = await screen.findByText( + FooterFormLanguage.defaultSubmitLabel, + ); + await userEvent.click(submitButton); +}