Preserve diff tree order and collapsed folders (#11931)

This commit is contained in:
Julius Marminge authored and GitHub committed 2026-09-15 11:08:06 -07:00
1 parent 7235701de0
commit 3efdcc5296
4 files changed
+107 -4

No files matched your search

@@ -1,9 +1,12 @@
import type { FileDiffMetadata } from "@pierre/diffs";
import { preloadFileTree } from "@pierre/trees";
import { describe, expect, it } from "vite-plus/test";
import {
buildDiffFileTreeUpdates,
compareDiffFileTreeEntries,
collectDirectoryPaths,
diffFileTreePositions,
diffFileTreeEntries,
} from "./diffFileTree.logic";
@@ -41,6 +44,34 @@ describe("collectDirectoryPaths", () => {
});
});
describe("diff tree reading order", () => {
it("places folders and files where their first diff appears", () => {
const paths = [
"apps/mobile/src/state/shell.ts",
"apps/mobile/src/features/threads/route.ts",
"apps/mobile/src/features/threads/screen.tsx",
];
const positions = diffFileTreePositions(paths);
const tree = preloadFileTree({
paths,
initialExpansion: "open",
flattenEmptyDirectories: true,
sort: compareDiffFileTreeEntries(() => positions),
});
const rows = [...tree.shadowHtml.matchAll(/data-item-path="([^"]+)"/g)].map(
(match) => match[1],
);
expect(rows).toEqual([
"apps/mobile/src/",
"apps/mobile/src/state/",
"apps/mobile/src/state/shell.ts",
"apps/mobile/src/features/threads/",
"apps/mobile/src/features/threads/route.ts",
"apps/mobile/src/features/threads/screen.tsx",
]);
});
});
describe("buildDiffFileTreeUpdates", () => {
it("adds a new file's directories before the file", () => {
expect(buildDiffFileTreeUpdates(["README.md"], ["README.md", "src/lib/a.ts"])).toEqual([