breadcrumbDropdowns.test.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /* @vitest-environment node */
  2. import { describe, it, expect } from "vitest";
  3. import {
  4. normalizeNumericOptions,
  5. buildExplorerDropdownItems,
  6. } from "./breadcrumbDropdowns";
  7. describe("lib/frontend/explorer/breadcrumbDropdowns", () => {
  8. describe("normalizeNumericOptions", () => {
  9. it("returns null for non-arrays or empty arrays", () => {
  10. expect(normalizeNumericOptions(null)).toBe(null);
  11. expect(normalizeNumericOptions(undefined)).toBe(null);
  12. expect(normalizeNumericOptions([])).toBe(null);
  13. });
  14. it("deduplicates and sorts numeric strings descending", () => {
  15. expect(normalizeNumericOptions(["1", "10", "2", "2", ""])).toEqual([
  16. "10",
  17. "2",
  18. "1",
  19. ]);
  20. });
  21. });
  22. describe("buildExplorerDropdownItems", () => {
  23. it("builds year items only when year is present", () => {
  24. const res = buildExplorerDropdownItems({
  25. branch: "NL01",
  26. year: "2024",
  27. yearOptions: ["2023", "2024", "2025"],
  28. });
  29. expect(res.yearItems?.[0]).toMatchObject({
  30. value: "2025",
  31. label: "2025",
  32. href: "/NL01/2025",
  33. });
  34. });
  35. it("builds month items with German labels", () => {
  36. const res = buildExplorerDropdownItems({
  37. branch: "NL01",
  38. year: "2024",
  39. month: "10",
  40. monthOptions: ["01", "10"],
  41. });
  42. // October must become "Oktober (10)" per formatter
  43. expect(res.monthItems?.find((x) => x.value === "10")?.label).toBe(
  44. "Oktober (10)"
  45. );
  46. });
  47. it("builds day items only when day is present", () => {
  48. const res = buildExplorerDropdownItems({
  49. branch: "NL01",
  50. year: "2024",
  51. month: "10",
  52. day: "23",
  53. dayOptions: ["01", "23"],
  54. });
  55. expect(res.dayItems?.find((x) => x.value === "23")?.href).toBe(
  56. "/NL01/2024/10/23"
  57. );
  58. });
  59. });
  60. });