feat: optionally sort translation mappings by creation date
This commit is contained in:
50
tests/mapping-created-at.test.ts
Normal file
50
tests/mapping-created-at.test.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
import { expect, it } from "bun:test";
|
||||
import { projectMappingCreatedAt, sortMappingRowsByCreatedAt } from "../src/lib/mapping-created-at";
|
||||
import type { ProjectRun } from "../src/lib/velum-project";
|
||||
import type { PlaceholderMapping } from "../src/types";
|
||||
|
||||
function run(createdAt: string, mapping: PlaceholderMapping): ProjectRun {
|
||||
return { version: 2, id: createdAt, projectPath: "/synthetic", projectName: "synthetic",
|
||||
createdAt, mapping, files: [] };
|
||||
}
|
||||
|
||||
it("ermittelt die erste gespeicherte Projektfassung je unveränderter Zuordnung", () => {
|
||||
const earlier = run("2026-01-01T10:00:00.000Z", {
|
||||
PERSON_01: { type: "PERSON", original: "Beispiel Eins" },
|
||||
ORG_01: { type: "ORG", original: "Frühere Organisation" },
|
||||
});
|
||||
const latest = run("2026-02-01T10:00:00.000Z", {
|
||||
PERSON_01: { type: "PERSON", original: "Beispiel Eins" },
|
||||
PERSON_02: { type: "PERSON", original: "Beispiel Zwei" },
|
||||
ORG_01: { type: "ORG", original: "Neue Organisation" },
|
||||
});
|
||||
expect(projectMappingCreatedAt([latest, earlier], latest.mapping)).toEqual({
|
||||
PERSON_01: earlier.createdAt,
|
||||
PERSON_02: latest.createdAt,
|
||||
ORG_01: latest.createdAt,
|
||||
});
|
||||
});
|
||||
|
||||
it("sortiert datierte Zuordnungen zuerst, sonst Nummern je Kategorie absteigend", () => {
|
||||
const rows = ["PERSON_02", "ORT_03", "PERSON_100", "ORT_20", "ORG_01", "PERSON_10"]
|
||||
.map((placeholder) => ({ placeholder, type: placeholder.split("_")[0] }));
|
||||
const sorted = sortMappingRowsByCreatedAt(rows, {
|
||||
PERSON_02: "2026-05-01T00:00:00.000Z",
|
||||
ORG_01: "2026-06-01T00:00:00.000Z",
|
||||
});
|
||||
expect(sorted.map((row) => row.placeholder))
|
||||
.toEqual(["ORG_01", "PERSON_02", "ORT_20", "ORT_03", "PERSON_100", "PERSON_10"]);
|
||||
});
|
||||
|
||||
it("behandelt importierte Erststände ohne echtes Anlagedatum als Nummern-Fallback", () => {
|
||||
const imported = { ...run("2026-01-01T10:00:00.000Z", {
|
||||
PERSON_01: { type: "PERSON", original: "Altbestand" },
|
||||
}), origin: "imported" as const };
|
||||
const later = { ...run("2026-02-01T10:00:00.000Z", {
|
||||
PERSON_01: { type: "PERSON", original: "Altbestand" },
|
||||
PERSON_02: { type: "PERSON", original: "Neu" },
|
||||
}), origin: "imported" as const, revisedFrom: imported.id };
|
||||
expect(projectMappingCreatedAt([later, imported], later.mapping)).toEqual({
|
||||
PERSON_02: later.createdAt,
|
||||
});
|
||||
});
|
||||
@@ -118,6 +118,22 @@ it("entfernt eine False-Positive-Gruppe aus der Sitzung und merkt alle Varianten
|
||||
]);
|
||||
});
|
||||
|
||||
it("bewahrt das Anlagedatum einer Sitzung beim Umklammern und Zusammenfassen", async () => {
|
||||
const session = await sessions.createSession("Zeitfolge");
|
||||
const first = await sessions.updateSessionMapping(session.id, {
|
||||
PERSON_01: { type: "PERSON", original: "Beispiel Eins" },
|
||||
});
|
||||
const created = first.mappingCreatedAt?.PERSON_01;
|
||||
expect(created).toBeTruthy();
|
||||
const next = await sessions.updateSessionMapping(session.id, {
|
||||
"<PERSON_01>": { type: "PERSON", original: "Beispiel Eins" },
|
||||
"<PERSON_02>": { type: "PERSON", original: "Beispiel Zwei", merged_into: "<PERSON_01>" },
|
||||
});
|
||||
expect(next.mappingCreatedAt?.["<PERSON_01>"]).toBe(created);
|
||||
expect(next.mappingCreatedAt?.["<PERSON_02>"]).toBeTruthy();
|
||||
expect(next.mappingCreatedAt?.PERSON_01).toBeUndefined();
|
||||
});
|
||||
|
||||
it("verlangt eine ausdrückliche Kontextwahl und legt ein Textprojekt nur einmal an", async () => {
|
||||
const root = await fs.mkdtemp(join(tmpdir(), "velum-text-context-"));
|
||||
roots.push(root);
|
||||
|
||||
Reference in New Issue
Block a user