The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 04:45 UTC
| 1 | import type { FileDiffMetadata } from "@pierre/diffs"; |
| 2 | import { describe, expect, it } from "vite-plus/test"; |
| 3 | |
| 4 | import { buildDiffFileTreeUpdates, diffFileTreeEntries } from "./diffFileTree.logic"; |
| 5 | |
| 6 | function file(type: FileDiffMetadata["type"], name: string, prevName = name): FileDiffMetadata { |
| 7 | return { type, name, prevName } as FileDiffMetadata; |
| 8 | } |
| 9 | |
| 10 | describe("diffFileTreeEntries", () => { |
| 11 | it("folds a file-to-symlink type change into one modified entry", () => { |
| 12 | expect( |
| 13 | diffFileTreeEntries([ |
| 14 | file("change", "CLAUDE.md"), |
| 15 | file("deleted", "AGENTS.md"), |
| 16 | file("new", "AGENTS.md"), |
| 17 | file("new", "docs/new.md"), |
| 18 | ]), |
| 19 | ).toEqual([ |
| 20 | { path: "CLAUDE.md", status: "modified" }, |
| 21 | { path: "AGENTS.md", status: "modified" }, |
| 22 | { path: "docs/new.md", status: "added" }, |
| 23 | ]); |
| 24 | }); |
| 25 | }); |
| 26 | |
| 27 | describe("buildDiffFileTreeUpdates", () => { |
| 28 | it("adds a new file's directories before the file", () => { |
| 29 | expect(buildDiffFileTreeUpdates(["README.md"], ["README.md", "src/lib/a.ts"])).toEqual([ |
| 30 | { type: "add", path: "src/" }, |
| 31 | { type: "add", path: "src/lib/" }, |
| 32 | { type: "add", path: "src/lib/a.ts" }, |
| 33 | ]); |
| 34 | }); |
| 35 | |
| 36 | it("removes files before their now-empty directories, deepest first", () => { |
| 37 | expect(buildDiffFileTreeUpdates(["src/lib/a.ts", "src/b.ts"], ["src/b.ts"])).toEqual([ |
| 38 | { type: "remove", path: "src/lib/a.ts" }, |
| 39 | { type: "remove", path: "src/lib/", recursive: true }, |
| 40 | ]); |
| 41 | }); |
| 42 | }); |