Diff-Endpunkt (GET /documents/{id}/diff) im versioningapi-Handler, Diff-Seite
mit freier Revisionswahl, Farbe+Symbol je Aenderung und Sprung zur naechsten
Aenderung im dms-browser-Frontend.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
37 lines
1.2 KiB
TypeScript
37 lines
1.2 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { countChanges, findNextChangeIndex, findPreviousChangeIndex } from "./diffNavigation";
|
|
import { DiffLine } from "./diffApi";
|
|
|
|
const lines: DiffLine[] = [
|
|
{ op: "equal", text: "a" },
|
|
{ op: "delete", text: "b" },
|
|
{ op: "equal", text: "c" },
|
|
{ op: "equal", text: "d" },
|
|
{ op: "insert", text: "e" },
|
|
{ op: "equal", text: "f" },
|
|
];
|
|
|
|
describe("diffNavigation", () => {
|
|
it("findNextChangeIndex springt zur naechsten Aenderung nach dem aktuellen Index", () => {
|
|
expect(findNextChangeIndex(lines, -1)).toBe(1);
|
|
expect(findNextChangeIndex(lines, 1)).toBe(4);
|
|
expect(findNextChangeIndex(lines, 4)).toBe(-1);
|
|
});
|
|
|
|
it("findPreviousChangeIndex springt zur vorherigen Aenderung", () => {
|
|
expect(findPreviousChangeIndex(lines, 6)).toBe(4);
|
|
expect(findPreviousChangeIndex(lines, 4)).toBe(1);
|
|
expect(findPreviousChangeIndex(lines, 1)).toBe(-1);
|
|
});
|
|
|
|
it("countChanges zaehlt alle Nicht-equal-Zeilen", () => {
|
|
expect(countChanges(lines)).toBe(2);
|
|
});
|
|
|
|
it("liefert -1 bei einer Liste ohne Aenderungen", () => {
|
|
const noChanges: DiffLine[] = [{ op: "equal", text: "x" }];
|
|
expect(findNextChangeIndex(noChanges, -1)).toBe(-1);
|
|
expect(countChanges(noChanges)).toBe(0);
|
|
});
|
|
});
|