mirror of
https://github.com/Sea-Haven-Industries/shoc-frontend-new.git
synced 2026-10-07 16:19:01 +00:00
fix(work-orders): restore patchField options and harden mutations tests
keep slide-over save callbacks working with the board patch queue.
This commit is contained in:
parent
e7fb8d6122
commit
9074841125
3 changed files with 35 additions and 36 deletions
|
|
@ -148,9 +148,9 @@ export default function WorkOrdersListPage() {
|
|||
}}
|
||||
data={page.completionDocs[String(activeDocRow.id)]}
|
||||
onSave={(data, status) => page.saveCompletionDoc(activeDocRow, data, status)}
|
||||
onDateCompletedChange={(date) =>
|
||||
page.patchFieldAsync(activeDocRow.id, { completedDate: date })
|
||||
}
|
||||
onDateCompletedChange={async (date) => {
|
||||
await page.patchFieldAsync(activeDocRow.id, { completedDate: date });
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
</Box>
|
||||
|
|
|
|||
|
|
@ -146,8 +146,21 @@ export function useWorkOrderTableMutations(
|
|||
},
|
||||
});
|
||||
|
||||
const patchField = (id: string | number, patch: WorkOrderTablePatch) => {
|
||||
patchMutation.mutate({ id, patch });
|
||||
const patchField = (
|
||||
id: string | number,
|
||||
patch: WorkOrderTablePatch,
|
||||
options?: {
|
||||
onSuccess?: () => void;
|
||||
onError?: (error: Error) => void;
|
||||
},
|
||||
) => {
|
||||
patchMutation.mutate(
|
||||
{ id, patch },
|
||||
{
|
||||
onSuccess: () => options?.onSuccess?.(),
|
||||
onError: (error) => options?.onError?.(error),
|
||||
},
|
||||
);
|
||||
};
|
||||
|
||||
const patchFieldAsync = (id: string | number, patch: WorkOrderTablePatch) =>
|
||||
|
|
|
|||
|
|
@ -2,8 +2,10 @@ 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 } from "@/domain/work-orders/types/work-order";
|
||||
import type { WorkOrderTableRow } from "@/domain/work-orders/types/work-order-table-row";
|
||||
import type {
|
||||
CompletionDocStatus,
|
||||
WorkOrderTableRow,
|
||||
} from "@/domain/work-orders/types/work-order-table-row";
|
||||
|
||||
const getById = vi.fn();
|
||||
const update = vi.fn();
|
||||
|
|
@ -34,34 +36,18 @@ function makeWrapper() {
|
|||
};
|
||||
}
|
||||
|
||||
const BASE_DETAIL: WorkOrderDetail = {
|
||||
id: 42,
|
||||
internalWONumber: "WO-42",
|
||||
workOrderNumber: "WO-42",
|
||||
title: "PM — SEA1",
|
||||
location: "Seattle",
|
||||
locationId: "loc-1",
|
||||
locationZip: "98101",
|
||||
assignedTo: "Dispatcher",
|
||||
dueDate: "",
|
||||
createdDate: "2026-06-01",
|
||||
createdDateFull: "2026-06-01T00:00:00Z",
|
||||
description: "",
|
||||
priority: "Sev 3",
|
||||
type ServerState = {
|
||||
status: string;
|
||||
scheduledDate: string;
|
||||
completedDate: string;
|
||||
docStatus: CompletionDocStatus;
|
||||
};
|
||||
|
||||
const BASE_SERVER: ServerState = {
|
||||
status: "Open",
|
||||
po: "",
|
||||
tt: "",
|
||||
problem: "HVAC",
|
||||
trade: "",
|
||||
subTrade: "",
|
||||
vendorNTE: "",
|
||||
scheduledDate: "2026-06-01",
|
||||
completedDate: "",
|
||||
docStatus: "No",
|
||||
source: "PM",
|
||||
comments: [],
|
||||
auditLog: [],
|
||||
dispatches: [],
|
||||
};
|
||||
|
||||
const BASE_ROW = {
|
||||
|
|
@ -110,7 +96,7 @@ const BASE_ROW = {
|
|||
} as WorkOrderTableRow;
|
||||
|
||||
describe("useWorkOrderTableMutations completion-doc persistence", () => {
|
||||
let serverState: WorkOrderDetail;
|
||||
let serverState: ServerState;
|
||||
let events: string[];
|
||||
let rowState: WorkOrderTableRow;
|
||||
|
||||
|
|
@ -118,7 +104,7 @@ describe("useWorkOrderTableMutations completion-doc persistence", () => {
|
|||
getById.mockReset();
|
||||
update.mockReset();
|
||||
patchBoardField.mockReset();
|
||||
serverState = { ...BASE_DETAIL };
|
||||
serverState = { ...BASE_SERVER };
|
||||
rowState = { ...BASE_ROW };
|
||||
events = [];
|
||||
|
||||
|
|
@ -131,7 +117,7 @@ describe("useWorkOrderTableMutations completion-doc persistence", () => {
|
|||
await delay(5);
|
||||
if (payload.field === "docStatus" && typeof payload.value === "string") {
|
||||
const docStatus =
|
||||
payload.value === "NotNeeded" ? "NN" : (payload.value as WorkOrderDetail["docStatus"]);
|
||||
payload.value === "NotNeeded" ? "NN" : (payload.value as CompletionDocStatus);
|
||||
serverState = { ...serverState, docStatus };
|
||||
rowState = {
|
||||
...rowState,
|
||||
|
|
@ -217,7 +203,7 @@ describe("useWorkOrderTableMutations completion-doc persistence", () => {
|
|||
|
||||
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);
|
||||
expect(serverState.scheduledDate).toBe(BASE_SERVER.scheduledDate);
|
||||
expect(serverState.status).toBe(BASE_SERVER.status);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue