| 1 | import { describe, expect, it } from "vite-plus/test"; |
| 2 | import { guideFocusedRows } from "./guideDiffFocus"; |
| 3 | |
| 4 | describe("guide diff focus", () => { |
| 5 | const rows = [ |
| 6 | { id: "old", kind: "line" as const, fileId: "a", oldLineNumber: 10, change: "delete" as const }, |
| 7 | { id: "new", kind: "line" as const, fileId: "a", newLineNumber: 20, change: "add" as const }, |
| 8 | { id: "context", kind: "line" as const, fileId: "a", oldLineNumber: 11, newLineNumber: 21 }, |
| 9 | { id: "other", kind: "line" as const, fileId: "b", newLineNumber: 20 }, |
| 10 | ]; |
| 11 | it("uses the requested side and includes both range boundaries only in the target file", () => { |
| 12 | expect( |
| 13 | guideFocusedRows(rows, "a", { side: "old", start: 10, end: 11 }).map((r) => r.id), |
| 14 | ).toEqual(["old", "context"]); |
| 15 | expect( |
| 16 | guideFocusedRows(rows, "a", { side: "new", start: 20, end: 21 }).map((r) => r.id), |
| 17 | ).toEqual(["new", "context"]); |
| 18 | }); |
| 19 | it("does not select unrelated rows while a later file is loading", () => { |
| 20 | expect(guideFocusedRows(rows, undefined, { side: "new", start: 20, end: 21 })).toEqual([]); |
| 21 | expect(guideFocusedRows(rows, "a", undefined)).toEqual([]); |
| 22 | }); |
| 23 | }); |