Files
HiveGrid-Wireframes/03 Quellen und Referenzen/hivegrid-cloud/apps/web/app/components/screens/projects/PipelineKanbanPage.test.tsx
T

689 lines
32 KiB
TypeScript

// R-P8b interim-UI (AD-28) — PipelineKanbanPage unit test. Fixture built via the
// real buildKanbanVM; interactions asserted on injected callbacks. i18n mocked.
// SortableKanbanBoard is stubbed so a "drag-end" is simulated by invoking its
// onCardMove prop directly — this keeps the test deterministic (no dnd-kit
// layout math in jsdom) while still exercising the screen's requestMove routing.
import { fireEvent, render, screen } from "@testing-library/react";
import { describe, expect, it, vi } from "vitest";
import { buildBoardFacetsVM, buildKanbanVM, buildPipelineHandoverVM, type KanbanBoardData, type PipelineHandoverVM } from "@hivegrid/view-models";
import { PipelineKanbanPage, type PipelineKanbanActions } from "./PipelineKanbanPage";
vi.mock("react-i18next", () => ({
useTranslation: () => ({ t: (s: string) => s, i18n: { language: "de" } }),
}));
// Radix dropdowns neither open nor expose their menu context in jsdom, so the
// board switcher chip and every facet dropdown would be unreachable. The
// SubframeCore wrapper and both ~/ui menus become plain passthroughs; the
// entries stay real buttons. The ContextMenu is left alone — the card menu
// tests rely on the real one.
vi.mock("@subframe/core", async () => {
const actual = await vi.importActual<Record<string, unknown>>("@subframe/core");
const Pass = ({ children }: { children?: React.ReactNode }) => <>{children}</>;
return { ...actual, DropdownMenu: { Root: Pass, Trigger: Pass, Portal: Pass, Content: Pass } };
});
vi.mock("~/ui/components/DropdownMenu", () => {
const DropdownMenu = ({ children }: { children?: React.ReactNode }) => <div>{children}</div>;
DropdownMenu.DropdownItem = ({ children, onSelect, onClick, ...rest }: any) => (
<button type="button" onClick={(event: any) => { onSelect?.(); onClick?.(event); }} data-ui-id={rest["data-ui-id"]}>
{children}
</button>
);
DropdownMenu.DropdownDivider = () => <hr />;
return { DropdownMenu };
});
vi.mock("~/ui/components/DropdownMenuMultiSelect", () => {
const DropdownMenuMultiSelect = ({ children }: { children?: React.ReactNode }) => <div>{children}</div>;
DropdownMenuMultiSelect.DropdownItem = ({ children, onClick, selected, ...rest }: any) => (
<button type="button" onClick={onClick} aria-pressed={Boolean(selected)} data-ui-id={rest["data-ui-id"]}>
{children}
</button>
);
DropdownMenuMultiSelect.DropdownCustomItem = ({ children }: any) => <div>{children}</div>;
DropdownMenuMultiSelect.DropdownUserItem = ({ title }: any) => <div>{title}</div>;
DropdownMenuMultiSelect.DropdownDivider = () => <hr />;
return { DropdownMenuMultiSelect };
});
// Radix selects are not interactable in jsdom; swap ~/ui Select for a native
// one so the M01 lost-reason field can actually be chosen and asserted.
vi.mock("~/ui/components/Select", () => {
const Select = ({ value, onValueChange, label, error, errorText, children, ...rest }: any) => (
<div data-ui-id={rest["data-ui-id"]}>
<select
aria-label={typeof label === "string" ? label : "select"}
value={value ?? ""}
onChange={(e: any) => onValueChange?.(e.target.value)}
data-ui-id={rest["data-ui-id"] ? `${rest["data-ui-id"]}.native` : undefined}
>
<option value="" />
{children}
</select>
{error && errorText ? <span data-ui-id={rest["data-ui-id"] ? `${rest["data-ui-id"]}.errorText` : undefined}>{errorText}</span> : null}
</div>
);
Select.Item = ({ value, children }: any) => <option value={value}>{children}</option>;
return { Select };
});
// Stub the shared board: render each card via the real renderCard slot and expose
// one "move" button per (card, target column) that fires onCardMove — the same
// signal a real drag-end emits.
vi.mock("~/components/ui/kanban/SortableKanbanBoard", () => ({
SortableKanbanBoard: (p: {
columns: { id: string; name: React.ReactNode; price: React.ReactNode; sumMode?: "visible" | "locked" | "hidden"; twoColumn?: boolean; wrapAfter?: number; cards: { id: string }[] }[];
renderCard: (card: { id: string }, dragHandle?: React.ReactNode) => React.ReactNode;
onCardMove: (cardId: string, toColumnId: string, toIndex: number) => void;
dragHandlePlacement?: "above" | "inline";
}) => (
<div data-ui-id="ui.projects.board.columns">
{p.columns.map((col) => (
<div
key={col.id}
data-ui-id={`stub.col.${col.id}`}
data-sum-mode={col.sumMode}
data-two-column={String(col.twoColumn)}
data-wrap-after={String(col.wrapAfter)}
>
<span>{col.name}</span>
<span>{col.price}</span>
{col.cards.map((card) => (
<div key={card.id}>
{p.renderCard(
card,
p.dragHandlePlacement === "inline" ? (
<button type="button" aria-label={`drag-${card.id}`} data-ui-id={`stub.drag.${card.id}`} />
) : undefined,
)}
{p.columns
.filter((target) => target.id !== col.id)
.map((target) => (
<button
key={target.id}
type="button"
data-ui-id={`stub.move.${card.id}.${target.id}`}
onClick={() => p.onCardMove(card.id, target.id, 0)}
/>
))}
</div>
))}
</div>
))}
</div>
),
}));
const byUiId = (id: string) => document.querySelector(`[data-ui-id='${id}']`) as HTMLElement;
function boardData(
opts: {
empty?: boolean;
manyInS1?: boolean;
stuckP1?: boolean;
canAdmin?: boolean;
canDelete?: boolean;
undoP1?: boolean;
redoP1?: boolean;
cardTags?: { id: string; name: string; farbe: string }[];
} = {}
): KanbanBoardData {
const s1Cards = opts.empty
? []
: opts.manyInS1
? Array.from({ length: 7 }, (_, index) => ({
id: `p${index + 1}`,
projektNummer: `P-${index + 1}`,
projektname: `Projekt ${index + 1}`,
prioritaet: "normal" as const,
value: null,
valueVisible: false,
ownerUserId: null,
deadline: null,
isStuck: false,
}))
: [
// stuckP1: 9 full days in stage relative to generatedAt (2026-07-08T12:00Z).
{ id: "p1", projektNummer: "P-1", projektname: "Dach Nord", prioritaet: "normal" as const, value: "10000.00", valueVisible: true, ownerUserId: "u1", deadline: "2026-07-30", isStuck: false, inStageSince: opts.stuckP1 ? "2026-06-29T12:00:00.000Z" : "2026-07-08T00:00:00.000Z", kontaktLabel: "Fam. Bergmann", ort: "Freiburg", projekttyp: "PV / Solar", tags: opts.cardTags ?? [], startDatum: "2026-07-14", nextTerminTitel: "Ortstermin", nextTerminStartAt: "2026-07-22T08:00:00.000Z", undoStageChangeUntil: opts.undoP1 ? "2026-07-09T12:00:00.000Z" : null, redoStageId: opts.redoP1 ? "s3" : null },
{ id: "p2", projektNummer: "P-2", projektname: "Halle Sued", prioritaet: "normal" as const, value: null, valueVisible: false, ownerUserId: null, deadline: null, isStuck: false, inStageSince: "2026-07-08T00:00:00.000Z" },
];
const vm = buildKanbanVM({
board: {
pipeline: { id: "pl1", name: "Sales" },
pipelines: [
{ id: "pl1", name: "Sales", typHint: "sales" },
{ id: "pl2", name: "Auftrag", typHint: "auftrag" },
],
columns: [
{
stage: { id: "s1", name: "Neu", stageKind: "offen", color: "#000", winProbability: 10 },
projectCount: s1Cards.length,
aggregateValue: opts.empty ? null : "10000.00",
aggregateVisible: !opts.empty,
cards: s1Cards,
},
{ stage: { id: "s4", name: "In Arbeit", stageKind: "offen", color: "#00a", winProbability: 40 }, projectCount: 0, aggregateValue: null, aggregateVisible: false, cards: [] },
{ stage: { id: "s2", name: "Gewonnen", stageKind: "gewonnen", color: "#0a0", winProbability: 100 }, projectCount: 0, aggregateValue: null, aggregateVisible: false, cards: [] },
{ stage: { id: "s3", name: "Verloren", stageKind: "verloren", color: "#a00", winProbability: 0 }, projectCount: 0, aggregateValue: null, aggregateVisible: false, cards: [] },
],
generatedAt: "2026-07-08T12:00:00.000Z",
},
lostReasons: [{ id: "lr1", name: "Preis" }],
ownerLabels: new Map([["u1", "Rita Richter"]]),
buildDetailHref: (id) => `/acme/projects/${id}`,
sseHref: "/acme/stream",
perms: { canWrite: true, canChangeStage: true, canAdmin: opts.canAdmin ?? false, canDelete: opts.canDelete ?? false },
});
if (vm.status !== "ready") throw new Error("fixture not ready");
return vm.data;
}
function renderPage(
over: Partial<PipelineKanbanActions> = {},
opts: { showDemoToggle?: boolean; empty?: boolean; manyInS1?: boolean; q?: string; onlyMine?: boolean; stuckP1?: boolean; canAdmin?: boolean; canDelete?: boolean; undoP1?: boolean; canFilterByValue?: boolean; selectedOwners?: string[]; hasUnassigned?: boolean; tags?: { id: string; name: string; farbe: string }[]; selectedTagIds?: string[]; cardTags?: { id: string; name: string; farbe: string }[]; handover?: PipelineHandoverVM | null } = {},
) {
const actions: PipelineKanbanActions = {
onShowList: vi.fn(),
onOpenProject: vi.fn(),
onManageBoard: vi.fn(),
onSwitchPipeline: vi.fn(),
onToggleOnlyMine: vi.fn(),
onSearch: vi.fn(),
onToggleFacet: vi.fn(),
onRemoveChip: vi.fn(),
onResetFilters: vi.fn(),
onPeriodRangeChange: vi.fn(),
onToggleDemo: vi.fn(),
onMove: vi.fn(),
onBulkMove: vi.fn(),
onCreateProject: vi.fn(),
onDuplicate: vi.fn(),
onArchive: vi.fn(),
onUndoStage: vi.fn(),
onRedoStage: vi.fn(),
onMoveToPipeline: vi.fn(),
...over,
};
render(
<PipelineKanbanPage
data={boardData({
empty: opts.empty,
manyInS1: opts.manyInS1,
stuckP1: opts.stuckP1,
canAdmin: opts.canAdmin,
canDelete: opts.canDelete,
undoP1: opts.undoP1,
redoP1: opts.redoP1,
cardTags: opts.cardTags,
})}
onlyMine={opts.onlyMine ?? false}
q={opts.q ?? ""}
facets={buildBoardFacetsVM({
assignees: [{ userId: "u1", label: "Ada Lovelace" }],
hasUnassigned: opts.hasUnassigned ?? true,
tags: opts.tags ?? [],
selected: { owners: opts.selectedOwners ?? [], customerTypes: [], tagIds: opts.selectedTagIds ?? [], period: null, valueBands: [] },
onlyMine: opts.onlyMine ?? false,
q: opts.q ?? "",
canFilterByValue: opts.canFilterByValue ?? true,
})}
periodFrom=""
periodTo=""
includeDemoData={false}
showDemoToggle={opts.showDemoToggle ?? true}
submitting={false}
handover={opts.handover ?? null}
actions={actions}
/>
);
return actions;
}
describe("PipelineKanbanPage", () => {
it("renders columns and a project card", () => {
renderPage();
expect(screen.getAllByText("Neu").length).toBeGreaterThan(0);
expect(screen.getAllByText("Gewonnen").length).toBeGreaterThan(0);
expect(screen.getAllByText("Dach Nord").length).toBeGreaterThan(0);
expect(byUiId("ui.projects.board")).toBeTruthy();
expect(byUiId("ui.projects.board").getAttribute("data-sse-href")).toBe("/acme/stream");
expect((document.body.textContent ?? "").replace(/[\u00a0\u202f]/g, " ").match(/10\.000,00 €/g)).toHaveLength(2);
const card = byUiId("ui.projects.board.card.p1");
const dragHandle = byUiId("stub.drag.p1");
expect(card.contains(dragHandle)).toBe(true);
expect(dragHandle.textContent).toBe("");
expect(screen.getByRole("link", { name: "Dach Nord" }).getAttribute("href")).toBe("/acme/projects/p1");
});
it("keeps search typing local and commits once on Enter", () => {
const actions = renderPage();
const input = byUiId("ui.projects.board.search");
fireEvent.change(input, { target: { value: " Dach " } });
expect(actions.onSearch).not.toHaveBeenCalled();
fireEvent.keyDown(input, { key: "Enter" });
expect(actions.onSearch).toHaveBeenCalledOnce();
expect(actions.onSearch).toHaveBeenCalledWith("Dach");
});
it("toggles the demo-data checkbox through onToggleDemo", () => {
const actions = renderPage();
fireEvent.click(byUiId("ui.projects.board.demo"));
expect(actions.onToggleDemo).toHaveBeenCalledWith(true);
});
it("hides the demo-data checkbox when the demo UI is disabled (production)", () => {
renderPage({}, { showDemoToggle: false });
expect(document.querySelector('[data-ui-id="ui.projects.board.demo"]')).toBeNull();
});
it("creates a project through the quick-create dialog", () => {
const actions = renderPage();
fireEvent.click(byUiId("ui.projects.board.new"));
fireEvent.change(byUiId("ui.projects.board.createDialog.name"), { target: { value: "Neubau" } });
fireEvent.click(byUiId("ui.projects.board.createDialog.confirm"));
expect(actions.onCreateProject).toHaveBeenCalledWith({ projektname: "Neubau", potenziellerAuftragswert: "" });
});
it("submits directly on a drag into an open column (no dialog)", () => {
const actions = renderPage();
fireEvent.click(byUiId("stub.move.p1.s4"));
expect(actions.onMove).toHaveBeenCalledWith("p1", "s4");
expect(byUiId("ui.projects.board.moveDialog")).toBeFalsy();
});
it("opens the won confirm dialog on a drag into a won column, then submits on confirm", () => {
const actions = renderPage();
fireEvent.click(byUiId("stub.move.p1.s2"));
// Dialog opened, nothing submitted yet.
expect(actions.onMove).not.toHaveBeenCalled();
const confirm = byUiId("ui.projects.board.moveDialog.confirm");
expect(confirm).toBeTruthy();
expect(confirm.textContent).toContain("projects.actions.confirmWon");
fireEvent.click(confirm);
expect(actions.onMove).toHaveBeenCalledWith("p1", "s2");
});
it("blocks the lost move until a reason is chosen and says why (M01)", () => {
// Davids M01 shows a placeholder, not a preselected reason: the choice is
// deliberate. A blind confirm must therefore not record a reason nobody
// picked, and it must not look like a dead button either.
const actions = renderPage();
fireEvent.click(byUiId("stub.move.p1.s3"));
expect(actions.onMove).not.toHaveBeenCalled();
const confirm = byUiId("ui.projects.board.moveDialog.confirm");
expect(confirm.textContent).toContain("projects.actions.confirmLost");
fireEvent.click(confirm);
expect(actions.onMove).not.toHaveBeenCalled();
expect(byUiId("ui.projects.board.moveDialog.reason.errorText").textContent).toBe("projects.lostDialog.reasonRequired");
const reason = byUiId("ui.projects.board.moveDialog.reason.native") as HTMLSelectElement;
fireEvent.change(reason, { target: { value: "lr1" } });
fireEvent.click(confirm);
expect(actions.onMove).toHaveBeenCalledWith("p1", "s3", "lr1", undefined);
});
it("passes the optional M01 note along with the reason", () => {
const actions = renderPage();
fireEvent.click(byUiId("stub.move.p1.s3"));
fireEvent.change(byUiId("ui.projects.board.moveDialog.reason.native"), { target: { value: "lr1" } });
const note = byUiId("ui.projects.board.moveDialog.note") as HTMLTextAreaElement;
fireEvent.change(note, { target: { value: " Kunde hat intern entschieden. " } });
fireEvent.click(byUiId("ui.projects.board.moveDialog.confirm"));
expect(actions.onMove).toHaveBeenCalledWith("p1", "s3", "lr1", "Kunde hat intern entschieden.");
});
it("shows the 24h undo hint so the loss does not read as final", () => {
renderPage();
fireEvent.click(byUiId("stub.move.p1.s3"));
expect(byUiId("ui.projects.board.moveDialog").textContent).toContain("projects.lostDialog.undoHint");
});
it("offers M03 undo only inside the undo window and routes it", () => {
// The service clears undoStageChangeUntil once the window has passed, so a
// present value is the whole condition — no clock arithmetic in the screen.
const actions = renderPage({}, { undoP1: true });
fireEvent.contextMenu(byUiId("ui.projects.board.card.p1"));
fireEvent.click(byUiId("ui.projects.board.contextMenu.p1.undo"));
expect(actions.onUndoStage).toHaveBeenCalledWith("p1");
});
it("hides M03 undo when nothing can be undone", () => {
renderPage();
fireEvent.contextMenu(byUiId("ui.projects.board.card.p1"));
expect(byUiId("ui.projects.board.contextMenu.p1.undo")).toBeNull();
});
it("offers M03 redo only while an undone move can be re-applied and routes it", () => {
// Same shape as undo: the service keeps the redo pointer and clears it on
// the next forward move, so the screen only asks whether one is there.
const actions = renderPage({}, { redoP1: true });
fireEvent.contextMenu(byUiId("ui.projects.board.card.p1"));
fireEvent.click(byUiId("ui.projects.board.contextMenu.p1.redo"));
expect(actions.onRedoStage).toHaveBeenCalledWith("p1");
});
it("offers M03 board switching for every board except the current one", () => {
const actions = renderPage();
fireEvent.contextMenu(byUiId("ui.projects.board.card.p1"));
// The board being looked at is not a move target.
expect(byUiId("ui.projects.board.contextMenu.p1.moveToBoard.pl1")).toBeNull();
fireEvent.click(byUiId("ui.projects.board.contextMenu.p1.moveToBoard.pl2"));
expect(actions.onMoveToPipeline).toHaveBeenCalledWith("p1", "pl2");
});
it("hides M03 redo when nothing was undone", () => {
renderPage();
fireEvent.contextMenu(byUiId("ui.projects.board.card.p1"));
expect(byUiId("ui.projects.board.contextMenu.p1.redo")).toBeNull();
});
it("shows the locked-value state instead of an amount when the value is masked", () => {
renderPage();
const visible = byUiId("ui.projects.board.card.p1");
expect(visible.textContent).toContain("10.000,00");
const locked = byUiId("ui.projects.board.card.p2");
expect(locked.textContent).toContain("projects.board.valueLocked");
});
it("renders the owner as an avatar and the deadline as the end of the card date range", () => {
// Davids ProjectCard (Subframe 2026-07-28) replaced the footer row: the
// assignee is an avatar (no photo source, so initials) and the deadline is
// the right-hand end of the start/end range, in day.month form.
renderPage();
const owner = byUiId("ui.projects.board.owner.p1");
expect(owner.textContent).toBe("RR");
const card = byUiId("ui.projects.board.card.p1");
expect(card.textContent).toMatch(/30\.0?7\./u);
// A card without a deadline shows no date at all rather than an open range.
expect(byUiId("ui.projects.board.card.p2").textContent).not.toMatch(/\d{2}\.\d{2}\./u);
});
it("renders the S01 card subtitle, type tag and appointment pill", () => {
renderPage();
const card = byUiId("ui.projects.board.card.p1");
expect(card.textContent).toContain("Fam. Bergmann \u00b7 Freiburg");
expect(byUiId("ui.projects.board.typ.p1").textContent).toBe("PV / Solar");
expect(card.textContent).toContain("projects.board.nextAppointment");
// Start of the range comes from startDatum, formatted day.month like the export.
expect(card.textContent).toMatch(/14\.0?7\./u);
// A card without any of it stays clean instead of rendering empty chrome.
const bare = byUiId("ui.projects.board.card.p2");
expect(bare.textContent).not.toContain("projects.board.nextAppointment");
expect(byUiId("ui.projects.board.typ.p2")).toBeNull();
});
it("shows a dashed stage-aware placeholder in every empty column", () => {
renderPage();
for (const stageId of ["s4", "s2", "s3"]) {
const placeholder = byUiId(`ui.projects.board.column.empty.${stageId}`);
expect(placeholder).toBeTruthy();
expect(placeholder.textContent).toContain("projects.board.columnEmpty.title");
}
expect(byUiId("ui.projects.board.column.empty.s1")).toBeFalsy();
});
it("shows the filtered empty banner with reset + create when a filter yields zero cards", () => {
const actions = renderPage({}, { empty: true, q: "dach" });
expect(byUiId("ui.projects.board.emptyFiltered")).toBeTruthy();
expect(byUiId("ui.projects.board.empty")).toBeFalsy();
fireEvent.click(byUiId("ui.projects.board.emptyFiltered.reset"));
// One navigation drops every filter — search, only-mine and all facets.
expect(actions.onResetFilters).toHaveBeenCalled();
fireEvent.click(byUiId("ui.projects.board.emptyFiltered.create"));
expect(byUiId("ui.projects.board.createDialog")).toBeTruthy();
});
it("keeps the kanban columns under the notice when a filter empties the board", () => {
renderPage({}, { empty: true, q: "dach" });
// S01a: the message sits above the board, it does not replace it — the
// stages a project would land in stay visible.
expect(byUiId("ui.projects.board.columns")).toBeTruthy();
expect(byUiId("stub.col.s1")).toBeTruthy();
});
it("shows the plain empty notice above the board when the board is empty and unfiltered", () => {
renderPage({}, { empty: true });
expect(byUiId("ui.projects.board.empty")).toBeTruthy();
expect(byUiId("ui.projects.board.emptyFiltered")).toBeFalsy();
// Nothing to reset without a filter, but the board itself still renders.
expect(byUiId("ui.projects.board.emptyFiltered.reset")).toBeFalsy();
expect(byUiId("ui.projects.board.columns")).toBeTruthy();
});
it("maps aggregate visibility to the column sum mode", () => {
renderPage();
expect(byUiId("stub.col.s1").getAttribute("data-sum-mode")).toBe("visible");
expect(byUiId("stub.col.s4").getAttribute("data-sum-mode")).toBe("locked");
});
it("keeps every stage a single card column, even when it overflows", () => {
renderPage({}, { manyInS1: true });
expect(byUiId("stub.col.s1").getAttribute("data-two-column")).toBe("undefined");
expect(byUiId("stub.col.s4").getAttribute("data-two-column")).toBe("undefined");
expect(byUiId("ui.projects.board.twoColumnHint")).toBeFalsy();
});
it("keeps the staleness chip off the card, even past the 7-day threshold", () => {
// Davids S01 card carries the tag catalogue and the project type, nothing
// else; the VM still computes stuckDays for other readers.
renderPage({}, { stuckP1: true });
expect(byUiId("ui.projects.board.stuckDays.p1")).toBeFalsy();
expect(document.body.textContent).not.toContain("projects.board.stuckDays");
});
it("offers duplicate in the context menu when canWrite and routes it", () => {
const actions = renderPage();
fireEvent.contextMenu(byUiId("ui.projects.board.card.p1"));
const duplicate = byUiId("ui.projects.board.contextMenu.p1.duplicate");
expect(duplicate).toBeTruthy();
fireEvent.click(duplicate);
expect(actions.onDuplicate).toHaveBeenCalledWith("p1");
});
it("hides duplicate when the callback is not wired (no dead buttons)", () => {
renderPage({ onDuplicate: undefined });
fireEvent.contextMenu(byUiId("ui.projects.board.card.p1"));
expect(byUiId("ui.projects.board.contextMenu.p1")).toBeTruthy();
expect(byUiId("ui.projects.board.contextMenu.p1.duplicate")).toBeFalsy();
});
it("hides archive without the delete permission", () => {
renderPage();
fireEvent.contextMenu(byUiId("ui.projects.board.card.p1"));
expect(byUiId("ui.projects.board.contextMenu.p1")).toBeTruthy();
expect(byUiId("ui.projects.board.contextMenu.p1.archive")).toBeFalsy();
});
it("archives only after the confirm dialog is confirmed", () => {
const actions = renderPage({}, { canDelete: true });
fireEvent.contextMenu(byUiId("ui.projects.board.card.p1"));
const archiveItem = byUiId("ui.projects.board.contextMenu.p1.archive");
expect(archiveItem).toBeTruthy();
fireEvent.click(archiveItem);
// Dialog opened, nothing submitted yet.
expect(actions.onArchive).not.toHaveBeenCalled();
const confirm = byUiId("ui.projects.board.archiveDialog.confirm");
expect(confirm).toBeTruthy();
fireEvent.click(confirm);
expect(actions.onArchive).toHaveBeenCalledWith("p1");
expect(byUiId("ui.projects.board.archiveDialog")).toBeFalsy();
});
it("does not archive when the confirm dialog is cancelled", () => {
const actions = renderPage({}, { canDelete: true });
fireEvent.contextMenu(byUiId("ui.projects.board.card.p1"));
fireEvent.click(byUiId("ui.projects.board.contextMenu.p1.archive"));
fireEvent.click(screen.getByText("projects.actions.cancel"));
expect(actions.onArchive).not.toHaveBeenCalled();
expect(byUiId("ui.projects.board.archiveDialog")).toBeFalsy();
});
it("opens a right-click context menu with open / move / settings entries and routes a move", () => {
const actions = renderPage();
fireEvent.contextMenu(byUiId("ui.projects.board.card.p1"));
expect(byUiId("ui.projects.board.contextMenu.p1")).toBeTruthy();
expect(byUiId("ui.projects.board.contextMenu.p1.open")).toBeTruthy();
// Own column (s1) is not offered as a move target; admin entry hidden (canAdmin=false fixture).
expect(byUiId("ui.projects.board.contextMenu.p1.moveTo.s1")).toBeFalsy();
expect(byUiId("ui.projects.board.contextMenu.p1.settings")).toBeFalsy();
const moveItem = byUiId("ui.projects.board.contextMenu.p1.moveTo.s4");
expect(moveItem).toBeTruthy();
fireEvent.click(moveItem);
expect(actions.onMove).toHaveBeenCalledWith("p1", "s4");
});
it("routes the card context-menu open action without a document reload", () => {
const actions = renderPage();
fireEvent.contextMenu(byUiId("ui.projects.board.card.p1"));
fireEvent.click(byUiId("ui.projects.board.contextMenu.p1.open"));
expect(actions.onOpenProject).toHaveBeenCalledWith("/acme/projects/p1");
});
it("keeps board settings in the card context menu only and switches views from the header", () => {
const actions = renderPage();
// The header carries the view switch and the create CTA — board settings are
// reachable from the card context menu, not from a header button.
expect(byUiId("ui.projects.board.viewToggle")).toBeTruthy();
expect(byUiId("ui.projects.board.new")).toBeTruthy();
expect(byUiId("ui.projects.board.manage")).toBeFalsy();
// No CSV button in the head — the export is not part of Davids S01.
expect(byUiId("ui.projects.board.export")).toBeFalsy();
fireEvent.click(byUiId("ui.projects.board.viewToggle.list"));
expect(actions.onShowList).toHaveBeenCalled();
});
it("shows every configured stage until the column picker hides one", () => {
renderPage();
for (const stageId of ["s1", "s2", "s3", "s4"]) expect(byUiId(`stub.col.${stageId}`)).toBeTruthy();
fireEvent.click(byUiId("ui.projects.board.columnPicker.s3"));
expect(byUiId("stub.col.s3")).toBeFalsy();
// Hiding a column does not take the stage off the card context menu (see the
// move-target test), so losing a project never depends on showing it.
fireEvent.click(byUiId("ui.projects.board.columnPicker.s3"));
expect(byUiId("stub.col.s3")).toBeTruthy();
});
it("offers board settings in the header only for an admin", () => {
const actions = renderPage({}, { canAdmin: true });
const button = byUiId("ui.projects.board.settings");
expect(byUiId("ui.projects.board.header").contains(button)).toBe(true);
fireEvent.click(button);
expect(actions.onManageBoard).toHaveBeenCalled();
renderPage();
expect(document.querySelectorAll('[data-ui-id="ui.projects.board.settings"]').length).toBe(1);
});
it("puts the board switcher in the header and the search into the filter bar", () => {
const actions = renderPage();
// S01: the switcher is a header chip, not a toolbar select; the free-text
// search moved into the filter bar next to the facets.
const switcher = byUiId("ui.projects.board.switcher");
expect(byUiId("ui.projects.board.header").contains(switcher)).toBe(true);
expect(byUiId("ui.projects.board.filterBar").contains(byUiId("ui.projects.board.search"))).toBe(true);
fireEvent.click(switcher);
fireEvent.click(byUiId("ui.projects.board.switcher.pl2"));
expect(actions.onSwitchPipeline).toHaveBeenCalledWith("pl2");
});
it("renders one facet button per available facet and toggles an option", () => {
const actions = renderPage();
for (const facet of ["owner", "customerType", "period", "value"]) {
expect(byUiId(`ui.projects.board.facet.${facet}`)).toBeTruthy();
}
fireEvent.click(byUiId("ui.projects.board.facet.owner"));
fireEvent.click(byUiId("ui.projects.board.facet.owner.u1"));
expect(actions.onToggleFacet).toHaveBeenCalledWith("owner", "u1");
});
it("hides the value facet from a viewer without tenant-wide volume access", () => {
renderPage({}, { canFilterByValue: false });
expect(byUiId("ui.projects.board.facet.owner")).toBeTruthy();
// Picking a band would reveal the very number the card gate withholds.
expect(byUiId("ui.projects.board.facet.value")).toBeFalsy();
});
it("keeps a selected unassigned bucket visible even when no project is unassigned", () => {
renderPage({}, { hasUnassigned: false, selectedOwners: ["none"] });
// Dropping the option would leave the filter active with no chip to remove.
expect(byUiId("ui.projects.board.filterChip.owner.none")).toBeTruthy();
});
it("shows one removable chip per active filter", () => {
const actions = renderPage({}, { onlyMine: true, selectedOwners: ["u1"] });
expect(byUiId("ui.projects.board.filterChip.owner.u1")).toBeTruthy();
expect(byUiId("ui.projects.board.filterChip.onlyMine.1")).toBeTruthy();
fireEvent.click(byUiId("ui.projects.board.filterChip.onlyMine.1.remove"));
expect(actions.onRemoveChip).toHaveBeenCalledWith(expect.objectContaining({ facet: "onlyMine" }));
});
it("shows the project tags as chips on the card and offers them as a facet", () => {
renderPage(
{},
{
cardTags: [{ id: "t1", name: "PV / Solar", farbe: "yellow-subtle" }],
tags: [{ id: "t1", name: "PV / Solar", farbe: "yellow-subtle" }],
}
);
expect(byUiId("ui.projects.board.tag.p1.t1").textContent).toContain("PV / Solar");
expect(byUiId("ui.projects.board.facet.tags")).toBeTruthy();
});
});
// --- M04 handover ---------------------------------------------------------
// D-P8: the move is the trigger ("Erreicht eine Karte die letzte Stage […],
// oeffnet sich M04 automatisch"). The board therefore has to open the dialog on
// what the move handed back — leaving it to the detail page would mean the
// board offers nothing at the moment the flow says it should.
const handoverVM = buildPipelineHandoverVM({
projectId: "p1",
projectName: "Projekt Eins",
fromPipelineId: "pipe1",
fromPipelineName: "Vertrieb",
toPipelineId: "pipe2",
toPipelineName: "Auftrag",
toStageId: "s-neu",
toStageName: "Neu",
candidates: [{ id: "note_1", kind: "notiz", title: "BAFA-Antrag läuft", atIso: null, defaultSelected: true }],
});
describe("PipelineKanbanPage — M04 handover", () => {
it("stays out of the way while no move has offered one", () => {
renderPage();
expect(document.querySelector("[data-ui-id='ui.projects.handover']")).toBeNull();
});
it("opens the dialog on the payload the move handed back", () => {
renderPage({ onHandover: vi.fn() }, { handover: handoverVM });
const dialog = document.querySelector("[data-ui-id='ui.projects.handover']") as HTMLElement;
expect(dialog).not.toBeNull();
expect(dialog.textContent).toContain("Vertrieb → Auftrag");
});
it("commits the handover with the project, its board and the ticked records", () => {
const onHandover = vi.fn();
renderPage({ onHandover }, { handover: handoverVM });
fireEvent.click(document.querySelector("[data-ui-id='ui.projects.handover.confirm']")!);
expect(onHandover).toHaveBeenCalledWith("p1", "pipe1", [{ kind: "notiz", sourceId: "note_1" }]);
});
it("keeps the dialog shut once it is dismissed, so the board is usable again", () => {
renderPage({ onHandover: vi.fn() }, { handover: handoverVM });
fireEvent.click(document.querySelector("[data-ui-id='ui.projects.handover.cancel']")!);
expect(document.querySelector("[data-ui-id='ui.projects.handover']")).toBeNull();
});
});