27 lines
1.6 KiB
TypeScript
27 lines
1.6 KiB
TypeScript
import assert from "node:assert/strict";
|
|
import test from "node:test";
|
|
// @ts-expect-error Node's native TypeScript runner requires the explicit extension.
|
|
import { resizeTranscriptRange, snapTimelineTime } from "../lib/timeline-edit.ts";
|
|
|
|
test("playhead chooses the nearest boundary or EOT and Alt allows free positioning", () => {
|
|
const points = [{ ms: 2000, label: "片段结束" }, { ms: 2150, label: "判断点" }];
|
|
assert.equal(snapTimelineTime(2110, points, 10000, 400).ms, 2150);
|
|
assert.equal(snapTimelineTime(2030, points, 10000, 400).ms, 2000);
|
|
assert.equal(snapTimelineTime(2110, points, 10000, 400, true).ms, 2110);
|
|
assert.equal(snapTimelineTime(4000, points, 10000, 400).point, null);
|
|
});
|
|
|
|
test("zoom narrows magnetic distance and long calls cannot pull the head by seconds", () => {
|
|
const points = [{ ms: 2000, label: "片段" }];
|
|
assert.equal(snapTimelineTime(2100, points, 10000, 400).ms, 2000);
|
|
assert.equal(snapTimelineTime(2100, points, 10000, 3200).ms, 2100);
|
|
assert.equal(snapTimelineTime(2800, points, 600000, 400).ms, 2800);
|
|
});
|
|
|
|
test("resizing never crosses the opposite boundary or the recording ends", () => {
|
|
assert.deepEqual(resizeTranscriptRange(2000, 4000, "start", 4500, 10000), { start_ms: 3999, end_ms: 4000 });
|
|
assert.deepEqual(resizeTranscriptRange(2000, 4000, "end", 1500, 10000), { start_ms: 2000, end_ms: 2001 });
|
|
assert.deepEqual(resizeTranscriptRange(2000, 4000, "start", -500, 10000), { start_ms: 0, end_ms: 4000 });
|
|
assert.deepEqual(resizeTranscriptRange(2000, 4000, "end", 15000, 10000), { start_ms: 2000, end_ms: 10000 });
|
|
});
|