mirror of
https://github.com/Sea-Haven-Industries/shoc-frontend-new.git
synced 2026-10-06 17:02:05 +00:00
* feat(work-orders): board wizard create with service notes Co-authored-by: Cursor <cursoragent@cursor.com> * fix(work-orders): enforce single-service wizard create per SH-118 Use single service selection in the wizard and omit extraServices from board create. * refactor(work-orders): extract wizard controller for maintainability gate Move duplicate-WO wiring and lookup hooks out of NewWoWizard so the changed-file function line cap passes after merging dev. --------- Co-authored-by: Cursor <cursoragent@cursor.com>
78 lines
2.6 KiB
TypeScript
78 lines
2.6 KiB
TypeScript
import { act, renderHook } from "@testing-library/react";
|
|
import { describe, expect, it } from "vitest";
|
|
import { useWizardPocAutofill } from "@/app/(protected)/workorders/_components/wizard/use-wizard-poc-autofill";
|
|
import type { Location } from "@/domain/locations/types/location";
|
|
import {
|
|
EMPTY_WIZARD_DRAFT,
|
|
type WorkOrderWizardDraft,
|
|
} from "@/domain/work-orders/types/work-order-wizard";
|
|
import { useState } from "react";
|
|
|
|
function baseLocation(overrides: Partial<Location> = {}): Location {
|
|
return {
|
|
id: "loc-1",
|
|
name: "BK5",
|
|
contact: "Janelle Pickett",
|
|
phone: "214-555-0111",
|
|
...overrides,
|
|
} as Location;
|
|
}
|
|
|
|
describe("useWizardPocAutofill", () => {
|
|
it("fills empty POC fields from location detail once", () => {
|
|
const { result } = renderHook(() => {
|
|
const [draft, setDraft] = useState<WorkOrderWizardDraft>({ ...EMPTY_WIZARD_DRAFT });
|
|
useWizardPocAutofill(true, "loc-1", baseLocation(), setDraft);
|
|
return draft;
|
|
});
|
|
|
|
expect(result.current.pocName).toBe("Janelle Pickett");
|
|
expect(result.current.pocPhone).toBe("214-555-0111");
|
|
});
|
|
|
|
it("does not overwrite POC edits made before location detail arrives", () => {
|
|
const { result, rerender } = renderHook(
|
|
({ detail }: { detail: Location | undefined }) => {
|
|
const [draft, setDraft] = useState<WorkOrderWizardDraft>({
|
|
...EMPTY_WIZARD_DRAFT,
|
|
pocName: "Dispatcher Typed",
|
|
pocPhone: "999-000-1111",
|
|
});
|
|
useWizardPocAutofill(true, "loc-1", detail, setDraft);
|
|
return draft;
|
|
},
|
|
{ initialProps: { detail: undefined as Location | undefined } },
|
|
);
|
|
|
|
expect(result.current.pocName).toBe("Dispatcher Typed");
|
|
|
|
act(() => {
|
|
rerender({ detail: baseLocation() });
|
|
});
|
|
|
|
expect(result.current.pocName).toBe("Dispatcher Typed");
|
|
expect(result.current.pocPhone).toBe("999-000-1111");
|
|
});
|
|
|
|
it("re-seeds POC after re-selecting the same location clears the fields", () => {
|
|
const { result } = renderHook(() => {
|
|
const [draft, setDraft] = useState<WorkOrderWizardDraft>({ ...EMPTY_WIZARD_DRAFT });
|
|
const autofill = useWizardPocAutofill(true, "loc-1", baseLocation(), setDraft);
|
|
return { draft, setDraft, autofill };
|
|
});
|
|
|
|
expect(result.current.draft.pocName).toBe("Janelle Pickett");
|
|
|
|
act(() => {
|
|
result.current.setDraft((current) => ({
|
|
...current,
|
|
pocName: "",
|
|
pocPhone: "",
|
|
}));
|
|
result.current.autofill.notifyLocationChanged("loc-1");
|
|
});
|
|
|
|
expect(result.current.draft.pocName).toBe("Janelle Pickett");
|
|
expect(result.current.draft.pocPhone).toBe("214-555-0111");
|
|
});
|
|
});
|