shoc-frontend-new/src/test/domain/work-orders/mappers/completed-date-board-column.test.ts
Alexandre Brandizzi 460397dacb fix(workorders): let dispatchers clear the completed date from the board cell (SH-390)
The completed-date cell editor had no Clear control. It now offers Clear
when a date is set and the row is editable, patching completedDate to an
empty value, which the board PATCH persists as null. Completed and
Canceled rows stay locked, matching set/change.
2026-09-24 20:44:08 -03:00

32 lines
1.4 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { WO_TABLE_COLS } from "@/app/(protected)/workorders/_components/list/table/wo-table-cols";
import { expandScalarBoardOps } from "@/domain/work-orders/mappers/expand-scalar-board-ops";
import { mapWorkOrderTableRow } from "@/domain/work-orders/mappers/work-order-table-row-mapper";
describe("COMPLETED DATE board column wiring", () => {
it("includes COMPLETED DATE column between STATUS and COMP DOC", () => {
const keys = WO_TABLE_COLS.map((col) => col.key);
expect(keys).toContain("completed");
expect(keys.indexOf("completed")).toBe(keys.indexOf("status") + 1);
expect(keys.indexOf("completed")).toBeLessThan(keys.indexOf("doc"));
});
it("expands completedDate patch to board field op", () => {
const ops = expandScalarBoardOps({ completedDate: "2026-07-30" });
expect(ops).toEqual([{ field: "completedDate", value: "2026-07-30" }]);
});
it("expands a clearing completedDate patch to an empty-string board field op (SH-390)", () => {
const ops = expandScalarBoardOps({ completedDate: "" });
expect(ops).toEqual([{ field: "completedDate", value: "" }]);
});
it("maps completedDate returned by a board GET row", () => {
const row = mapWorkOrderTableRow({
id: 42,
completedDate: "2026-07-30T00:00:00Z",
});
expect(row.completedDate).toBe("2026-07-30");
});
});