|
| 1 | +import { describe, expect, test } from "bun:test"; |
| 2 | +import { createTestDiffFile, lines } from "../../../test/helpers/diff-helpers"; |
| 3 | +import { buildSidebarEntries } from "./files"; |
| 4 | + |
| 5 | +describe("files helpers", () => { |
| 6 | + test("buildSidebarEntries hides zero-value sidebar stats", () => { |
| 7 | + const onlyAdd = createTestDiffFile({ |
| 8 | + id: "only-add", |
| 9 | + path: "src/ui/only-add.ts", |
| 10 | + before: lines("export const stable = true;"), |
| 11 | + after: lines( |
| 12 | + "export const stable = true;", |
| 13 | + "export const add1 = 1;", |
| 14 | + "export const add2 = 2;", |
| 15 | + "export const add3 = 3;", |
| 16 | + "export const add4 = 4;", |
| 17 | + "export const add5 = 5;", |
| 18 | + ), |
| 19 | + }); |
| 20 | + const onlyRemove = createTestDiffFile({ |
| 21 | + id: "only-remove", |
| 22 | + path: "src/ui/only-remove.ts", |
| 23 | + before: lines( |
| 24 | + "export const stable = true;", |
| 25 | + "export const remove1 = 1;", |
| 26 | + "export const remove2 = 2;", |
| 27 | + "export const remove3 = 3;", |
| 28 | + ), |
| 29 | + after: lines("export const stable = true;"), |
| 30 | + }); |
| 31 | + const renamedWithoutContentChanges = { |
| 32 | + ...createTestDiffFile({ |
| 33 | + id: "rename-only", |
| 34 | + path: "src/ui/Renamed.tsx", |
| 35 | + previousPath: "src/ui/Legacy.tsx", |
| 36 | + before: lines("export const stable = true;"), |
| 37 | + after: lines("export const stable = true;"), |
| 38 | + }), |
| 39 | + stats: { additions: 0, deletions: 0 }, |
| 40 | + }; |
| 41 | + |
| 42 | + const entries = buildSidebarEntries([onlyAdd, onlyRemove, renamedWithoutContentChanges]).filter( |
| 43 | + (entry) => entry.kind === "file", |
| 44 | + ); |
| 45 | + |
| 46 | + expect(entries).toHaveLength(3); |
| 47 | + expect(entries[0]).toMatchObject({ |
| 48 | + name: "only-add.ts", |
| 49 | + additionsText: "+5", |
| 50 | + deletionsText: null, |
| 51 | + }); |
| 52 | + expect(entries[1]).toMatchObject({ |
| 53 | + name: "only-remove.ts", |
| 54 | + additionsText: null, |
| 55 | + deletionsText: "-3", |
| 56 | + }); |
| 57 | + expect(entries[2]).toMatchObject({ |
| 58 | + name: "Legacy.tsx -> Renamed.tsx", |
| 59 | + additionsText: null, |
| 60 | + deletionsText: null, |
| 61 | + }); |
| 62 | + }); |
| 63 | +}); |
0 commit comments