// WF-P8 S07 — PipelineAdminPage unit test. Fixture via the real // buildPipelineAdminVM; interactions asserted on the injected onSubmit. // The column config moved to S04 (BoardSettingsPage.test.tsx); what is left // here is the board table, its filters and the create dialog incl. S07a. import { fireEvent, render, screen } from "@testing-library/react"; import { describe, expect, it, vi } from "vitest"; import { buildPipelineAdminVM, type PipelineAdminData, type PipelineAdminItem } from "@hivegrid/view-models"; import { filterBoards, PipelineAdminPage } from "./PipelineAdminPage"; vi.mock("react-i18next", () => ({ useTranslation: () => ({ t: (s: string) => s, i18n: { language: "de" } }), })); // Radix selects are not interactable in jsdom; swap ~/ui Select for a native // one so the create dialog's type field can be driven and asserted. vi.mock("~/ui/components/Select", () => { const Select = ({ value, onValueChange, label, error, errorText, children, ...rest }: any) => (
{error && errorText ? {errorText} : null}
); Select.Item = ({ value, children }: any) => ; return { Select }; }); // Radix dropdowns neither open nor provide their menu context in jsdom, so the // row actions would be unreachable. Both the SubframeCore wrapper and the ~/ui // menu are swapped for plain passthroughs; the entries stay real buttons. vi.mock("@subframe/core", async () => { const actual = await vi.importActual>("@subframe/core"); const Pass = ({ children }: { children?: React.ReactNode }) => <>{children}; return { ...actual, DropdownMenu: { Root: Pass, Trigger: Pass, Portal: Pass, Content: Pass, Item: Pass } }; }); // Same reason for the facet menus of the filter bar. vi.mock("~/ui/components/DropdownMenuMultiSelect", () => { const DropdownMenuMultiSelect = ({ children }: { children?: React.ReactNode }) =>
{children}
; DropdownMenuMultiSelect.DropdownItem = ({ children, onClick, selected, ...rest }: any) => ( ); DropdownMenuMultiSelect.DropdownCustomItem = ({ children }: any) =>
{children}
; DropdownMenuMultiSelect.DropdownUserItem = ({ title }: any) =>
{title}
; DropdownMenuMultiSelect.DropdownDivider = () =>
; return { DropdownMenuMultiSelect }; }); vi.mock("~/ui/components/DropdownMenu", () => { const DropdownMenu = ({ children }: { children?: React.ReactNode }) =>
{children}
; DropdownMenu.DropdownItem = ({ children, onSelect, ...rest }: any) => ( ); DropdownMenu.DropdownDivider = () =>
; return { DropdownMenu }; }); const byUiId = (id: string) => document.querySelector(`[data-ui-id='${id}']`) as HTMLElement; type FixturePipeline = Parameters[0]["pipelines"][number]; const salesBoard: FixturePipeline = { id: "pl1", name: "Sales", typHint: "sales", isDefault: true, projectCount: 11, updatedAtIso: "2026-07-12T06:12:00.000Z", stages: [ { id: "s1", name: "Neu", stageKind: "offen", winProbability: 10, color: "#000", position: 10, projectCount: 4 }, { id: "s2", name: "Gewonnen", stageKind: "gewonnen", winProbability: 100, color: "#0a0", position: 20, projectCount: 5 }, { id: "s3", name: "Verloren", stageKind: "verloren", winProbability: 0, color: "#a00", position: 30, projectCount: 2 }, ], accessRules: [], fieldConfigs: [], }; // No won/lost stage -> the VM calls this a draft; one deny rule -> restricted. const draftBoard: FixturePipeline = { id: "pl2", name: "Eigenes Board", typHint: "custom", isDefault: false, projectCount: 0, stages: [{ id: "s9", name: "Neu", stageKind: "offen", winProbability: 0, color: "#666", position: 10, projectCount: 0 }], accessRules: [{ id: "a1", principalType: "group", principalId: "grp-montage", kannSehen: false, kannBearbeiten: false }], fieldConfigs: [], }; function adminData(pipelines: FixturePipeline[] = [salesBoard, draftBoard]): PipelineAdminData { const vm = buildPipelineAdminVM({ canAdmin: true, pipelines }); if (vm.status !== "ready") throw new Error("fixture not ready"); return vm.data; } const baseProps = { lostReasonsHref: "/acme/admin/pipelines/lost-reasons", settingsHref: (id: string) => `/acme/admin/pipelines/${id}`, }; function renderPage(data = adminData()) { const onSubmit = vi.fn(); render(); return onSubmit; } describe("PipelineAdminPage", () => { it("points the header settings button at the default board", () => { renderPage(); // The export's button names no board; the default one is the only sensible // target, and it is the board the footer line already calls out. expect(byUiId("ui.projects.admin.headerSettings").getAttribute("href")).toBe("/acme/admin/pipelines/pl1"); }); it("falls back to the first board when none is marked as the default", () => { renderPage(adminData([{ ...draftBoard, isDefault: false }])); expect(byUiId("ui.projects.admin.headerSettings").getAttribute("href")).toBe("/acme/admin/pipelines/pl2"); }); it("renders one row per board with counts, access and status", () => { renderPage(); expect(byUiId("ui.projects.admin.list")).toBeTruthy(); expect(screen.getByText("Sales")).toBeTruthy(); expect(byUiId("ui.projects.admin.row.pl1.projects").textContent).toBe("11"); // getAllByText: the mocked native filter selects render the same labels as //