mirror of
https://github.com/Sea-Haven-Industries/shoc-frontend-new.git
synced 2026-10-01 20:13:12 +00:00
test(work-orders): align table mutations test with updateCompletedDate
Assert updateCompletedDate instead of getById before EditWorkorder.
This commit is contained in:
parent
96f3daf20c
commit
27c7c8df55
1 changed files with 18 additions and 30 deletions
|
|
@ -2,17 +2,19 @@ import type { ReactNode } from "react";
|
|||
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
||||
import { act, renderHook, waitFor } from "@testing-library/react";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import type { WorkOrderDetail, WorkOrderFormValues } from "@/domain/work-orders/types/work-order";
|
||||
import type { WorkOrderDetail } from "@/domain/work-orders/types/work-order";
|
||||
import type { WorkOrderTableRow } from "@/domain/work-orders/types/work-order-table-row";
|
||||
|
||||
const getById = vi.fn();
|
||||
const update = vi.fn();
|
||||
const updateCompletedDate = vi.fn();
|
||||
const patchBoardField = vi.fn();
|
||||
|
||||
vi.mock("@/domain/work-orders/api/work-orders-api", () => ({
|
||||
workOrdersApi: {
|
||||
getById: (...args: unknown[]) => getById(...args),
|
||||
update: (...args: unknown[]) => update(...args),
|
||||
updateCompletedDate: (...args: unknown[]) => updateCompletedDate(...args),
|
||||
patchBoardField: (...args: unknown[]) => patchBoardField(...args),
|
||||
},
|
||||
}));
|
||||
|
|
@ -117,6 +119,7 @@ describe("useWorkOrderTableMutations completion-doc persistence", () => {
|
|||
beforeEach(() => {
|
||||
getById.mockReset();
|
||||
update.mockReset();
|
||||
updateCompletedDate.mockReset();
|
||||
patchBoardField.mockReset();
|
||||
serverState = { ...BASE_DETAIL };
|
||||
rowState = { ...BASE_ROW };
|
||||
|
|
@ -144,24 +147,11 @@ describe("useWorkOrderTableMutations completion-doc persistence", () => {
|
|||
},
|
||||
);
|
||||
|
||||
getById.mockImplementation(async () => {
|
||||
events.push("getById:start");
|
||||
await delay(15);
|
||||
events.push("getById:end");
|
||||
return { ...serverState };
|
||||
});
|
||||
|
||||
update.mockImplementation(async (_id: unknown, values: WorkOrderFormValues) => {
|
||||
events.push("update:start");
|
||||
updateCompletedDate.mockImplementation(async (_id: unknown, completedDate: string) => {
|
||||
events.push("updateCompletedDate:start");
|
||||
await delay(5);
|
||||
serverState = {
|
||||
...serverState,
|
||||
scheduledDate: values.scheduledDate,
|
||||
completedDate: values.completedDate,
|
||||
status: values.status,
|
||||
};
|
||||
events.push("update:end");
|
||||
return { ...serverState };
|
||||
serverState = { ...serverState, completedDate };
|
||||
events.push("updateCompletedDate:end");
|
||||
});
|
||||
});
|
||||
|
||||
|
|
@ -189,10 +179,12 @@ describe("useWorkOrderTableMutations completion-doc persistence", () => {
|
|||
workOrderVersion: "AAAAAAA=",
|
||||
});
|
||||
expect(update).not.toHaveBeenCalled();
|
||||
expect(updateCompletedDate).not.toHaveBeenCalled();
|
||||
expect(getById).not.toHaveBeenCalled();
|
||||
expect(serverState.docStatus).toBe("NN");
|
||||
});
|
||||
|
||||
it("serializes board docStatus and completedDate full-update without racing", async () => {
|
||||
it("serializes board docStatus and completedDate without racing or GetWorkorderById", async () => {
|
||||
const onPatch = vi.fn();
|
||||
const { result } = renderHook(
|
||||
() =>
|
||||
|
|
@ -209,27 +201,23 @@ describe("useWorkOrderTableMutations completion-doc persistence", () => {
|
|||
result.current.patchField(42, { completedDate: "2026-07-20" });
|
||||
});
|
||||
|
||||
await waitFor(() => expect(events).toContain("update:end"));
|
||||
await waitFor(() => expect(events).toContain("updateCompletedDate:end"));
|
||||
await waitFor(() => expect(events).toContain("boardPatch:end"));
|
||||
|
||||
expect(events).toEqual([
|
||||
"boardPatch:start",
|
||||
"boardPatch:end",
|
||||
"getById:start",
|
||||
"getById:end",
|
||||
"update:start",
|
||||
"update:end",
|
||||
"updateCompletedDate:start",
|
||||
"updateCompletedDate:end",
|
||||
]);
|
||||
|
||||
expect(getById).not.toHaveBeenCalled();
|
||||
expect(update).not.toHaveBeenCalled();
|
||||
expect(updateCompletedDate).toHaveBeenCalledWith(42, "2026-07-20");
|
||||
|
||||
expect(serverState.docStatus).toBe("Yes");
|
||||
expect(serverState.completedDate).toBe("2026-07-20");
|
||||
expect(serverState.scheduledDate).toBe(BASE_DETAIL.scheduledDate);
|
||||
expect(serverState.status).toBe(BASE_DETAIL.status);
|
||||
|
||||
for (const call of update.mock.calls) {
|
||||
const values = call[1] as WorkOrderFormValues;
|
||||
expect(values.scheduledDate).toBe(BASE_DETAIL.scheduledDate);
|
||||
expect(values.status).not.toBe("Done");
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue