mirror of
https://github.com/Sea-Haven-Industries/shoc-frontend-new.git
synced 2026-09-30 10:23:11 +00:00
test(work-orders): cover missing checklist completedBy provenance
Regression: null/empty/whitespace completedBy shows Unknown, never the viewer.
This commit is contained in:
parent
40c6e3cb3d
commit
01351b3f33
1 changed files with 58 additions and 0 deletions
|
|
@ -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();
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Reference in a new issue