Simpl-Resultat/src/hooks/useHighlights.test.ts
le king fu 8b90cb6489
All checks were successful
PR Check / rust (push) Successful in 21m14s
PR Check / frontend (push) Successful in 2m16s
PR Check / rust (pull_request) Successful in 21m31s
PR Check / frontend (pull_request) Successful in 2m14s
feat(reports/highlights): default reference month to previous month + YTD current year, user-changeable (#106)
- 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
2026-04-19 08:28:30 -04:00

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,
});
});
});