- Extract shared defaultReferencePeriod helper (src/utils/referencePeriod.ts) - useHighlights now reads ?refY=YYYY&refM=MM, defaults to previous month - getHighlights signature: (referenceYear, referenceMonth, ytdYear, windowDays, ...) - YTD tile pinned to Jan 1 of current civil year, independent of reference month - CompareReferenceMonthPicker surfaced on /reports/highlights - Hub highlights panel inherits the same default via useHighlights - useCartes and useCompare now delegate their default-period helpers to the shared util
35 lines
1.5 KiB
TypeScript
35 lines
1.5 KiB
TypeScript
import { describe, it, expect } from "vitest";
|
|
import { resolveHighlightsReference } from "./useHighlights";
|
|
|
|
describe("resolveHighlightsReference", () => {
|
|
const TODAY = new Date(2026, 3, 14); // April 14, 2026
|
|
|
|
it("falls back to the previous month when no params are provided", () => {
|
|
expect(resolveHighlightsReference(null, null, TODAY)).toEqual({ year: 2026, month: 3 });
|
|
});
|
|
|
|
it("accepts a valid (year, month) pair from the URL", () => {
|
|
expect(resolveHighlightsReference("2025", "11", TODAY)).toEqual({ year: 2025, month: 11 });
|
|
});
|
|
|
|
it("rejects non-integer values and falls back to the default", () => {
|
|
expect(resolveHighlightsReference("abc", "3", TODAY)).toEqual({ year: 2026, month: 3 });
|
|
expect(resolveHighlightsReference("2026", "foo", TODAY)).toEqual({ year: 2026, month: 3 });
|
|
});
|
|
|
|
it("rejects out-of-range months and falls back to the default", () => {
|
|
expect(resolveHighlightsReference("2026", "0", TODAY)).toEqual({ year: 2026, month: 3 });
|
|
expect(resolveHighlightsReference("2026", "13", TODAY)).toEqual({ year: 2026, month: 3 });
|
|
});
|
|
|
|
it("rejects absurd years and falls back to the default", () => {
|
|
expect(resolveHighlightsReference("999", "6", TODAY)).toEqual({ year: 2026, month: 3 });
|
|
});
|
|
|
|
it("wraps January back to December of the previous year for the default", () => {
|
|
expect(resolveHighlightsReference(null, null, new Date(2026, 0, 10))).toEqual({
|
|
year: 2025,
|
|
month: 12,
|
|
});
|
|
});
|
|
});
|