41 lines
1.8 KiB
JavaScript
41 lines
1.8 KiB
JavaScript
import { test } from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import { sliceEditActionsWithDrafts } from "../../src/lib/annotation-autosave.js";
|
|
import { scanSliceEditConflicts, resolveSliceEditConflicts } from "../../src/lib/slice-edit-conflict.js";
|
|
|
|
test("parked text participates in the real boundary conflict resolution without duplicate actions", () => {
|
|
const slices = [
|
|
{ id: "s1", start: 0, end: 4 },
|
|
{ id: "s2", start: 4, end: 8 },
|
|
];
|
|
const original = [{ id: "a", start: 0, end: 4, description: "", status: "pending" }];
|
|
const draft = { sliceId: "s1", annotation: { ...original[0], description: " 保留草稿 " }, selectingEnd: false };
|
|
const prepared = sliceEditActionsWithDrafts(original, [draft]);
|
|
const pending = [
|
|
{ ...slices[0], end: 3.9 },
|
|
{ ...slices[1], start: 3.9 },
|
|
];
|
|
const scan = scanSliceEditConflicts({ baseSlices: slices, pendingSlices: pending, actions: prepared.actions });
|
|
assert.equal(scan.entries.length, 1);
|
|
const result = resolveSliceEditConflicts({
|
|
baseSlices: slices,
|
|
pendingSlices: pending,
|
|
actions: prepared.actions,
|
|
choices: { a: "truncate" },
|
|
});
|
|
assert(result.actions.every((a) => a.description === "保留草稿" && a.status === "described"));
|
|
assert.equal(
|
|
result.actions.reduce((n, a) => n + a.end - a.start, 0),
|
|
4,
|
|
);
|
|
assert.equal(original[0].description, "");
|
|
assert.equal(draft.annotation.description, " 保留草稿 ");
|
|
});
|
|
test("unfinished end selection is returned for navigation instead of being silently applied", () => {
|
|
const action = { id: "a", start: 0, end: 1, description: "未完成" };
|
|
const d = { sliceId: "s1", annotation: action, selectingEnd: true };
|
|
const result = sliceEditActionsWithDrafts([], [d]);
|
|
assert.deepEqual(result.actions, []);
|
|
assert.deepEqual(result.unresolved, [d]);
|
|
});
|