Skip to content

Commit 38ba3b2

Browse files
committed
chore: finish tests
1 parent bf21656 commit 38ba3b2

File tree

3 files changed

+33
-6
lines changed

3 files changed

+33
-6
lines changed

site/src/pages/CreateWorkspacePage/CreateWorkspacePage.test.tsx

+22
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
waitForLoaderToBeRemoved,
2121
} from "testHelpers/renderHelpers";
2222
import CreateWorkspacePage from "./CreateWorkspacePage";
23+
import { Language } from "./CreateWorkspacePageView";
2324

2425
const nameLabelText = "Workspace Name";
2526
const createWorkspaceText = "Create Workspace";
@@ -270,4 +271,25 @@ describe("CreateWorkspacePage", () => {
270271
);
271272
});
272273
});
274+
275+
it("Detects when a workspace is being created with the 'duplicate' mode", async () => {
276+
const params = new URLSearchParams({
277+
mode: "duplicate",
278+
name: MockWorkspace.name,
279+
version: MockWorkspace.template_active_version_id,
280+
});
281+
282+
renderWithAuth(<CreateWorkspacePage />, {
283+
path: "/templates/:template/workspace",
284+
route: `/templates/${MockWorkspace.name}/workspace?${params.toString()}`,
285+
});
286+
287+
const warningMessage = await screen.findByRole("alert");
288+
const nameInput = await screen.findByRole("textbox", {
289+
name: "Workspace Name",
290+
});
291+
292+
expect(warningMessage).toHaveTextContent(Language.duplicationWarning);
293+
expect(nameInput).toHaveValue(`${MockWorkspace.name}-copy`);
294+
});
273295
});

site/src/pages/CreateWorkspacePage/CreateWorkspacePageView.tsx

+6-2
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ import { useSearchParams } from "react-router-dom";
3737
import { CreateWSPermissions } from "./permissions";
3838
import { Alert } from "components/Alert/Alert";
3939

40+
export const Language = {
41+
duplicationWarning:
42+
"Duplicating a workspace only copies its parameters. No state from the old workspace is copied over.",
43+
} as const;
44+
4045
export interface CreateWorkspacePageViewProps {
4146
mode: CreateWorkspaceMode;
4247
error: unknown;
@@ -124,8 +129,7 @@ export const CreateWorkspacePageView: FC<CreateWorkspacePageViewProps> = ({
124129

125130
{mode === "duplicate" && (
126131
<Alert severity="info" dismissible>
127-
Duplicating a workspace only copies its parameters. No state from
128-
the old workspace is copied over.
132+
{Language.duplicationWarning}
129133
</Alert>
130134
)}
131135

site/src/pages/CreateWorkspacePage/useWorkspaceDuplication.test.tsx

+5-4
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,9 @@ describe(`${useWorkspaceDuplication.name}`, () => {
9090
M.MockWorkspaceBuildParameter5,
9191
];
9292

93-
for (const p of mockBuildParams) {
94-
expect(parsedParams.get(`param.${p.name}`)).toEqual(p.value);
93+
for (const { name, value } of mockBuildParams) {
94+
const key = `param.${name}`;
95+
expect(parsedParams.get(key)).toEqual(value);
9596
}
9697
});
9798

@@ -101,13 +102,13 @@ describe(`${useWorkspaceDuplication.name}`, () => {
101102
await performNavigation(button, router);
102103

103104
const parsedParams = new URLSearchParams(router.state.location.search);
104-
const expectedParamEntries = [
105+
const extraMetadataEntries = [
105106
["mode", "duplicate"],
106107
["name", MockWorkspace.name],
107108
["version", MockWorkspace.template_active_version_id],
108109
] as const;
109110

110-
for (const [key, value] of expectedParamEntries) {
111+
for (const [key, value] of extraMetadataEntries) {
111112
expect(parsedParams.get(key)).toBe(value);
112113
}
113114
});

0 commit comments

Comments
 (0)