forked from longtao.wu/droboticflow
45 lines
1.9 KiB
JavaScript
45 lines
1.9 KiB
JavaScript
import test from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import {
|
|
annotationTaskEditableRange,
|
|
initialCaptureSlices,
|
|
analyzeSliceCoverage,
|
|
} from "../../src/lib/annotation-operations.js";
|
|
|
|
const task = {
|
|
id: "capture",
|
|
clipStart: 0,
|
|
clipEnd: 2515.485,
|
|
sourceIsFullVideo: true,
|
|
sourceDurationSeconds: 2515.485,
|
|
coverageStartSecond: 0.327,
|
|
coverageEndSecond: 1.929,
|
|
};
|
|
test("first entry fully covers exactly the API editable range, not the longer source clip", () => {
|
|
const range = annotationTaskEditableRange(task);
|
|
const slices = initialCaptureSlices(task);
|
|
assert.deepEqual(range, { start: 0.327, end: 1.929 });
|
|
assert.equal(analyzeSliceCoverage(slices, range.start, range.end).complete, true);
|
|
assert.equal(
|
|
initialCaptureSlices(task, [{ revision: 0, authorUserId: "system", segments: [{ start: 0, end: 2515.485 }] }])[0]
|
|
.end,
|
|
1.929,
|
|
);
|
|
});
|
|
test("existing human revisions and drafts are preserved, including conflicting data", () => {
|
|
const segments = [{ id: "human", name: "manual", start: 0, end: 2515.485 }];
|
|
assert.equal(initialCaptureSlices(task, [{ revision: 1, authorUserId: "human", segments }]), segments);
|
|
assert.equal(initialCaptureSlices(task, [], segments), segments);
|
|
assert.equal(analyzeSliceCoverage(segments, 0.327, 1.929).complete, false);
|
|
});
|
|
test("empty revisions and legacy task ranges initialize safely", () => {
|
|
assert.equal(initialCaptureSlices(task, [{ revision: 1, segments: [] }], []).length, 1);
|
|
assert.deepEqual(annotationTaskEditableRange({ sourceIsFullVideo: true, sourceDurationSeconds: 10 }), {
|
|
start: 0,
|
|
end: 10,
|
|
});
|
|
assert.deepEqual(annotationTaskEditableRange({ clipStart: 2, clipEnd: 4 }), { start: 2, end: 4 });
|
|
assert.deepEqual(initialCaptureSlices({ id: "invalid", clipStart: 0, clipEnd: 0 }), []);
|
|
assert.notEqual(initialCaptureSlices(task)[0].id, initialCaptureSlices({ ...task, id: "another" })[0].id);
|
|
});
|