mirror of
https://github.com/Sea-Haven-Industries/shoc-frontend-new.git
synced 2026-10-06 22:52:06 +00:00
Share Week/Date/Range on inline, board, and slide-over DateCell. A selected range lands on the start day, matching the wizard.
155 lines
5 KiB
TypeScript
155 lines
5 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { buildInlineDraftCreateInput } from "@/app/(protected)/workorders/_components/list/table/build-inline-draft-create-input";
|
|
import { mapWizardDraftToBoardCreatePayload } from "@/domain/work-orders/mappers/work-order-board-mapper";
|
|
import { EMPTY_TABLE_DRAFT } from "@/domain/work-orders/types/work-order-table-row";
|
|
|
|
describe("buildInlineDraftCreateInput", () => {
|
|
it("defaults type to PM and omits schedule flags when undated", () => {
|
|
const draft = {
|
|
...EMPTY_TABLE_DRAFT,
|
|
site: "BK5",
|
|
locationId: "9",
|
|
woNumber: "25001",
|
|
pocName: "Jane",
|
|
pocPhone: "555-0100",
|
|
scheduleWeekOnly: true,
|
|
targetWeek: "",
|
|
scheduledOn: "",
|
|
};
|
|
|
|
const input = buildInlineDraftCreateInput(draft, [], [{ id: 9, name: "BK5 · Dallas, TX" }]);
|
|
|
|
expect(input.type).toBe("PM");
|
|
expect(input.scheduleWeekOnly).toBe(false);
|
|
expect(input.scheduledOn).toBe("");
|
|
expect(input.targetWeek).toBe("");
|
|
|
|
const payload = mapWizardDraftToBoardCreatePayload(input);
|
|
expect(payload.scheduledDate).toBeUndefined();
|
|
expect(payload.targetWeek).toBeUndefined();
|
|
expect(payload.scheduleWeekOnly).toBeUndefined();
|
|
expect(payload.woNumber).toBe("25001");
|
|
expect(payload.pocName).toBe("Jane");
|
|
expect(payload.locationId).toBe(9);
|
|
expect(payload).not.toHaveProperty("customer");
|
|
});
|
|
|
|
it("keeps week-only schedule when targetWeek is set", () => {
|
|
const draft = {
|
|
...EMPTY_TABLE_DRAFT,
|
|
site: "BK5",
|
|
locationId: "9",
|
|
woNumber: "25002",
|
|
type: "Reactive" as const,
|
|
pocName: "Jane",
|
|
pocPhone: "555-0100",
|
|
scheduleWeekOnly: true,
|
|
targetWeek: "2026-06-22",
|
|
};
|
|
|
|
const input = buildInlineDraftCreateInput(draft, [], [{ id: 9, name: "BK5 · Dallas, TX" }]);
|
|
const payload = mapWizardDraftToBoardCreatePayload(input);
|
|
|
|
expect(payload.scheduleWeekOnly).toBe(true);
|
|
expect(payload.targetWeek).toBe("2026-06-22");
|
|
expect(payload.scheduledDate).toBeUndefined();
|
|
});
|
|
|
|
it("sends assignTo when a dispatcher is selected at inline create", () => {
|
|
const draft = {
|
|
...EMPTY_TABLE_DRAFT,
|
|
site: "BK5",
|
|
locationId: "9",
|
|
woNumber: "25003",
|
|
pocName: "Jane",
|
|
pocPhone: "555-0100",
|
|
dispatcherId: "sarah",
|
|
};
|
|
const users = [{ id: "sarah", name: "Sarah Chen" }];
|
|
|
|
const input = buildInlineDraftCreateInput(draft, users, [{ id: 9, name: "BK5 · Dallas, TX" }]);
|
|
const payload = mapWizardDraftToBoardCreatePayload(input);
|
|
|
|
expect(input.assigneeId).toBe("sarah");
|
|
expect(input.assigneeName).toBe("Sarah Chen");
|
|
expect(payload.assignTo).toBe("sarah");
|
|
});
|
|
|
|
it("omits assignTo when Assigned To is left unassigned", () => {
|
|
const draft = {
|
|
...EMPTY_TABLE_DRAFT,
|
|
site: "BK5",
|
|
locationId: "9",
|
|
woNumber: "25004",
|
|
pocName: "Jane",
|
|
pocPhone: "555-0100",
|
|
dispatcherId: "",
|
|
};
|
|
|
|
const input = buildInlineDraftCreateInput(draft, [], [{ id: 9, name: "BK5 · Dallas, TX" }]);
|
|
const payload = mapWizardDraftToBoardCreatePayload(input);
|
|
|
|
expect(input.assigneeId).toBe("");
|
|
expect(payload).not.toHaveProperty("assignTo");
|
|
});
|
|
|
|
it("maps range mode so create persists the start as scheduledDate", () => {
|
|
const draft = {
|
|
...EMPTY_TABLE_DRAFT,
|
|
site: "BK5",
|
|
locationId: "9",
|
|
woNumber: "25007",
|
|
pocName: "Jane",
|
|
pocPhone: "555-0100",
|
|
scheduledOn: "2026-06-08",
|
|
scheduleEnd: "2026-06-12",
|
|
schedMode: "range" as const,
|
|
scheduleWeekOnly: false,
|
|
};
|
|
|
|
const input = buildInlineDraftCreateInput(draft, [], [{ id: 9, name: "BK5 · Dallas, TX" }]);
|
|
const payload = mapWizardDraftToBoardCreatePayload(input);
|
|
|
|
expect(input.schedMode).toBe("range");
|
|
expect(input.scheduleEnd).toBe("2026-06-12");
|
|
expect(payload.scheduledDate).toBe("2026-06-08");
|
|
expect(payload.scheduleWeekOnly).toBeUndefined();
|
|
expect(payload.targetWeek).toBeUndefined();
|
|
expect(payload).not.toHaveProperty("scheduleEnd");
|
|
});
|
|
|
|
it("promotes Pending to Scheduled when create has a concrete date", () => {
|
|
const draft = {
|
|
...EMPTY_TABLE_DRAFT,
|
|
site: "BK5",
|
|
locationId: "9",
|
|
woNumber: "25006",
|
|
pocName: "Jane",
|
|
pocPhone: "555-0100",
|
|
status: "Pending" as const,
|
|
scheduledOn: "2026-06-01",
|
|
scheduleWeekOnly: false,
|
|
};
|
|
|
|
const input = buildInlineDraftCreateInput(draft, [], [{ id: 9, name: "BK5 · Dallas, TX" }]);
|
|
expect(input.status).toBe("Scheduled");
|
|
});
|
|
|
|
it("demotes Scheduled to Pending when create has no concrete date", () => {
|
|
const draft = {
|
|
...EMPTY_TABLE_DRAFT,
|
|
site: "BK5",
|
|
locationId: "9",
|
|
woNumber: "25005",
|
|
pocName: "Jane",
|
|
pocPhone: "555-0100",
|
|
status: "Scheduled" as const,
|
|
scheduledOn: "",
|
|
scheduleWeekOnly: true,
|
|
targetWeek: "",
|
|
};
|
|
|
|
const input = buildInlineDraftCreateInput(draft, [], [{ id: 9, name: "BK5 · Dallas, TX" }]);
|
|
expect(input.status).toBe("Pending");
|
|
});
|
|
});
|