import { describe, expect, it } from "vitest"; import { t } from "@/lib/i18n"; import { pickRepoLabel } from "./vcs-dialogs"; /** * `pickRepoLabel` feeds the commit and change-request dialog titles, which * render it through `integrations:commitChangesScoped` / `createScoped`. Two of * its three branches used to return hardcoded English ("All repos", * "Repository") inside those now-translated titles; these cases pin that they * resolve through the catalog while the repo-name branches keep returning * user data verbatim. * * `vitest.setup.ts` initializes i18next in `en`, so `t()` returns the English * catalog values here. */ describe("pickRepoLabel", () => { const noDisplayName = () => undefined; it("prefers the resolved display name for an explicitly scoped repo", () => { expect(pickRepoLabel("api", false, (name) => `kdlbs/${name}`, t)).toBe("kdlbs/api"); }); it("falls back to the raw repo name when it has no display name", () => { // Repository names are user data and must never be translated. expect(pickRepoLabel("api", false, noDisplayName, t)).toBe("api"); }); it("translates the multi-repo fan-out label when no repo is scoped", () => { expect(pickRepoLabel(undefined, true, noDisplayName, t)).toBe(t("integrations:allRepos")); }); it("translates an explicit workspace-root scope separately from fan-out", () => { expect(pickRepoLabel("", true, noDisplayName, t)).toBe(t("integrations:repository")); }); it("translates the single-repo fallback when the primary repo has no display name", () => { expect(pickRepoLabel(undefined, false, noDisplayName, t)).toBe(t("integrations:repository")); }); it("prefers the primary repo's display name over the translated fallback", () => { expect(pickRepoLabel("", false, () => "kdlbs/kandev", t)).toBe("kdlbs/kandev"); }); });