import { describe, expect, it } from "vitest"; import type { SkillView } from "@/lib/api/types"; import { groupByScope, scopeLabel, tierLabel } from "./skills"; const skill = (over: Partial): SkillView => ({ name: "x", scope: "builtin", tier: "analyst", ...over, }); describe("scopeLabel / tierLabel", () => { it("maps known values, passes through unknown", () => { expect(scopeLabel("builtin")).toBe("内置"); expect(scopeLabel("mystery")).toBe("mystery"); expect(tierLabel("writer")).toBe("写手"); expect(tierLabel("xl")).toBe("xl"); }); }); describe("groupByScope", () => { it("groups by scope in first-seen order, preserves within-group order", () => { const skills: SkillView[] = [ skill({ name: "a", scope: "builtin" }), skill({ name: "b", scope: "custom" }), skill({ name: "c", scope: "builtin" }), ]; const groups = groupByScope(skills); expect(groups.map((g) => g.scope)).toEqual(["builtin", "custom"]); expect(groups[0].skills.map((s) => s.name)).toEqual(["a", "c"]); expect(groups[1].skills.map((s) => s.name)).toEqual(["b"]); }); it("handles undefined", () => { expect(groupByScope(undefined)).toEqual([]); }); });