import { expect, it } from "bun:test"; import { groupReviewHits, makeTextBatches, spansBySegment } from "../src/lib/project-review"; it("ordnet gebündelte API-Treffer nach Unicode-Positionen den richtigen Dateien zu", () => { const [batch] = makeTextBatches([ { key: "eins.txt", text: "😀 Max" }, { key: "zwei.txt", text: "Max und Max" }, ]); expect(batch.segments).toHaveLength(2); const second = batch.segments[1]; const spans = spansBySegment(batch, [ { start: 2, end: 5, original: "Max" }, { start: second.start, end: second.start + 3, original: "Max" }, { start: batch.segments[0].end, end: second.start + 1, original: "Grenztreffer" }, ]); expect(spans.get("eins.txt")).toEqual([{ start: 2, end: 5, original: "Max" }]); expect(spans.get("zwei.txt")).toEqual([{ start: 0, end: 3, original: "Max" }]); expect(makeTextBatches([{ key: "a", text: "abc" }, { key: "b", text: "def" }], 5)).toHaveLength(2); }); it("zeigt gleiche Zuordnungen einmal mit der Anzahl ihrer Vorkommen", () => { const hits = [ { id: "a", type: "PERSON", original: "Max", placeholder: "PERSON_01", file: "a.txt" }, { id: "b", type: "PERSON", original: "Max", placeholder: "PERSON_01", file: "b.txt" }, { id: "c", type: "PERSON", original: "Max", placeholder: "PERSON_02", file: "c.txt" }, { id: "d", type: "ORT", original: "Max", placeholder: "ORT_01", file: "a.txt" }, ]; const groups = groupReviewHits(hits); expect(groups).toHaveLength(3); expect(groups.find((group) => group.placeholder === "PERSON_01")?.hits).toHaveLength(2); expect(groups.find((group) => group.placeholder === "PERSON_01")?.hits.map((hit) => hit.id)).toEqual(["a", "b"]); });