2026-08-11 15:36:25 -04:00
|
|
|
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");
|
|
|
|
|
});
|
2026-09-25 16:35:40 -04:00
|
|
|
|
|
|
|
|
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");
|
|
|
|
|
});
|
2026-08-11 15:36:25 -04:00
|
|
|
});
|