2026-07-17 10:45:59 -03:00
|
|
|
import { describe, expect, it } from "vitest";
|
|
|
|
|
import {
|
|
|
|
|
buildSlideOverPatch,
|
|
|
|
|
isSlideOverDraftDirty,
|
|
|
|
|
SLIDE_OVER_EDIT_KEYS,
|
|
|
|
|
} from "@/domain/work-orders/utils/slide-over-draft";
|
|
|
|
|
import type { WorkOrderTableRow } from "@/domain/work-orders/types/work-order-table-row";
|
|
|
|
|
|
|
|
|
|
function baseRow(overrides: Partial<WorkOrderTableRow> = {}): WorkOrderTableRow {
|
|
|
|
|
return {
|
|
|
|
|
id: 1,
|
|
|
|
|
woNumber: "1001",
|
|
|
|
|
site: "SITE-A",
|
|
|
|
|
type: "PM",
|
2026-08-14 11:59:52 -03:00
|
|
|
severity: null,
|
2026-07-17 10:45:59 -03:00
|
|
|
dispatcherId: "10",
|
|
|
|
|
dispatcherName: "Alex",
|
|
|
|
|
scheduledOn: "2026-07-16",
|
2026-08-10 17:12:13 -03:00
|
|
|
completedDate: "",
|
2026-07-17 10:45:59 -03:00
|
|
|
targetWeek: "",
|
|
|
|
|
dayGroup: "2026-07-16",
|
|
|
|
|
dayLabel: "Thu",
|
|
|
|
|
location: "Main",
|
|
|
|
|
locationId: 5,
|
|
|
|
|
pm: "Plumbing",
|
|
|
|
|
serviceNotes: "",
|
|
|
|
|
extraServices: [],
|
|
|
|
|
vendorId: "v1",
|
|
|
|
|
company: "Acme",
|
|
|
|
|
tech: "Sam",
|
|
|
|
|
techPhone: "",
|
|
|
|
|
apptStart: "",
|
|
|
|
|
apptEnd: "",
|
|
|
|
|
apptTime: "09:00",
|
|
|
|
|
status: "Incomplete",
|
|
|
|
|
docStatus: "",
|
|
|
|
|
pocName: "",
|
|
|
|
|
pocPhone: "",
|
|
|
|
|
pocNotes: "",
|
|
|
|
|
dueDate: "2026-07-20",
|
|
|
|
|
rescheduleCount: 0,
|
|
|
|
|
carriedOver: 0,
|
|
|
|
|
originalWeek: "",
|
|
|
|
|
originalDate: "",
|
|
|
|
|
isPastDue: false,
|
|
|
|
|
scheduleWeekOnly: false,
|
|
|
|
|
mediaCount: 0,
|
|
|
|
|
title: "",
|
|
|
|
|
priority: "",
|
|
|
|
|
primaryDispatchId: null,
|
|
|
|
|
rowVersion: "1",
|
|
|
|
|
dispatchRowVersion: "",
|
|
|
|
|
flagColor: null,
|
|
|
|
|
...overrides,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
describe("slide-over-draft", () => {
|
|
|
|
|
it("exposes only board-persistable edit keys", () => {
|
|
|
|
|
expect(SLIDE_OVER_EDIT_KEYS).toContain("woNumber");
|
|
|
|
|
expect(SLIDE_OVER_EDIT_KEYS).toContain("status");
|
2026-08-10 17:12:13 -03:00
|
|
|
expect(SLIDE_OVER_EDIT_KEYS).toContain("vendorId");
|
2026-07-17 10:45:59 -03:00
|
|
|
expect(SLIDE_OVER_EDIT_KEYS).not.toContain("pocName");
|
|
|
|
|
expect(SLIDE_OVER_EDIT_KEYS).not.toContain("locationId");
|
|
|
|
|
expect(SLIDE_OVER_EDIT_KEYS).not.toContain("techPhone");
|
2026-08-10 17:12:13 -03:00
|
|
|
expect(SLIDE_OVER_EDIT_KEYS).not.toContain("company");
|
|
|
|
|
expect(SLIDE_OVER_EDIT_KEYS).not.toContain("tech");
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("tracks vendor via vendorId only (company/tech are display companions)", () => {
|
|
|
|
|
const row = baseRow();
|
|
|
|
|
const draft = baseRow({ company: "Other Co", tech: "Pat" });
|
|
|
|
|
expect(isSlideOverDraftDirty(draft, row)).toBe(false);
|
|
|
|
|
expect(buildSlideOverPatch(draft, row)).toEqual({});
|
|
|
|
|
|
|
|
|
|
const vendorDraft = baseRow({ vendorId: "v2", company: "Other Co", tech: "Pat" });
|
|
|
|
|
expect(isSlideOverDraftDirty(vendorDraft, row)).toBe(true);
|
|
|
|
|
expect(buildSlideOverPatch(vendorDraft, row)).toEqual({ vendorId: "v2" });
|
2026-07-17 10:45:59 -03:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("ignores POC-only edits for dirty state", () => {
|
|
|
|
|
const row = baseRow();
|
|
|
|
|
const draft = baseRow({ pocName: "Jordan", pocPhone: "555-0100" });
|
|
|
|
|
expect(isSlideOverDraftDirty(draft, row)).toBe(false);
|
|
|
|
|
expect(buildSlideOverPatch(draft, row)).toEqual({});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("detects dirty draft when a tracked field changes", () => {
|
|
|
|
|
const row = baseRow();
|
|
|
|
|
const draft = baseRow({ scheduledOn: "2026-07-17" });
|
|
|
|
|
expect(isSlideOverDraftDirty(draft, row)).toBe(true);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("is not dirty when values match", () => {
|
|
|
|
|
const row = baseRow();
|
|
|
|
|
expect(isSlideOverDraftDirty(row, row)).toBe(false);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("builds a patch with only changed fields", () => {
|
|
|
|
|
const row = baseRow();
|
|
|
|
|
const draft = baseRow({
|
|
|
|
|
woNumber: "1002",
|
|
|
|
|
status: "Completed",
|
|
|
|
|
extraServices: ["HVAC"],
|
|
|
|
|
});
|
|
|
|
|
expect(buildSlideOverPatch(draft, row)).toEqual({
|
|
|
|
|
woNumber: "1002",
|
|
|
|
|
status: "Completed",
|
|
|
|
|
extraServices: ["HVAC"],
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|