diff --git a/src/test/app/(protected)/workorders/dispatch-checklist-section.test.tsx b/src/test/app/(protected)/workorders/dispatch-checklist-section.test.tsx new file mode 100644 index 00000000..194aff65 --- /dev/null +++ b/src/test/app/(protected)/workorders/dispatch-checklist-section.test.tsx @@ -0,0 +1,58 @@ +import { render, screen } from "@testing-library/react"; +import { describe, expect, it, vi } from "vitest"; +import { DispatchChecklistSection } from "@/app/(protected)/workorders/_components/dispatch/dispatch-detail/dispatch-checklist-section"; +import type { DispatchChecklistItem } from "@/domain/work-orders/types/work-order"; + +const VIEWER_NAME = "Alice Viewer"; + +function renderChecklist(items: DispatchChecklistItem[]) { + return render( + , + ); +} + +describe("DispatchChecklistSection completedBy provenance", () => { + it.each([ + { label: "null", completedBy: null }, + { label: "empty", completedBy: "" }, + { label: "whitespace", completedBy: " " }, + ])("shows Unknown (never the viewer) when completedBy is $label", ({ completedBy }) => { + renderChecklist([ + { + id: 1, + itemText: "Verify site access", + isCompleted: true, + completedBy, + completedAt: "2026-07-01T15:30:00Z", + }, + ]); + + expect(screen.getByText(/Unknown/)).toBeInTheDocument(); + expect(screen.queryByText(VIEWER_NAME)).not.toBeInTheDocument(); + expect(screen.queryByText(/Alice/)).not.toBeInTheDocument(); + }); + + it("renders the recorded completedBy when present", () => { + renderChecklist([ + { + id: 2, + itemText: "Collect photos", + isCompleted: true, + completedBy: "Jordan Tech", + completedAt: "2026-07-01T15:30:00Z", + }, + ]); + + expect(screen.getByText(/Jordan Tech/)).toBeInTheDocument(); + expect(screen.queryByText(/Unknown/)).not.toBeInTheDocument(); + expect(screen.queryByText(VIEWER_NAME)).not.toBeInTheDocument(); + }); +});