mirror of
https://github.com/Sea-Haven-Industries/shoc-frontend-new.git
synced 2026-09-30 09:13:11 +00:00
Allow empty Appt Time in wizard, table, and slide-over without blocking create or complete. Omit appointment fields without vendorId so create does not hit DispatchRequired.
253 lines
7.6 KiB
TypeScript
253 lines
7.6 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { mapWizardDraftToFormValues } from "@/domain/work-orders/mappers/wizard-draft-mapper";
|
|
import {
|
|
EMPTY_WIZARD_DRAFT,
|
|
canContinueWizardStep1,
|
|
canContinueWizardStep2,
|
|
canCreateWorkOrderFromWizard,
|
|
isWizardStepValid,
|
|
isWizardWoNumberValid,
|
|
wizardStep1ContinueHint,
|
|
wizardStep2ContinueHint,
|
|
} 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("allows step 1 with a blank woNumber for backend SH generation", () => {
|
|
expect(canContinueWizardStep1(EMPTY_WIZARD_DRAFT)).toBe(true);
|
|
expect(isWizardStepValid(1, EMPTY_WIZARD_DRAFT)).toBe(true);
|
|
});
|
|
|
|
it("allows step 1 without type when woNumber is set", () => {
|
|
const draft = { ...EMPTY_WIZARD_DRAFT, woNumber: "12345" };
|
|
expect(canContinueWizardStep1(draft)).toBe(true);
|
|
expect(isWizardStepValid(1, draft)).toBe(true);
|
|
});
|
|
|
|
it("allows step 1 without woNumber when type is set", () => {
|
|
const draft = { ...EMPTY_WIZARD_DRAFT, type: "PM" as const };
|
|
expect(canContinueWizardStep1(draft)).toBe(true);
|
|
expect(isWizardStepValid(1, draft)).toBe(true);
|
|
});
|
|
|
|
it("allows step 1 when type and woNumber are set (schedule optional)", () => {
|
|
const draft = {
|
|
...EMPTY_WIZARD_DRAFT,
|
|
type: "PM" as const,
|
|
woNumber: "12345",
|
|
};
|
|
expect(canContinueWizardStep1(draft)).toBe(true);
|
|
expect(isWizardStepValid(1, draft)).toBe(true);
|
|
});
|
|
|
|
it("blocks step 1 for Emergency without severity", () => {
|
|
const draft = {
|
|
...EMPTY_WIZARD_DRAFT,
|
|
type: "Emergency" as const,
|
|
woNumber: "12345",
|
|
};
|
|
expect(canContinueWizardStep1(draft)).toBe(false);
|
|
});
|
|
|
|
it("allows step 1 for Emergency with severity", () => {
|
|
const draft = {
|
|
...EMPTY_WIZARD_DRAFT,
|
|
type: "Emergency" as const,
|
|
woNumber: "12345",
|
|
severity: 2 as const,
|
|
};
|
|
expect(canContinueWizardStep1(draft)).toBe(true);
|
|
});
|
|
|
|
it("blocks step 2 without POC name/phone", () => {
|
|
const draft = {
|
|
...EMPTY_WIZARD_DRAFT,
|
|
type: "PM" as const,
|
|
woNumber: "12345",
|
|
locationId: "99",
|
|
siteCode: "BK5",
|
|
};
|
|
expect(canContinueWizardStep2(draft)).toBe(false);
|
|
expect(isWizardStepValid(2, draft)).toBe(false);
|
|
});
|
|
|
|
it("allows step 2 without an account when site and POC are set", () => {
|
|
const draft = {
|
|
...EMPTY_WIZARD_DRAFT,
|
|
type: "PM" as const,
|
|
woNumber: "12345",
|
|
locationId: "99",
|
|
siteCode: "BK5",
|
|
pocName: "Jordan",
|
|
pocPhone: "555-0100",
|
|
};
|
|
expect(canContinueWizardStep2(draft)).toBe(true);
|
|
expect(isWizardStepValid(2, draft)).toBe(true);
|
|
expect(wizardStep2ContinueHint(draft)).toBeNull();
|
|
});
|
|
|
|
it("hints pick a site when step 2 has no location", () => {
|
|
expect(wizardStep2ContinueHint(EMPTY_WIZARD_DRAFT)).toBe("Pick a site to continue");
|
|
});
|
|
|
|
it("hints POC when step 2 has site but no phone", () => {
|
|
const draft = {
|
|
...EMPTY_WIZARD_DRAFT,
|
|
locationId: "99",
|
|
siteCode: "BK5",
|
|
pocName: "Jordan",
|
|
};
|
|
expect(wizardStep2ContinueHint(draft)).toBe("Enter POC name and phone to continue");
|
|
});
|
|
|
|
it("allows step 2 when site and POC are set", () => {
|
|
const draft = {
|
|
...EMPTY_WIZARD_DRAFT,
|
|
type: "PM" as const,
|
|
woNumber: "12345",
|
|
locationId: "99",
|
|
siteCode: "BK5",
|
|
pocName: "Jordan",
|
|
pocPhone: "555-0100",
|
|
};
|
|
expect(canContinueWizardStep2(draft)).toBe(true);
|
|
expect(isWizardStepValid(2, draft)).toBe(true);
|
|
expect(wizardStep2ContinueHint(draft)).toBeNull();
|
|
});
|
|
|
|
it("blocks create without siteCode", () => {
|
|
const draft = {
|
|
...EMPTY_WIZARD_DRAFT,
|
|
type: "PM" as const,
|
|
woNumber: "12345",
|
|
locationId: "99",
|
|
};
|
|
expect(canCreateWorkOrderFromWizard(draft)).toBe(false);
|
|
expect(isWizardStepValid(2, draft)).toBe(false);
|
|
});
|
|
|
|
it("allows create when type, woNumber, site, and POC are set", () => {
|
|
const draft = {
|
|
...EMPTY_WIZARD_DRAFT,
|
|
type: "PM" as const,
|
|
woNumber: "12345678901",
|
|
locationId: "99",
|
|
siteCode: "BK5",
|
|
pocName: "Jordan",
|
|
pocPhone: "555-0100",
|
|
};
|
|
expect(canCreateWorkOrderFromWizard(draft)).toBe(true);
|
|
expect(isWizardStepValid(2, draft)).toBe(true);
|
|
});
|
|
|
|
it("does not require Appt Time for wizard step 3 or create", () => {
|
|
const draft = {
|
|
...EMPTY_WIZARD_DRAFT,
|
|
type: "PM" as const,
|
|
woNumber: "12345678901",
|
|
locationId: "99",
|
|
siteCode: "BK5",
|
|
pocName: "Jordan",
|
|
pocPhone: "555-0100",
|
|
apptStart: "",
|
|
apptEnd: "",
|
|
};
|
|
expect(isWizardStepValid(3, draft)).toBe(true);
|
|
expect(canCreateWorkOrderFromWizard(draft)).toBe(true);
|
|
});
|
|
|
|
it("allows provisional SH-prefixed woNumber", () => {
|
|
const draft = {
|
|
...EMPTY_WIZARD_DRAFT,
|
|
type: "PM" as const,
|
|
woNumber: "SH12345",
|
|
};
|
|
expect(isWizardWoNumberValid(draft.woNumber)).toBe(true);
|
|
expect(canContinueWizardStep1(draft)).toBe(true);
|
|
});
|
|
|
|
it("accepts whitespace-only woNumber for backend SH generation", () => {
|
|
const draft = {
|
|
...EMPTY_WIZARD_DRAFT,
|
|
type: "PM" as const,
|
|
woNumber: " ",
|
|
};
|
|
expect(isWizardWoNumberValid(draft.woNumber)).toBe(true);
|
|
expect(canContinueWizardStep1(draft)).toBe(true);
|
|
});
|
|
|
|
it("rejects non-alphanumeric woNumber", () => {
|
|
expect(isWizardWoNumberValid("!!!")).toBe(false);
|
|
expect(canContinueWizardStep1({ ...EMPTY_WIZARD_DRAFT, type: "PM", woNumber: "!!!" })).toBe(
|
|
false,
|
|
);
|
|
});
|
|
|
|
it("accepts alphanumeric woNumber", () => {
|
|
expect(isWizardWoNumberValid("ABC123")).toBe(true);
|
|
});
|
|
|
|
it("hints alphanumeric WO number or severity when step 1 is incomplete", () => {
|
|
expect(wizardStep1ContinueHint(EMPTY_WIZARD_DRAFT)).toBeNull();
|
|
expect(wizardStep1ContinueHint({ ...EMPTY_WIZARD_DRAFT, type: "PM", woNumber: "!!!" })).toBe(
|
|
"WO number must be alphanumeric",
|
|
);
|
|
expect(wizardStep1ContinueHint({ ...EMPTY_WIZARD_DRAFT, type: "Emergency" })).toBe(
|
|
"Select severity to continue",
|
|
);
|
|
});
|
|
});
|