67 lines
2.9 KiB
TypeScript
67 lines
2.9 KiB
TypeScript
import { render, screen, waitFor } from "@testing-library/react";
|
|
import userEvent from "@testing-library/user-event";
|
|
import { http, HttpResponse } from "msw";
|
|
import { beforeEach, expect, test, vi } from "vitest";
|
|
import { canonicalWorkspaceFixture, workspaceRevisionFixture } from "../test/workspace-fixtures";
|
|
import { server } from "../test/msw";
|
|
import { WorkspacePublishDialog } from "./WorkspacePublishDialog";
|
|
|
|
const workspace = {
|
|
...canonicalWorkspaceFixture("bootstrap-slot"),
|
|
workspace: {
|
|
...canonicalWorkspaceFixture("bootstrap-slot").workspace,
|
|
name: "Bootstrap slot",
|
|
description: "Needs configuration",
|
|
},
|
|
};
|
|
|
|
const request = {
|
|
action: "create" as const,
|
|
workspace,
|
|
baseCommit: "a".repeat(40),
|
|
};
|
|
|
|
beforeEach(() => {
|
|
server.use(http.post("/api/workspaces/validate", () => HttpResponse.json({ workspace, contract: {} })));
|
|
});
|
|
|
|
test("validates a bootstrap draft and requires a separate confirmation before creating it", async () => {
|
|
const user = userEvent.setup();
|
|
const published = vi.fn();
|
|
let publishCalls = 0;
|
|
server.use(http.post("/api/workspaces/publish", () => {
|
|
publishCalls += 1;
|
|
return HttpResponse.json({ revision: workspaceRevisionFixture("bootstrap-slot") });
|
|
}));
|
|
|
|
render(<WorkspacePublishDialog open request={request} onOpenChange={vi.fn()} onPublished={published} />);
|
|
|
|
expect(screen.getByRole("button", { name: "Create workspace" })).toBeDisabled();
|
|
await user.click(screen.getByRole("button", { name: "Validate draft" }));
|
|
expect(await screen.findByText("Workspace definition is valid.")).toBeVisible();
|
|
await user.click(screen.getByRole("button", { name: "Create workspace" }));
|
|
expect(screen.getByRole("heading", { name: "Confirm workspace creation" })).toBeVisible();
|
|
expect(publishCalls).toBe(0);
|
|
await user.click(screen.getByRole("button", { name: "Confirm create" }));
|
|
|
|
await waitFor(() => expect(published).toHaveBeenCalledWith(workspaceRevisionFixture("bootstrap-slot")));
|
|
expect(publishCalls).toBe(1);
|
|
});
|
|
|
|
test("surfaces a safe curator-owned refusal without showing conflict resolution UI", async () => {
|
|
const user = userEvent.setup();
|
|
server.use(http.post("/api/workspaces/publish", () => HttpResponse.json({
|
|
code: "workspace_curator_owned",
|
|
message: "Existing descriptors are curator-owned.",
|
|
}, { status: 409 })));
|
|
|
|
render(<WorkspacePublishDialog open request={request} onOpenChange={vi.fn()} onPublished={vi.fn()} />);
|
|
|
|
await user.click(screen.getByRole("button", { name: "Validate draft" }));
|
|
await user.click(await screen.findByRole("button", { name: "Create workspace" }));
|
|
await user.click(screen.getByRole("button", { name: "Confirm create" }));
|
|
|
|
expect(await screen.findByText("workspace_curator_owned: Existing descriptors are curator-owned.")).toBeVisible();
|
|
expect(screen.queryByText(/save revised draft|use your draft|use registry value/i)).not.toBeInTheDocument();
|
|
});
|