121 lines
4.6 KiB
JavaScript
121 lines
4.6 KiB
JavaScript
import test from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import { computeReworkChanges, submittedReworkWorkspace } from "../../src/lib/rework-changes.js";
|
|
import { computeReworkEmphasis } from "../../src/lib/rework-emphasis.js";
|
|
const slices = [
|
|
{ id: "s1", name: "拿取", start: 0, end: 10 },
|
|
{ id: "s2", name: "放回", start: 10, end: 20 },
|
|
];
|
|
const actions = [
|
|
{ id: "a1", start: 0, end: 10, description: "动作一", status: "described" },
|
|
{ id: "a2", start: 10, end: 20, description: "动作二", status: "described" },
|
|
];
|
|
const baseline = {
|
|
round: 1,
|
|
slices,
|
|
actions,
|
|
problems: [{ id: "p1", scope: "slice", sliceId: "s1", text: "修正整片" }],
|
|
};
|
|
|
|
test("all-change view includes an edited action with no former opinion and preserves before/after", () => {
|
|
const now = actions.map((a) => (a.id === "a2" ? { ...a, description: "额外修改" } : a));
|
|
const e = computeReworkEmphasis({ baselines: [baseline], currentSlices: slices, currentActions: now });
|
|
assert.deepEqual(
|
|
e.changes.items.map((item) => item.sliceId),
|
|
["s2"],
|
|
);
|
|
assert.equal(e.unclearedCount, 1, "unrelated edits do not clear another slice's opinion");
|
|
assert.match(e.changes.items[0].details[0].before, /动作二/);
|
|
assert.match(e.changes.items[0].details[0].after, /额外修改/);
|
|
assert.deepEqual(e.changes.items[0].actionIds, ["a2"]);
|
|
});
|
|
|
|
test("undo and regenerated IDs leave no net changes; field order and audit metadata are ignored", () => {
|
|
const now = actions.toReversed().map((a) => ({ ...a, id: `new-${a.id}`, savedAt: "ignored" }));
|
|
assert.deepEqual(
|
|
computeReworkChanges(
|
|
baseline,
|
|
slices.map((s) => ({ ...s, id: `new-${s.id}` })),
|
|
now,
|
|
).items,
|
|
[],
|
|
);
|
|
});
|
|
|
|
test("split, merge and discard highlight every affected surviving slice", () => {
|
|
const split = [{ ...slices[0], end: 4 }, { ...slices[0], id: "child", start: 4 }, slices[1]];
|
|
const splitActions = [{ ...actions[0], end: 4 }, { ...actions[0], id: "child-action", start: 4 }, actions[1]];
|
|
assert.deepEqual(
|
|
computeReworkChanges(baseline, split, splitActions).items.map((item) => item.sliceId),
|
|
["s1", "child"],
|
|
);
|
|
const merged = [{ ...slices[0], end: 20 }];
|
|
assert.match(computeReworkChanges(baseline, merged, actions).items[0].details[0].kind, /合并/);
|
|
const discarded = [{ ...slices[0], name: "", deliveryDisposition: "discard", discardReason: "遮挡" }, slices[1]];
|
|
const item = computeReworkChanges(baseline, discarded, [actions[1]]).items[0];
|
|
assert.match(item.details[0].after, /舍弃:遮挡/);
|
|
assert.ok(item.details.some((d) => d.kind.includes("移除")));
|
|
});
|
|
|
|
test("boundary, hand, label, state and deletion changes remain visible without original problems", () => {
|
|
for (const patch of [
|
|
{ description: "修改" },
|
|
{ handedness: "left" },
|
|
{ labelId: "new-label" },
|
|
{ label: "新的动作类别" },
|
|
{ status: "invalid", isInvalid: true },
|
|
{ end: 19.9 },
|
|
]) {
|
|
assert.equal(
|
|
computeReworkChanges({ ...baseline, problems: [] }, slices, [actions[0], { ...actions[1], ...patch }]).items[0]
|
|
.sliceId,
|
|
"s2",
|
|
);
|
|
}
|
|
assert.equal(computeReworkChanges(baseline, slices, [actions[0]]).items[0].sliceId, "s2");
|
|
});
|
|
|
|
test("missing legacy snapshots and a missing current-round baseline remain unknown", () => {
|
|
assert.equal(computeReworkChanges({ slices }, slices, actions).available, false);
|
|
const e = computeReworkEmphasis({
|
|
baselines: [baseline],
|
|
currentRound: 2,
|
|
currentSlices: slices,
|
|
currentActions: actions,
|
|
});
|
|
assert.equal(e.changes.available, false);
|
|
});
|
|
|
|
test("only the current round supplies all-change comparisons", () => {
|
|
const round2 = {
|
|
...baseline,
|
|
round: 2,
|
|
actions: actions.map((a) => ({ ...a, description: a.description + "第二轮" })),
|
|
};
|
|
const e = computeReworkEmphasis({
|
|
baselines: [baseline, round2],
|
|
currentRound: 2,
|
|
currentSlices: slices,
|
|
currentActions: round2.actions,
|
|
});
|
|
assert.deepEqual(e.changes.items, []);
|
|
});
|
|
|
|
test("QC reads a matching submitted revision pair, not a live draft or later generated slices", () => {
|
|
const detail = {
|
|
task: { currentRevision: 2 },
|
|
sliceRevisions: [
|
|
{ revision: 2, segments: slices },
|
|
{ revision: 3, segments: [] },
|
|
],
|
|
revisions: [
|
|
{ revision: 1, segments: [] },
|
|
{ revision: 2, segments: actions },
|
|
],
|
|
humanItem: { subject: { payload: { annotationWorkspace: { segments: [] } } } },
|
|
};
|
|
assert.deepEqual(submittedReworkWorkspace(detail).actions, actions);
|
|
assert.deepEqual(submittedReworkWorkspace(detail).slices, slices);
|
|
assert.equal(submittedReworkWorkspace({ ...detail, revisions: [{ revision: 1, segments: actions }] }), null);
|
|
});
|