┌─ TS ───────────────────────────────────────────────────────────────────────┐
│ import { describe, expect, it } from "vitest"; │
│ import { layoutPath, pathSegs } from "./GitPath"; │
│ │
│ const repo = { name: "ooknet.org", slug: "ooknet-org" }; │
│ │
│ describe("pathSegs", () => { │
│ it("links every segment but the leaf", () => { │
│ const segs = pathSegs(repo, "master", "src/lib/git.ts"); │
│ expect(segs.map((s) => s.label)).toEqual(["ooknet.org", "src", "lib", "git.ts" │
│ ]); │
│ expect(segs[0].href).toBe("/git/ooknet-org/"); │
│ expect(segs[1].href).toBe("/git/ooknet-org/tree/master/src/"); │
│ expect(segs[2].href).toBe("/git/ooknet-org/tree/master/src/lib/"); │
│ expect(segs[3].href).toBeUndefined(); │
│ }); │
│ │
│ it("links the leaf on tree pages", () => { │
│ const segs = pathSegs(repo, "master", "src/lib", true); │
│ expect(segs[2].href).toBe("/git/ooknet-org/tree/master/src/lib/"); │
│ }); │
│ }); │
│ │
│ describe("layoutPath", () => { │
│ it("hard-wraps single segments wider than the frame", () => { │
│ const long = "death_knight_frost_race_p1_raid_cleave_burst.json"; │
│ const segs = pathSegs(repo, "master", `web/data/${long}`); │
│ const rows = layoutPath(segs, 48); │
│ const joined = rows.flat().map((s) => s.label).join("").replace(/^ooknet.orgwe │
│ bdata/, ""); │
│ expect(joined).toBe(long); │
│ for (const row of rows) { │
│ const width = row.reduce((n, s, j) => n + s.label.length + (j > 0 && !s.cont │
│ ? 3 : 0), 0); │
│ expect(width).toBeLessThanOrEqual(48); │
│ } │
│ }); │
│ │
│ it("wraps long paths at segment boundaries", () => { │
│ const segs = pathSegs(repo, "master", "a-long-directory/another-long-one/deepe │
│ r/file.ts"); │
│ const rows = layoutPath(segs, 30); │
│ expect(rows.length).toBeGreaterThan(1); │
│ expect(rows.flat().map((s) => s.label)).toEqual(segs.map((s) => s.label)); │
│ }); │
│ }); │
└────────────────────────────────────────────────────────────────────────────────────┘
┌─ TS ─────────────────────────────────┐
│ import { describe, expect, it } from "vitest │
│ "; │
│ import { layoutPath, pathSegs } from "./GitP │
│ ath"; │
│ │
│ const repo = { name: "ooknet.org", slug: "oo │
│ knet-org" }; │
│ │
│ describe("pathSegs", () => { │
│ it("links every segment but the leaf", () │
│ => { │
│ const segs = pathSegs(repo, "master", "s │
│ rc/lib/git.ts"); │
│ expect(segs.map((s) => s.label)).toEqual │
│ (["ooknet.org", "src", "lib", "git.ts"]); │
│ expect(segs[0].href).toBe("/git/ooknet-o │
│ rg/"); │
│ expect(segs[1].href).toBe("/git/ooknet-o │
│ rg/tree/master/src/"); │
│ expect(segs[2].href).toBe("/git/ooknet-o │
│ rg/tree/master/src/lib/"); │
│ expect(segs[3].href).toBeUndefined(); │
│ }); │
│ │
│ it("links the leaf on tree pages", () => { │
│ const segs = pathSegs(repo, "master", "s │
│ rc/lib", true); │
│ expect(segs[2].href).toBe("/git/ooknet-o │
│ rg/tree/master/src/lib/"); │
│ }); │
│ }); │
│ │
│ describe("layoutPath", () => { │
│ it("hard-wraps single segments wider than │
│ the frame", () => { │
│ const long = "death_knight_frost_race_p1 │
│ _raid_cleave_burst.json"; │
│ const segs = pathSegs(repo, "master", `w │
│ eb/data/${long}`); │
│ const rows = layoutPath(segs, 48); │
│ const joined = rows.flat().map((s) => s. │
│ label).join("").replace(/^ooknet.orgwebdata/ │
│ , ""); │
│ expect(joined).toBe(long); │
│ for (const row of rows) { │
│ const width = row.reduce((n, s, j) => │
│ n + s.label.length + (j > 0 && !s.cont ? 3 : │
│ 0), 0); │
│ expect(width).toBeLessThanOrEqual(48); │
│ } │
│ }); │
│ │
│ it("wraps long paths at segment boundaries │
│ ", () => { │
│ const segs = pathSegs(repo, "master", "a │
│ -long-directory/another-long-one/deeper/file │
│ .ts"); │
│ const rows = layoutPath(segs, 30); │
│ expect(rows.length).toBeGreaterThan(1); │
│ expect(rows.flat().map((s) => s.label)). │
│ toEqual(segs.map((s) => s.label)); │
│ }); │
│ }); │
└──────────────────────────────────────────────┘