shoc-frontend-new/src/test/app/(protected)/workorders/use-wizard-poc-autofill.test.tsx
Arthur Bassi ee90d73a44
Some checks are pending
CI / ci (push) Waiting to run
CI / governance (push) Waiting to run
CI / vendor-visual-regression (push) Waiting to run
Deploy / deploy (push) Waiting to run
feat(work-orders): board wizard create with service notes (#99)
* 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>
2026-08-13 18:43:11 -03:00

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");
});
});