mirror of
https://github.com/Sea-Haven-Industries/shoc-frontend-new.git
synced 2026-10-06 22:52:06 +00:00
64 lines
2.4 KiB
TypeScript
64 lines
2.4 KiB
TypeScript
|
|
import { describe, expect, it } from "vitest";
|
|||
|
|
import {
|
|||
|
|
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");
|
|||
|
|
});
|
|||
|
|
});
|