fix: harden workspace manager drafts
This commit is contained in:
@@ -72,6 +72,43 @@ test("stages duplicate and delete operations without publishing", async () => {
|
||||
expect(published).toBe(false);
|
||||
});
|
||||
|
||||
test("proposes a different valid ID when duplicating a 63-character workspace ID", async () => {
|
||||
const user = userEvent.setup();
|
||||
const maxId = `w${"a".repeat(62)}`;
|
||||
const maxWorkspace = { ...workspace, workspace: { ...workspace.workspace, id: maxId } };
|
||||
server.use(
|
||||
http.get("http://localhost:8787/workspaces", () => HttpResponse.json([{
|
||||
id: maxId, name: "Maximum", displayName: "Maximum", language: "en", file: `workspaces/${maxId}.yaml`,
|
||||
revision: { id: maxId, commit: "a".repeat(40), blob: "b".repeat(40), snapshotPath: "/tmp/maximum", state: "operational" },
|
||||
}])),
|
||||
http.get(`http://localhost:8787/workspaces/${maxId}`, () => HttpResponse.json({
|
||||
workspace: maxWorkspace,
|
||||
revision: { id: maxId, commit: "a".repeat(40), blob: "b".repeat(40), snapshotPath: "/tmp/maximum", state: "operational" },
|
||||
})),
|
||||
);
|
||||
renderManager();
|
||||
|
||||
await user.click(await screen.findByRole("button", { name: "Maximum" }));
|
||||
await user.click(screen.getByRole("button", { name: "Duplicate workspace" }));
|
||||
|
||||
const proposed = screen.getByLabelText("Workspace ID") as HTMLInputElement;
|
||||
expect(proposed.value).toMatch(/^[a-z][a-z0-9-]{2,62}$/);
|
||||
expect(proposed).not.toHaveValue(maxId);
|
||||
});
|
||||
|
||||
test("does not show a saved-draft toast when manager validation rejects a DWH timeout", async () => {
|
||||
const user = userEvent.setup();
|
||||
renderManager();
|
||||
|
||||
await user.click(await screen.findByRole("button", { name: "PSD Clinical" }));
|
||||
await user.clear(screen.getByLabelText("DWH timeout (ms)"));
|
||||
await user.type(screen.getByLabelText("DWH timeout (ms)"), "0");
|
||||
await user.click(screen.getByRole("button", { name: "Save draft" }));
|
||||
|
||||
expect(screen.getByRole("alert")).toHaveTextContent("DWH timeout must be a positive whole number");
|
||||
expect(screen.queryByText("Draft saved in this browser.")).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
test("runs validation and installation test with only sanitized messages", async () => {
|
||||
const user = userEvent.setup();
|
||||
server.use(
|
||||
@@ -90,3 +127,53 @@ test("runs validation and installation test with only sanitized messages", async
|
||||
expect(await screen.findByText("binding_missing: DWH binding is not configured")).toBeVisible();
|
||||
expect(within(screen.getByTestId("workspace-diagnostics")).queryByText(/password|token|secret/i)).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
test("shows an accessible retry instead of a loading status when the registry status query fails", async () => {
|
||||
const user = userEvent.setup();
|
||||
let calls = 0;
|
||||
server.use(http.get("http://localhost:8787/workspace-registry/status", () => {
|
||||
calls += 1;
|
||||
return calls === 1 ? new HttpResponse(null, { status: 503 }) : HttpResponse.json({ branch: "main", ahead: 0, behind: 0, degraded: false });
|
||||
}));
|
||||
renderManager();
|
||||
|
||||
expect(await screen.findByRole("alert", { name: "Workspace registry status failed" })).toHaveTextContent("Could not load registry status.");
|
||||
await user.click(screen.getByRole("button", { name: "Retry registry status" }));
|
||||
expect(await screen.findByText("main")).toBeVisible();
|
||||
expect(calls).toBe(2);
|
||||
});
|
||||
|
||||
test("shows an accessible retry instead of an empty list when the workspace list query fails", async () => {
|
||||
const user = userEvent.setup();
|
||||
let calls = 0;
|
||||
server.use(http.get("http://localhost:8787/workspaces", () => {
|
||||
calls += 1;
|
||||
return calls === 1 ? new HttpResponse(null, { status: 503 }) : HttpResponse.json([]);
|
||||
}));
|
||||
renderManager();
|
||||
|
||||
expect(await screen.findByRole("alert", { name: "Workspace list failed" })).toHaveTextContent("Could not load workspaces.");
|
||||
expect(screen.queryByText("No published workspaces.")).not.toBeInTheDocument();
|
||||
await user.click(screen.getByRole("button", { name: "Retry workspace list" }));
|
||||
expect(await screen.findByText("No published workspaces.")).toBeVisible();
|
||||
expect(calls).toBe(2);
|
||||
});
|
||||
|
||||
test("shows an accessible retry when the selected workspace detail query fails", async () => {
|
||||
const user = userEvent.setup();
|
||||
let calls = 0;
|
||||
server.use(http.get("http://localhost:8787/workspaces/psd-clinical", () => {
|
||||
calls += 1;
|
||||
return calls === 1 ? new HttpResponse(null, { status: 503 }) : HttpResponse.json({
|
||||
workspace,
|
||||
revision: { id: "psd-clinical", commit: "a".repeat(40), blob: "b".repeat(40), snapshotPath: "/tmp/psd", state: "operational" },
|
||||
});
|
||||
}));
|
||||
renderManager();
|
||||
|
||||
await user.click(await screen.findByRole("button", { name: "PSD Clinical" }));
|
||||
expect(await screen.findByRole("alert", { name: "Workspace details failed" })).toHaveTextContent("Could not load workspace details.");
|
||||
await user.click(screen.getByRole("button", { name: "Retry workspace details" }));
|
||||
expect(await screen.findByRole("heading", { name: "PSD Clinical" })).toBeVisible();
|
||||
expect(calls).toBe(2);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user