forked from longtao.wu/droboticflow
169 lines
5.0 KiB
JavaScript
169 lines
5.0 KiB
JavaScript
import assert from "node:assert/strict";
|
|
import test from "node:test";
|
|
import { reviewSeekHarness } from "./review-seek-harness.mjs";
|
|
import { annotationShortcutHelpForContext } from "../../src/lib/annotation-shortcuts.js";
|
|
|
|
const slices = [
|
|
{ id: "slice-1", name: "first", start: 0, end: 4 },
|
|
{ id: "slice-2", name: "second", start: 4, end: 8 },
|
|
];
|
|
const segments = Array.from({ length: 8 }, (_, i) => ({
|
|
id: `action-${i + 1}`,
|
|
start: i / 2,
|
|
end: (i + 1) / 2,
|
|
description: `action ${i + 1}`,
|
|
}));
|
|
|
|
function key(f, key, modifiers = {}) {
|
|
f.nodes()
|
|
.find((node) => node.props["data-testid"] === "capture-annotation-workbench")
|
|
.props.onKeyDown({
|
|
key,
|
|
ctrlKey: false,
|
|
metaKey: false,
|
|
altKey: false,
|
|
shiftKey: false,
|
|
repeat: false,
|
|
defaultPrevented: false,
|
|
nativeEvent: {},
|
|
target: { closest: () => null, matches: () => false },
|
|
preventDefault() {},
|
|
...modifiers,
|
|
});
|
|
f.flush();
|
|
f.settle();
|
|
}
|
|
function clickAction(f, id) {
|
|
f.nodes()
|
|
.find((node) => node.props["data-annotation-id"] === id)
|
|
.props.onClick({ stopPropagation() {} });
|
|
f.flush();
|
|
f.settle();
|
|
}
|
|
function atStart(f, time) {
|
|
assert.ok(
|
|
Math.abs(f.videos.left.currentTime - time) < 0.000003,
|
|
`expected action start ${time}, actual media time ${f.videos.left.currentTime}`,
|
|
);
|
|
assert.equal(f.videos.left.paused, true);
|
|
}
|
|
function fixture(overrides) {
|
|
return reviewSeekHarness({
|
|
isQualityReview: false,
|
|
slices,
|
|
segments,
|
|
clipEnd: 8,
|
|
frameBoundaries: Array.from({ length: 81 }, (_, i) => i / 10),
|
|
onChange: () => assert.fail("selection must never save annotations"),
|
|
...overrides,
|
|
});
|
|
}
|
|
|
|
for (const continuousActions of [false, true]) {
|
|
for (const focusedLayout of [false, true]) {
|
|
const name = `${continuousActions ? "continuous" : "legacy"} ${focusedLayout ? "focused" : "normal"}`;
|
|
test(`${name}: clicking and keyboard action selection always seeks the first frame`, () => {
|
|
const f = fixture({ continuousActions, focusedLayout });
|
|
try {
|
|
clickAction(f, "action-2");
|
|
atStart(f, 0.5);
|
|
key(f, "ArrowDown");
|
|
atStart(f, 1);
|
|
key(f, "ArrowUp");
|
|
atStart(f, 0.5);
|
|
// Reselecting the same action must return to its start as well.
|
|
key(f, "ArrowRight");
|
|
clickAction(f, "action-2");
|
|
atStart(f, 0.5);
|
|
} finally {
|
|
f.destroy();
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
test("continuous six-action keyboard jumps seek starts, explicit end-frame command stays available", () => {
|
|
const f = fixture({ continuousActions: true });
|
|
try {
|
|
clickAction(f, "action-1");
|
|
key(f, "ArrowDown", { ctrlKey: true });
|
|
atStart(f, 3);
|
|
key(f, "ArrowUp", { metaKey: true });
|
|
atStart(f, 0);
|
|
key(f, "ArrowDown", { altKey: true });
|
|
atStart(f, 0.4);
|
|
key(f, "ArrowUp", { altKey: true });
|
|
atStart(f, 0);
|
|
key(f, "ArrowUp");
|
|
atStart(f, 3.5);
|
|
} finally {
|
|
f.destroy();
|
|
}
|
|
});
|
|
|
|
for (const phase of ["slice", "annotate"]) {
|
|
test(`${phase}: mouse and keyboard slice selection seek the selected slice start`, () => {
|
|
const f = fixture({ phase, continuousActions: true });
|
|
try {
|
|
f.clickSlice("slice-2");
|
|
f.settle();
|
|
atStart(f, 4);
|
|
key(f, "ArrowLeft", { ctrlKey: true });
|
|
atStart(f, 0);
|
|
key(f, "ArrowRight", { metaKey: true });
|
|
atStart(f, 4);
|
|
} finally {
|
|
f.destroy();
|
|
}
|
|
});
|
|
}
|
|
|
|
for (const mode of ["quality", "acceptance"]) {
|
|
for (const focusedLayout of [false, true]) {
|
|
test(`${mode} ${focusedLayout ? "focused" : "normal"}: action selection and shortcuts locate starts`, () => {
|
|
const f = fixture({
|
|
readOnly: true,
|
|
focusedLayout,
|
|
isQualityReview: mode === "quality",
|
|
...(mode === "acceptance"
|
|
? {
|
|
mediaOnly: true,
|
|
reviewNavigation: {
|
|
actions: segments,
|
|
selectedActionId: "action-2",
|
|
onSelectAction: () => true,
|
|
},
|
|
}
|
|
: {}),
|
|
});
|
|
try {
|
|
if (mode === "acceptance") {
|
|
f.controller.seekAction("action-2");
|
|
f.flush();
|
|
f.settle();
|
|
} else clickAction(f, "action-2");
|
|
atStart(f, 0.5);
|
|
key(f, "ArrowDown");
|
|
atStart(f, 1);
|
|
f.controller.seekAction("action-2");
|
|
f.flush();
|
|
f.settle();
|
|
atStart(f, 0.5);
|
|
} finally {
|
|
f.destroy();
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
test("navigation help consistently describes start selection and preserves explicit end commands", () => {
|
|
for (const continuousActions of [false, true]) {
|
|
const help = annotationShortcutHelpForContext("annotate", { continuousActions });
|
|
assert.match(help.find((row) => row.keys === "↑ / ↓").label, /片头/);
|
|
if (continuousActions) {
|
|
assert.match(help.find((row) => row.keys === "Ctrl / ⌘ + ↑ / ↓").label, /片头/);
|
|
assert.match(help.find((row) => row.keys === "Alt + ↑ / ↓").label, /最后可编辑帧/);
|
|
}
|
|
}
|
|
});
|