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)]}
|
data={page.completionDocs[String(activeDocRow.id)]}
|
||||||
onSave={(data, status) => page.saveCompletionDoc(activeDocRow, data, status)}
|
onSave={(data, status) => page.saveCompletionDoc(activeDocRow, data, status)}
|
||||||
onDateCompletedChange={(date) =>
|
onDateCompletedChange={async (date) => {
|
||||||
page.patchFieldAsync(activeDocRow.id, { completedDate: date })
|
await page.patchFieldAsync(activeDocRow.id, { completedDate: date });
|
||||||
}
|
}}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</Box>
|
</Box>
|
||||||
|
|
|
||||||
|
|
@ -146,8 +146,21 @@ export function useWorkOrderTableMutations(
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const patchField = (id: string | number, patch: WorkOrderTablePatch) => {
|
const patchField = (
|
||||||
patchMutation.mutate({ id, patch });
|
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) =>
|
const patchFieldAsync = (id: string | number, patch: WorkOrderTablePatch) =>
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,10 @@ import type { ReactNode } from "react";
|
||||||
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
||||||
import { act, renderHook, waitFor } from "@testing-library/react";
|
import { act, renderHook, waitFor } from "@testing-library/react";
|
||||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||||
import type { WorkOrderDetail } from "@/domain/work-orders/types/work-order";
|
import type {
|
||||||
import type { WorkOrderTableRow } from "@/domain/work-orders/types/work-order-table-row";
|
CompletionDocStatus,
|
||||||
|
WorkOrderTableRow,
|
||||||
|
} from "@/domain/work-orders/types/work-order-table-row";
|
||||||
|
|
||||||
const getById = vi.fn();
|
const getById = vi.fn();
|
||||||
const update = vi.fn();
|
const update = vi.fn();
|
||||||
|
|
@ -34,34 +36,18 @@ function makeWrapper() {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const BASE_DETAIL: WorkOrderDetail = {
|
type ServerState = {
|
||||||
id: 42,
|
status: string;
|
||||||
internalWONumber: "WO-42",
|
scheduledDate: string;
|
||||||
workOrderNumber: "WO-42",
|
completedDate: string;
|
||||||
title: "PM — SEA1",
|
docStatus: CompletionDocStatus;
|
||||||
location: "Seattle",
|
};
|
||||||
locationId: "loc-1",
|
|
||||||
locationZip: "98101",
|
const BASE_SERVER: ServerState = {
|
||||||
assignedTo: "Dispatcher",
|
|
||||||
dueDate: "",
|
|
||||||
createdDate: "2026-06-01",
|
|
||||||
createdDateFull: "2026-06-01T00:00:00Z",
|
|
||||||
description: "",
|
|
||||||
priority: "Sev 3",
|
|
||||||
status: "Open",
|
status: "Open",
|
||||||
po: "",
|
|
||||||
tt: "",
|
|
||||||
problem: "HVAC",
|
|
||||||
trade: "",
|
|
||||||
subTrade: "",
|
|
||||||
vendorNTE: "",
|
|
||||||
scheduledDate: "2026-06-01",
|
scheduledDate: "2026-06-01",
|
||||||
completedDate: "",
|
completedDate: "",
|
||||||
docStatus: "No",
|
docStatus: "No",
|
||||||
source: "PM",
|
|
||||||
comments: [],
|
|
||||||
auditLog: [],
|
|
||||||
dispatches: [],
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const BASE_ROW = {
|
const BASE_ROW = {
|
||||||
|
|
@ -110,7 +96,7 @@ const BASE_ROW = {
|
||||||
} as WorkOrderTableRow;
|
} as WorkOrderTableRow;
|
||||||
|
|
||||||
describe("useWorkOrderTableMutations completion-doc persistence", () => {
|
describe("useWorkOrderTableMutations completion-doc persistence", () => {
|
||||||
let serverState: WorkOrderDetail;
|
let serverState: ServerState;
|
||||||
let events: string[];
|
let events: string[];
|
||||||
let rowState: WorkOrderTableRow;
|
let rowState: WorkOrderTableRow;
|
||||||
|
|
||||||
|
|
@ -118,7 +104,7 @@ describe("useWorkOrderTableMutations completion-doc persistence", () => {
|
||||||
getById.mockReset();
|
getById.mockReset();
|
||||||
update.mockReset();
|
update.mockReset();
|
||||||
patchBoardField.mockReset();
|
patchBoardField.mockReset();
|
||||||
serverState = { ...BASE_DETAIL };
|
serverState = { ...BASE_SERVER };
|
||||||
rowState = { ...BASE_ROW };
|
rowState = { ...BASE_ROW };
|
||||||
events = [];
|
events = [];
|
||||||
|
|
||||||
|
|
@ -131,7 +117,7 @@ describe("useWorkOrderTableMutations completion-doc persistence", () => {
|
||||||
await delay(5);
|
await delay(5);
|
||||||
if (payload.field === "docStatus" && typeof payload.value === "string") {
|
if (payload.field === "docStatus" && typeof payload.value === "string") {
|
||||||
const docStatus =
|
const docStatus =
|
||||||
payload.value === "NotNeeded" ? "NN" : (payload.value as WorkOrderDetail["docStatus"]);
|
payload.value === "NotNeeded" ? "NN" : (payload.value as CompletionDocStatus);
|
||||||
serverState = { ...serverState, docStatus };
|
serverState = { ...serverState, docStatus };
|
||||||
rowState = {
|
rowState = {
|
||||||
...rowState,
|
...rowState,
|
||||||
|
|
@ -217,7 +203,7 @@ describe("useWorkOrderTableMutations completion-doc persistence", () => {
|
||||||
|
|
||||||
expect(serverState.docStatus).toBe("Yes");
|
expect(serverState.docStatus).toBe("Yes");
|
||||||
expect(serverState.completedDate).toBe("2026-07-20");
|
expect(serverState.completedDate).toBe("2026-07-20");
|
||||||
expect(serverState.scheduledDate).toBe(BASE_DETAIL.scheduledDate);
|
expect(serverState.scheduledDate).toBe(BASE_SERVER.scheduledDate);
|
||||||
expect(serverState.status).toBe(BASE_DETAIL.status);
|
expect(serverState.status).toBe(BASE_SERVER.status);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue