datePresets.test.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /* @vitest-environment node */
  2. import { describe, it, expect } from "vitest";
  3. import { buildDatePresets, DATE_PRESET_KEY } from "./datePresets.js";
  4. describe("lib/frontend/search/datePresets", () => {
  5. it("builds stable ISO ranges for a fixed date", () => {
  6. const now = new Date(2026, 0, 15); // 2026-01-15 (local)
  7. const presets = buildDatePresets({ now });
  8. const byKey = Object.fromEntries(presets.map((p) => [p.key, p]));
  9. expect(byKey[DATE_PRESET_KEY.TODAY]).toMatchObject({
  10. from: "2026-01-15",
  11. to: "2026-01-15",
  12. });
  13. expect(byKey[DATE_PRESET_KEY.YESTERDAY]).toMatchObject({
  14. from: "2026-01-14",
  15. to: "2026-01-14",
  16. });
  17. expect(byKey[DATE_PRESET_KEY.LAST_7_DAYS]).toMatchObject({
  18. from: "2026-01-09",
  19. to: "2026-01-15",
  20. });
  21. expect(byKey[DATE_PRESET_KEY.THIS_MONTH]).toMatchObject({
  22. from: "2026-01-01",
  23. to: "2026-01-15",
  24. });
  25. expect(byKey[DATE_PRESET_KEY.LAST_MONTH]).toMatchObject({
  26. from: "2025-12-01",
  27. to: "2025-12-31",
  28. });
  29. expect(byKey[DATE_PRESET_KEY.THIS_YEAR]).toMatchObject({
  30. from: "2026-01-01",
  31. to: "2026-01-15",
  32. });
  33. });
  34. });