import { describe, it, expect } from "vitest"; import { resolveReportsPeriod } from "./useReportsPeriod"; describe("resolveReportsPeriod", () => { const fixedToday = new Date("2026-04-14T12:00:00Z"); it("defaults to current civil year when no URL params are set", () => { const result = resolveReportsPeriod(null, null, null, fixedToday); expect(result.from).toBe("2026-01-01"); expect(result.to).toBe("2026-12-31"); expect(result.period).toBe("custom"); }); it("restores state from bookmarked from/to params", () => { const result = resolveReportsPeriod("2025-03-01", "2025-06-30", null, fixedToday); expect(result.from).toBe("2025-03-01"); expect(result.to).toBe("2025-06-30"); expect(result.period).toBe("custom"); }); it("keeps period=yearly alongside explicit from/to", () => { const result = resolveReportsPeriod("2024-01-01", "2024-12-31", "year", fixedToday); expect(result.period).toBe("year"); }); it("ignores malformed dates and falls back to the civil year", () => { const result = resolveReportsPeriod("not-a-date", "also-not", null, fixedToday); expect(result.from).toBe("2026-01-01"); expect(result.to).toBe("2026-12-31"); expect(result.period).toBe("custom"); }); it("resolves preset period values without from/to", () => { const result = resolveReportsPeriod(null, null, "6months", fixedToday); expect(result.period).toBe("6months"); expect(result.from).toBeTruthy(); expect(result.to).toBeTruthy(); }); it("rejects an invalid period string and falls back to civil year custom", () => { const result = resolveReportsPeriod(null, null, "bogus", fixedToday); expect(result.period).toBe("custom"); expect(result.from).toBe("2026-01-01"); }); it("treats `all` as a preset with empty range (service handles the clauses)", () => { const result = resolveReportsPeriod(null, null, "all", fixedToday); expect(result.period).toBe("all"); // Fallback civil year when computeDateRange returns empty expect(result.from).toBe("2026-01-01"); expect(result.to).toBe("2026-12-31"); }); });