mirror of
https://github.com/Sea-Haven-Industries/seahaven-ap.git
synced 2026-10-03 05:43:13 +00:00
28 lines
1.3 KiB
TypeScript
28 lines
1.3 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { formatRelativeFromIsoDate, formatSlashDate } from "@/dashboard/invoice-date-format";
|
|
|
|
describe("invoice column date helpers (AP-47)", () => {
|
|
it("formats ISO dates as MM/DD/YYYY", () => {
|
|
expect(formatSlashDate("2026-04-10")).toBe("04/10/2026");
|
|
});
|
|
|
|
it("formats relative ages from a fixed now", () => {
|
|
const now = new Date("2026-08-11T12:00:00");
|
|
expect(formatRelativeFromIsoDate("2026-08-11", now)).toBe("today");
|
|
expect(formatRelativeFromIsoDate("2026-08-10", now)).toBe("1 day ago");
|
|
expect(formatRelativeFromIsoDate("2026-02-11", now)).toBe("6 months ago");
|
|
});
|
|
|
|
it("uses calendar days so early hours still treat yesterday as 1 day ago", () => {
|
|
const earlyMorning = new Date("2026-08-11T01:15:00");
|
|
expect(formatRelativeFromIsoDate("2026-08-10", earlyMorning)).toBe("1 day ago");
|
|
expect(formatRelativeFromIsoDate("2026-08-11", earlyMorning)).toBe("today");
|
|
});
|
|
|
|
it("formats future invoice and due dates instead of clamping to today", () => {
|
|
const now = new Date("2026-08-11T12:00:00");
|
|
expect(formatRelativeFromIsoDate("2026-08-12", now)).toBe("in 1 day");
|
|
expect(formatRelativeFromIsoDate("2026-08-16", now)).toBe("in 5 days");
|
|
expect(formatRelativeFromIsoDate("2026-10-11", now)).toBe("in 2 months");
|
|
});
|
|
});
|