import { describe, expect, it } from "vitest"; import { breadcrumbFor, breadcrumbLabel, type OrgMaps } from "@/lib/org"; import type { Database } from "@/lib/supabase/types"; type Division = Database["public"]["Tables"]["divisions"]["Row"]; type Department = Database["public"]["Tables"]["departments"]["Row"]; type Team = Database["public"]["Tables"]["teams"]["Row"]; type Location = Database["public"]["Tables"]["locations"]["Row"]; const division: Division = { id: "div-1", org_number: "20100000", name: "Produktion" }; const department: Department = { id: "dept-1", org_number: "21100000", name: "Fertigung", division_id: "div-1" }; const team: Team = { id: "team-1", org_number: "22010000", name: "Montage", department_id: "dept-1" }; const location: Location = { id: "loc-1", name: "Wien-Hernals", country: "Österreich" }; const orgMaps: OrgMaps = { divisions: new Map([[division.id, division]]), departments: new Map([[department.id, department]]), teams: new Map([[team.id, team]]), locations: new Map([[location.id, location]]), divisionList: [division], locationList: [location], }; describe("breadcrumbFor", () => { it("resolves division, department (via team), and team from ids", () => { const result = breadcrumbFor(orgMaps, division.id, team.id); expect(result.division?.name).toBe("Produktion"); expect(result.department?.name).toBe("Fertigung"); expect(result.team?.name).toBe("Montage"); }); it("has no team/department for a division head with no team (team_id null)", () => { const result = breadcrumbFor(orgMaps, division.id, null); expect(result.division?.name).toBe("Produktion"); expect(result.team).toBeUndefined(); expect(result.department).toBeUndefined(); }); }); describe("breadcrumbLabel", () => { it("joins division › department › team with the SAP-OM breadcrumb separator", () => { expect(breadcrumbLabel(orgMaps, division.id, team.id)).toBe("Produktion › Fertigung › Montage"); }); it("omits missing segments instead of producing empty separators", () => { expect(breadcrumbLabel(orgMaps, division.id, null)).toBe("Produktion"); }); it("falls back to a dash when nothing resolves", () => { expect(breadcrumbLabel(orgMaps, null, null)).toBe("–"); }); });