mirror of
https://github.com/Sea-Haven-Industries/shoc-frontend-new.git
synced 2026-10-03 15:03:22 +00:00
* fix(work-orders): allow blank WO number in wizard create path
[recover] remove malicious eslint payload (was d0d08508)
* fix(work-orders): emit severity before type in board scalar PATCH ops
Co-authored-by: Cursor <cursoragent@cursor.com>
* chore(work-orders): drop vendor collateral from SH-192 lane
* fix(work-orders): add severity to unscheduled highlight fixture after dev merge
* refactor(work-orders): extract inline type/severity cell under function line cap
* fix(work-orders): add severity to comp-doc and media fixtures after dev merge
PR #45 introduced completion-doc, media and table-mutation fixtures that predate the required severity field, so the integrated head failed tsc. Fill severity on those row builders (null for PM, SEV 1 for the Emergency fixture) and type the mutation BASE_ROW instead of asserting it.
* test(work-orders): align merge fixes with severity field and WO# placeholder
---------
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Arthur Bassi <bassi-arthurr@users.noreply.github.com>
Co-authored-by: Alexandre Brandizzi <alex_brandizzi@hotmail.com>
100 lines
2.9 KiB
TypeScript
100 lines
2.9 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import {
|
|
buildSlideOverPatch,
|
|
isSlideOverDraftDirty,
|
|
} from "@/domain/work-orders/utils/slide-over-draft";
|
|
import type { WorkOrderTableRow } from "@/domain/work-orders/types/work-order-table-row";
|
|
|
|
/**
|
|
* Mirrors the failed-save path: optimistic parent row absorbs the patch, then
|
|
* rolls back, while draft is compared against a frozen pre-save baseline.
|
|
*/
|
|
function afterFailedOptimisticSave(input: {
|
|
baseline: WorkOrderTableRow;
|
|
draft: WorkOrderTableRow;
|
|
optimisticParent: WorkOrderTableRow;
|
|
rolledBackParent: WorkOrderTableRow;
|
|
}) {
|
|
const dirtyAgainstOptimistic = isSlideOverDraftDirty(input.draft, input.optimisticParent);
|
|
const dirtyAgainstBaseline = isSlideOverDraftDirty(input.draft, input.baseline);
|
|
const dirtyAgainstRolledBack = isSlideOverDraftDirty(input.draft, input.rolledBackParent);
|
|
const retryPatch = buildSlideOverPatch(input.draft, input.baseline);
|
|
return {
|
|
dirtyAgainstOptimistic,
|
|
dirtyAgainstBaseline,
|
|
dirtyAgainstRolledBack,
|
|
retryPatch,
|
|
canRetry: dirtyAgainstBaseline && Object.keys(retryPatch).length > 0,
|
|
};
|
|
}
|
|
|
|
function row(overrides: Partial<WorkOrderTableRow> = {}): WorkOrderTableRow {
|
|
return {
|
|
id: 1,
|
|
woNumber: "1001",
|
|
site: "SITE-A",
|
|
type: "PM",
|
|
severity: null,
|
|
dispatcherId: "10",
|
|
dispatcherName: "Alex",
|
|
scheduledOn: "2026-07-16",
|
|
completedDate: "",
|
|
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: "rv1",
|
|
dispatchRowVersion: "",
|
|
flagColor: null,
|
|
...overrides,
|
|
};
|
|
}
|
|
|
|
describe("slide-over failed-save baseline contract", () => {
|
|
it("stays dirty vs frozen baseline after optimistic parent absorbs the edit", () => {
|
|
const baseline = row({ woNumber: "1001" });
|
|
const draft = row({ woNumber: "2002" });
|
|
const optimisticParent = row({ woNumber: "2002" });
|
|
|
|
const result = afterFailedOptimisticSave({
|
|
baseline,
|
|
draft,
|
|
optimisticParent,
|
|
rolledBackParent: baseline,
|
|
});
|
|
|
|
// Bug the review caught: comparing against optimistic parent clears dirty.
|
|
expect(result.dirtyAgainstOptimistic).toBe(false);
|
|
expect(result.dirtyAgainstBaseline).toBe(true);
|
|
expect(result.dirtyAgainstRolledBack).toBe(true);
|
|
expect(result.canRetry).toBe(true);
|
|
expect(result.retryPatch).toEqual({ woNumber: "2002" });
|
|
});
|
|
});
|