2026-09-01 14:16:52 -03:00
|
|
|
|
import { describe, expect, it } from "vitest";
|
|
|
|
|
|
import {
|
2026-09-02 09:47:34 -03:00
|
|
|
|
applyCarryOverDisplayDayFields,
|
2026-09-01 14:16:52 -03:00
|
|
|
|
formatCarriedOverHover,
|
|
|
|
|
|
isCarryOverDisplayRow,
|
|
|
|
|
|
mapCarryOverDisplayDay,
|
|
|
|
|
|
resolveCarryOverSourceWeek,
|
|
|
|
|
|
shouldShowCarriedOverPill,
|
|
|
|
|
|
} from "@/domain/work-orders/utils/carry-over-display";
|
|
|
|
|
|
|
|
|
|
|
|
describe("carry-over-display", () => {
|
|
|
|
|
|
it("hides the pill below 2 and on terminal statuses", () => {
|
|
|
|
|
|
expect(shouldShowCarriedOverPill(1, "Scheduled")).toBe(false);
|
|
|
|
|
|
expect(shouldShowCarriedOverPill(2, "Scheduled")).toBe(true);
|
|
|
|
|
|
expect(shouldShowCarriedOverPill(3, "Completed")).toBe(false);
|
|
|
|
|
|
expect(shouldShowCarriedOverPill(3, "Canceled")).toBe(false);
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it("formats hover without a source week", () => {
|
|
|
|
|
|
expect(formatCarriedOverHover(2)).toBe(
|
|
|
|
|
|
"Carried over 2 times — this WO was not completed and moved to the next period",
|
|
|
|
|
|
);
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it("appends the source week label from originalWeek", () => {
|
|
|
|
|
|
expect(formatCarriedOverHover(3, "2026-05-04")).toBe(
|
|
|
|
|
|
"Carried over 3 times — this WO was not completed and moved to the next period. Source week: 5/4–5/8.",
|
|
|
|
|
|
);
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it("resolves source week from originalWeek, then originalDate, then scheduledOn", () => {
|
|
|
|
|
|
expect(resolveCarryOverSourceWeek({ originalWeek: "2026-05-04" })).toBe("2026-05-04");
|
|
|
|
|
|
expect(resolveCarryOverSourceWeek({ originalDate: "2026-05-06" })).toBe("2026-05-04");
|
|
|
|
|
|
expect(resolveCarryOverSourceWeek({ scheduledOn: "2026-05-13" })).toBe("2026-05-11");
|
|
|
|
|
|
expect(resolveCarryOverSourceWeek({})).toBe("");
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it("treats non-terminal rows scheduled before the viewed week as carry-over", () => {
|
|
|
|
|
|
expect(
|
|
|
|
|
|
isCarryOverDisplayRow(
|
|
|
|
|
|
{ scheduledOn: "2026-05-13", status: "Scheduled", carriedOver: 1 },
|
|
|
|
|
|
"2026-05-18",
|
|
|
|
|
|
),
|
|
|
|
|
|
).toBe(true);
|
|
|
|
|
|
expect(
|
|
|
|
|
|
isCarryOverDisplayRow(
|
|
|
|
|
|
{ scheduledOn: "2026-05-20", status: "Scheduled", carriedOver: 2 },
|
|
|
|
|
|
"2026-05-18",
|
|
|
|
|
|
),
|
|
|
|
|
|
).toBe(false);
|
|
|
|
|
|
expect(
|
|
|
|
|
|
isCarryOverDisplayRow(
|
|
|
|
|
|
{ scheduledOn: "2026-05-13", status: "Completed", carriedOver: 2 },
|
|
|
|
|
|
"2026-05-18",
|
|
|
|
|
|
),
|
|
|
|
|
|
).toBe(false);
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it("maps the original weekday onto the viewed week and weekends onto Monday", () => {
|
|
|
|
|
|
expect(mapCarryOverDisplayDay("2026-05-13", "2026-05-18")).toBe("2026-05-20");
|
|
|
|
|
|
expect(mapCarryOverDisplayDay("2026-05-16", "2026-05-18")).toBe("2026-05-18");
|
|
|
|
|
|
expect(mapCarryOverDisplayDay("2026-05-17", "2026-05-18")).toBe("2026-05-18");
|
|
|
|
|
|
});
|
2026-09-02 09:47:34 -03:00
|
|
|
|
|
|
|
|
|
|
it("remaps dayGroup to the viewed weekday without changing scheduledOn", () => {
|
|
|
|
|
|
const row = {
|
|
|
|
|
|
scheduledOn: "2026-05-13",
|
|
|
|
|
|
status: "Scheduled",
|
|
|
|
|
|
dayGroup: "05/13",
|
|
|
|
|
|
dayLabel: "WED · 05/13",
|
|
|
|
|
|
};
|
|
|
|
|
|
const next = applyCarryOverDisplayDayFields(row, "2026-05-18");
|
|
|
|
|
|
expect(next.scheduledOn).toBe("2026-05-13");
|
|
|
|
|
|
expect(next.dayGroup).toBe("05/20");
|
|
|
|
|
|
expect(next.dayLabel).toBe("WED · 05/20");
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it("leaves in-week and terminal rows' dayGroup unchanged", () => {
|
|
|
|
|
|
const inWeek = {
|
|
|
|
|
|
scheduledOn: "2026-05-20",
|
|
|
|
|
|
status: "Scheduled",
|
|
|
|
|
|
dayGroup: "05/20",
|
|
|
|
|
|
dayLabel: "WED · 05/20",
|
|
|
|
|
|
};
|
|
|
|
|
|
const completed = {
|
|
|
|
|
|
scheduledOn: "2026-05-13",
|
|
|
|
|
|
status: "Completed",
|
|
|
|
|
|
dayGroup: "05/13",
|
|
|
|
|
|
dayLabel: "WED · 05/13",
|
|
|
|
|
|
};
|
|
|
|
|
|
expect(applyCarryOverDisplayDayFields(inWeek, "2026-05-18")).toEqual(inWeek);
|
|
|
|
|
|
expect(applyCarryOverDisplayDayFields(completed, "2026-05-18")).toEqual(completed);
|
|
|
|
|
|
});
|
2026-09-01 14:16:52 -03:00
|
|
|
|
});
|