mirror of
https://github.com/Sea-Haven-Industries/shoc-frontend-new.git
synced 2026-10-04 13:42:09 +00:00
93 lines
2.9 KiB
TypeScript
93 lines
2.9 KiB
TypeScript
|
|
import { describe, expect, it } from "vitest";
|
||
|
|
import { mapWizardDraftToFormValues } from "@/domain/work-orders/mappers/wizard-draft-mapper";
|
||
|
|
import {
|
||
|
|
EMPTY_WIZARD_DRAFT,
|
||
|
|
canContinueWizardStep1,
|
||
|
|
canCreateWorkOrderFromWizard,
|
||
|
|
isWizardStepValid,
|
||
|
|
} from "@/domain/work-orders/types/work-order-wizard";
|
||
|
|
|
||
|
|
describe("mapWizardDraftToFormValues", () => {
|
||
|
|
it("maps minimal draft with type and site to valid form values", () => {
|
||
|
|
const draft = {
|
||
|
|
...EMPTY_WIZARD_DRAFT,
|
||
|
|
type: "PM" as const,
|
||
|
|
locationId: "42",
|
||
|
|
locationName: "DFW8 · Dallas, TX",
|
||
|
|
woNumber: "24818",
|
||
|
|
assigneeName: "Sarah Chen",
|
||
|
|
status: "Incomplete" as const,
|
||
|
|
};
|
||
|
|
|
||
|
|
const values = mapWizardDraftToFormValues(draft);
|
||
|
|
|
||
|
|
expect(values.title).toBe("PM — #24818");
|
||
|
|
expect(values.workOrderNumber).toBe("24818");
|
||
|
|
expect(values.locationId).toBe("42");
|
||
|
|
expect(values.assignedTo).toBe("Sarah Chen");
|
||
|
|
expect(values.status).toBe("Open");
|
||
|
|
expect(values.priority).toBe("Sev 3");
|
||
|
|
expect(values.source).toBe("PM");
|
||
|
|
expect(values.createdDate).toMatch(/^\d{4}-\d{2}-\d{2}$/);
|
||
|
|
});
|
||
|
|
|
||
|
|
it("maps emergency type to Sev 1 priority", () => {
|
||
|
|
const values = mapWizardDraftToFormValues({
|
||
|
|
...EMPTY_WIZARD_DRAFT,
|
||
|
|
type: "Emergency",
|
||
|
|
locationId: "1",
|
||
|
|
locationName: "Site A",
|
||
|
|
});
|
||
|
|
|
||
|
|
expect(values.priority).toBe("Sev 1");
|
||
|
|
expect(values.title).toBe("Emergency — Site A");
|
||
|
|
});
|
||
|
|
|
||
|
|
it("includes appointment and notes in description", () => {
|
||
|
|
const values = mapWizardDraftToFormValues({
|
||
|
|
...EMPTY_WIZARD_DRAFT,
|
||
|
|
type: "Reactive",
|
||
|
|
locationId: "1",
|
||
|
|
locationName: "Site A",
|
||
|
|
apptStart: "09:00",
|
||
|
|
apptEnd: "11:00",
|
||
|
|
pocNotes: "Call ahead",
|
||
|
|
vendorName: "Roto-Rooter",
|
||
|
|
vendorNotes: "Prefers morning",
|
||
|
|
});
|
||
|
|
|
||
|
|
expect(values.description).toContain("Appt:");
|
||
|
|
expect(values.description).toContain("POC notes: Call ahead");
|
||
|
|
expect(values.description).toContain("Vendor: Roto-Rooter");
|
||
|
|
});
|
||
|
|
});
|
||
|
|
|
||
|
|
describe("wizard step validation", () => {
|
||
|
|
it("blocks step 1 continue without type", () => {
|
||
|
|
expect(canContinueWizardStep1(EMPTY_WIZARD_DRAFT)).toBe(false);
|
||
|
|
expect(isWizardStepValid(1, EMPTY_WIZARD_DRAFT)).toBe(false);
|
||
|
|
});
|
||
|
|
|
||
|
|
it("allows step 1 continue when type is selected", () => {
|
||
|
|
const draft = { ...EMPTY_WIZARD_DRAFT, type: "PM" as const };
|
||
|
|
expect(canContinueWizardStep1(draft)).toBe(true);
|
||
|
|
expect(isWizardStepValid(1, draft)).toBe(true);
|
||
|
|
});
|
||
|
|
|
||
|
|
it("blocks create without location", () => {
|
||
|
|
const draft = { ...EMPTY_WIZARD_DRAFT, type: "PM" as const };
|
||
|
|
expect(canCreateWorkOrderFromWizard(draft)).toBe(false);
|
||
|
|
expect(isWizardStepValid(2, draft)).toBe(false);
|
||
|
|
});
|
||
|
|
|
||
|
|
it("allows create when location is selected", () => {
|
||
|
|
const draft = {
|
||
|
|
...EMPTY_WIZARD_DRAFT,
|
||
|
|
type: "PM" as const,
|
||
|
|
locationId: "99",
|
||
|
|
};
|
||
|
|
expect(canCreateWorkOrderFromWizard(draft)).toBe(true);
|
||
|
|
expect(isWizardStepValid(2, draft)).toBe(true);
|
||
|
|
});
|
||
|
|
});
|