mirror of
https://github.com/Sea-Haven-Industries/shoc-frontend-new.git
synced 2026-10-02 12:03:12 +00:00
test(work-orders): assert CompDoc Generate skips Yes when date patch fails
This commit is contained in:
parent
65d75ca372
commit
6481d9ce86
1 changed files with 31 additions and 3 deletions
|
|
@ -120,14 +120,14 @@ describe("CompDocDialog Save Draft / Generate completion contract", () => {
|
|||
expect(onDateCompletedChange).toHaveBeenCalledWith("2026-07-15");
|
||||
});
|
||||
expect(onSave).toHaveBeenCalledWith(expect.any(Object), "No");
|
||||
expect(patches).toEqual([{ docStatus: "No" }, { completedDate: "2026-07-15" }]);
|
||||
expect(patches).toEqual([{ completedDate: "2026-07-15" }, { docStatus: "No" }]);
|
||||
expect(patches.some((patch) => "scheduledOn" in patch)).toBe(false);
|
||||
expect(patches.some((patch) => patch.status === "Completed")).toBe(false);
|
||||
expect(row.scheduledOn).toBe(SCHEDULED_ON);
|
||||
expect(row.status).toBe("Scheduled");
|
||||
});
|
||||
|
||||
it("Generate emits completedDate and doc Yes without auto-setting lifecycle Completed", async () => {
|
||||
it("Generate emits completedDate before doc Yes without auto-setting lifecycle Completed", async () => {
|
||||
const row = baseRow({ completedDate: "2026-07-01" });
|
||||
const { patches } = renderDialog(row);
|
||||
|
||||
|
|
@ -141,10 +141,38 @@ describe("CompDocDialog Save Draft / Generate completion contract", () => {
|
|||
expect.objectContaining({ generatedAt: expect.any(String) }),
|
||||
"Yes",
|
||||
);
|
||||
expect(patches).toEqual([{ docStatus: "Yes" }, { completedDate: "2026-07-20" }]);
|
||||
expect(patches).toEqual([{ completedDate: "2026-07-20" }, { docStatus: "Yes" }]);
|
||||
expect(patches.some((patch) => "scheduledOn" in patch)).toBe(false);
|
||||
expect(patches.some((patch) => patch.status === "Completed")).toBe(false);
|
||||
expect(row.scheduledOn).toBe(SCHEDULED_ON);
|
||||
expect(row.status).toBe("Scheduled");
|
||||
});
|
||||
|
||||
it("Generate does not write docStatus Yes when completedDate persistence fails", async () => {
|
||||
const row = baseRow({ completedDate: "2026-07-01" });
|
||||
const client = new QueryClient({
|
||||
defaultOptions: { queries: { retry: false }, mutations: { retry: false } },
|
||||
});
|
||||
onDateCompletedChange.mockRejectedValueOnce(new Error("conflict"));
|
||||
|
||||
render(
|
||||
<QueryClientProvider client={client}>
|
||||
<CompDocDialog
|
||||
row={row}
|
||||
open
|
||||
onOpenChange={vi.fn()}
|
||||
onSave={onSave}
|
||||
onDateCompletedChange={onDateCompletedChange}
|
||||
/>
|
||||
</QueryClientProvider>,
|
||||
);
|
||||
|
||||
changeDateCompleted("2026-07-20");
|
||||
fireEvent.click(screen.getByRole("button", { name: /^generate$/i }));
|
||||
|
||||
await waitFor(() => {
|
||||
expect(onDateCompletedChange).toHaveBeenCalledWith("2026-07-20");
|
||||
});
|
||||
expect(onSave).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue