import { describe, it, expect, afterEach } from "vitest"; import { render, screen, cleanup } from "@testing-library/react"; import type { TaskContextDTO } from "@/lib/api/domains/office-task-context-api"; import { TaskDetailContextPanel } from "./task-detail-context-panel"; afterEach(cleanup); const baseContext = (overrides: Partial = {}): TaskContextDTO => ({ task: { id: "task-1", identifier: "KAN-1", title: "Implement endpoint", state: "in_progress", workspace_id: "ws-1", }, children: [], siblings: [], blockers: [], blocked_by: [], available_documents: [], ...overrides, }); const parentTask: TaskRefForTest = { id: "parent", identifier: "KAN-2", title: "Plan", state: "completed", workspace_id: "ws-1", }; type TaskRefForTest = { id: string; identifier: string; title: string; state: string; workspace_id: string; parent_id?: string; }; describe("TaskDetailContextPanel", () => { it("renders nothing when context is null", () => { const { container } = render(); expect(container.firstChild).toBeNull(); }); it("renders nothing when context has no relations / docs / workspace", () => { const { container } = render(); expect(container.firstChild).toBeNull(); }); it("renders parent and siblings", () => { render( , ); expect(screen.getByText("Related tasks")).toBeTruthy(); expect(screen.getByText("KAN-2 Plan")).toBeTruthy(); expect(screen.getByText("KAN-3 Spec")).toBeTruthy(); }); it("renders document references with key + title but no body content", () => { render( , ); expect(screen.getByText("Documents available")).toBeTruthy(); expect(screen.getByText("spec")).toBeTruthy(); expect(screen.getByText(/Architecture spec/)).toBeTruthy(); }); it("renders the shared-workspace badge with member count", () => { render( , ); expect(screen.getByText(/Shared workspace ยท 2 members/)).toBeTruthy(); expect(screen.getByTestId("workspace-mode-label").textContent).toContain("inherit_parent"); expect(screen.getByText("/wt/abc")).toBeTruthy(); }); it("renders the requires-configuration banner when workspace_status flips", () => { render( , ); expect(screen.getByTestId("task-detail-context-panel-requires-config")).toBeTruthy(); }); });