test(work-orders): cover missing checklist completedBy provenance

Regression: null/empty/whitespace completedBy shows Unknown, never the viewer.
This commit is contained in:
Arthur Bassi 2026-07-22 13:28:12 -03:00
parent 40c6e3cb3d
commit 01351b3f33

View file

@ -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(
<DispatchChecklistSection
items={items}
isLocked={false}
isUpdating={false}
newItem=""
onNewItemChange={vi.fn()}
onToggleItem={vi.fn()}
onAddItem={vi.fn()}
/>,
);
}
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();
});
});