Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

pullRequestFileSections.test.ts

22 lines979 Bytes

1import { describe, expect, it } from "vite-plus/test";
2import { buildReviewParsedDiff } from "../review/reviewModel";
3import { groupByDirectory } from "./pullRequestFileSections";
4​
5function patch(path: string) {
6 return `diff --git a/${path} b/${path}\n--- a/${path}\n+++ b/${path}\n@@ -1 +1 @@\n-old\n+new\n`;
7}
8​
9describe("groupByDirectory", () => {
10 it("keeps review order when a parent directory resumes after a subdirectory", () => {
11 const parsed = buildReviewParsedDiff(
12 ["src/a.ts", "src/lib/b.ts", "src/z.ts"].map(patch).join("\n"),
13 "pr",
14 );
15 if (parsed.kind !== "files") throw new Error("Expected files");
16 const items = groupByDirectory(parsed.files, new Set());
17 expect(
18 items.map((item) => (item.kind === "directory" ? `${item.directory}/` : item.file.path)),
19 ).toEqual(["src/", "src/a.ts", "src/lib/", "src/lib/b.ts", "src/", "src/z.ts"]);
20 expect(new Set(items.map((item) => item.key)).size).toBe(items.length);
21 });
22});