mirror of
https://github.com/Sea-Haven-Industries/shoc-frontend-new.git
synced 2026-10-06 07:42:04 +00:00
Keep UPLIFT after COMP DOC alongside COMPLETED DATE from dev, wire uplifts through useWorkOrdersListPage, and refresh table-row fixtures.
149 lines
3.8 KiB
TypeScript
149 lines
3.8 KiB
TypeScript
import { act, renderHook, waitFor } from "@testing-library/react";
|
|
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
|
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
import type { ReactNode } from "react";
|
|
import { useCompDocDialog } from "@/app/(protected)/workorders/_hooks/use-comp-doc-dialog";
|
|
import type { Location } from "@/domain/locations/types/location";
|
|
import type { WorkOrderTableRow } from "@/domain/work-orders/types/work-order-table-row";
|
|
|
|
const locationDetailState = vi.hoisted(() => ({
|
|
data: undefined as Location | undefined,
|
|
}));
|
|
|
|
vi.mock("@/domain/locations/use-cases/use-location-detail", () => ({
|
|
useLocationDetail: () => ({ data: locationDetailState.data }),
|
|
}));
|
|
|
|
function baseRow(overrides: Partial<WorkOrderTableRow> = {}): WorkOrderTableRow {
|
|
return {
|
|
id: 42,
|
|
woNumber: "WO-42",
|
|
site: "SEA1",
|
|
type: "PM",
|
|
dispatcherId: "u1",
|
|
dispatcherName: "Dispatcher",
|
|
scheduledOn: "2026-06-01",
|
|
completedDate: "",
|
|
targetWeek: "",
|
|
dayGroup: "",
|
|
dayLabel: "",
|
|
location: "Seattle",
|
|
locationId: "loc-real-1",
|
|
pm: "HVAC",
|
|
serviceNotes: "",
|
|
extraServices: [],
|
|
vendorId: "",
|
|
company: "Vendor Co",
|
|
tech: "Tech One",
|
|
techPhone: "",
|
|
apptStart: "",
|
|
apptEnd: "",
|
|
apptTime: "",
|
|
status: "Scheduled",
|
|
docStatus: "No",
|
|
pocName: "Amazon Rep",
|
|
pocPhone: "",
|
|
pocNotes: "",
|
|
dueDate: "",
|
|
rescheduleCount: 0,
|
|
carriedOver: 0,
|
|
originalWeek: "",
|
|
originalDate: "",
|
|
isPastDue: false,
|
|
scheduleWeekOnly: false,
|
|
mediaCount: 0,
|
|
title: "PM — SEA1",
|
|
priority: "Sev 3",
|
|
primaryDispatchId: null,
|
|
rowVersion: "",
|
|
dispatchRowVersion: "",
|
|
flagColor: null,
|
|
upliftSummary: { hasUplift: false, pendingCount: 0 },
|
|
...overrides,
|
|
};
|
|
}
|
|
|
|
function wrapper({ children }: { children: ReactNode }) {
|
|
const client = new QueryClient({
|
|
defaultOptions: { queries: { retry: false }, mutations: { retry: false } },
|
|
});
|
|
return <QueryClientProvider client={client}>{children}</QueryClientProvider>;
|
|
}
|
|
|
|
describe("useCompDocDialog address seeding", () => {
|
|
beforeEach(() => {
|
|
locationDetailState.data = undefined;
|
|
});
|
|
|
|
it("seeds address from the first authoritative locationDetail without locking on the empty fallback", async () => {
|
|
const row = baseRow();
|
|
const { result, rerender } = renderHook(
|
|
() =>
|
|
useCompDocDialog({
|
|
row,
|
|
open: true,
|
|
onSave: vi.fn(),
|
|
}),
|
|
{ wrapper },
|
|
);
|
|
|
|
expect(result.current.editAddress).toBe("");
|
|
|
|
locationDetailState.data = {
|
|
id: "loc-real-1",
|
|
name: "SEA1",
|
|
address: "3811 Distribution Dr",
|
|
city: "Seattle",
|
|
state: "WA",
|
|
zipCode: "98101",
|
|
} as Location;
|
|
|
|
rerender();
|
|
|
|
await waitFor(() => {
|
|
expect(result.current.editAddress).toContain("3811 Distribution Dr");
|
|
});
|
|
});
|
|
|
|
it("does not overwrite address after the dispatcher edits it", async () => {
|
|
locationDetailState.data = {
|
|
id: "loc-real-1",
|
|
name: "SEA1",
|
|
address: "3811 Distribution Dr",
|
|
city: "Seattle",
|
|
state: "WA",
|
|
zipCode: "98101",
|
|
} as Location;
|
|
|
|
const row = baseRow();
|
|
const { result, rerender } = renderHook(
|
|
() =>
|
|
useCompDocDialog({
|
|
row,
|
|
open: true,
|
|
onSave: vi.fn(),
|
|
}),
|
|
{ wrapper },
|
|
);
|
|
|
|
await waitFor(() => {
|
|
expect(result.current.editAddress).toContain("3811 Distribution Dr");
|
|
});
|
|
|
|
act(() => {
|
|
result.current.setEditAddress("Dispatcher typed address");
|
|
});
|
|
|
|
locationDetailState.data = {
|
|
id: "loc-real-1",
|
|
name: "SEA1",
|
|
address: "999 Other St",
|
|
city: "Seattle",
|
|
state: "WA",
|
|
zipCode: "98101",
|
|
} as Location;
|
|
rerender();
|
|
|
|
expect(result.current.editAddress).toBe("Dispatcher typed address");
|
|
});
|
|
});
|