import { getActiveNavPath, getNavGroups, navGroups } from "@/config/menu"; import { describe, expect, it } from "vitest"; describe("getActiveNavPath", () => { it.each([ ["/", "/"], ["/vendors", "/vendors"], ["/vendors/42", "/vendors"], ["/vendors/42/edit", "/vendors"], ["/vendors/insights", "/vendors/insights"], ["/vendors/preferences", "/vendors/preferences"], ["/vendor-pos/42", "/vendor-pos"], ["/settings/services", "/settings/services"], ["/uplifts", "/uplifts"], ["/uplifts/12", "/uplifts"], ])("selects one longest boundary-matching route for %s", (pathname, expectedPath) => { expect(getActiveNavPath(pathname)).toBe(expectedPath); }); it("does not match partial route segments", () => { expect(getActiveNavPath("/vendor-posts")).toBeUndefined(); }); it("does not highlight the Services entry from other settings tabs", () => { expect(getActiveNavPath("/settings/dropdowns")).toBeUndefined(); }); }); describe("navGroups", () => { it("always offers Services in a DATA MANAGEMENT group", () => { const dataManagement = navGroups.find((group) => group.title === "DATA MANAGEMENT"); expect(dataManagement?.items.map((item) => item.path)).toContain("/settings/services"); }); it("does not include the approvals group by default", () => { expect(navGroups.some((group) => group.title === "APPROVALS")).toBe(false); }); }); describe("getNavGroups", () => { it("adds the APPROVALS group with Uplift Approvals for uplift reviewers", () => { const groups = getNavGroups({ canReviewUplifts: true }); const approvals = groups.find((group) => group.title === "APPROVALS"); expect(approvals?.items.map((item) => item.path)).toEqual(["/uplifts"]); expect(approvals?.items[0]?.label).toBe("Uplift Approvals"); }); it("omits the APPROVALS group for users who cannot review uplifts", () => { const groups = getNavGroups({ canReviewUplifts: false }); expect(groups.some((group) => group.title === "APPROVALS")).toBe(false); }); it("keeps the approvals group after TEAM", () => { const groups = getNavGroups({ canReviewUplifts: true }); const titles = groups.map((group) => group.title); expect(titles.indexOf("TEAM")).toBeLessThan(titles.indexOf("APPROVALS")); }); });