forked from longtao.wu/droboticflow
146 lines
6.7 KiB
JavaScript
146 lines
6.7 KiB
JavaScript
// Page-edge drags must use the global adjacent intervals and a stable gesture
|
|
// scale. Exercise actual pointer events, visible boundaries and saved API data.
|
|
import assert from "node:assert/strict";
|
|
import { chromium } from "playwright";
|
|
const browser = await chromium.launch({
|
|
executablePath: "/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge",
|
|
headless: true,
|
|
args: ["--no-proxy-server"],
|
|
});
|
|
const context = await browser.newContext({
|
|
storageState: "local-data/verification/annotation-workspace-layout/auth.json",
|
|
viewport: { width: 1280, height: 640 },
|
|
});
|
|
const page = await context.newPage();
|
|
page.setDefaultTimeout(12000);
|
|
const phase = process.env.NAVIGATION_PHASE || "slice";
|
|
const task = `annotation-task-workspace-layout-acceptance-many-${phase}-04`;
|
|
const button = (name) => page.getByRole("button", { name, exact: true });
|
|
const readItem = async () => {
|
|
const r = await context.request.get(
|
|
`http://127.0.0.1:5173/api/human-items/${task.replace("annotation-task-", "human-item-")}`,
|
|
);
|
|
assert.ok(r.ok());
|
|
return (await r.json()).item;
|
|
};
|
|
const mutation = () =>
|
|
page.waitForResponse((r) => r.url().endsWith("annotation-confirmations") && r.request().method() === "POST");
|
|
const search = async (label, ordinal) => {
|
|
await page.getByLabel(`查找${label}`, { exact: true }).fill(`#${ordinal}`);
|
|
await button(`查找下一${label}`).click();
|
|
};
|
|
try {
|
|
await page.goto(
|
|
`http://127.0.0.1:5173/plugins/annotation-qa/workflows/all/work?projectId=project-workspace-layout-acceptance&taskId=${task}`,
|
|
);
|
|
await button("继续工作").click();
|
|
if (await button("进入专注视图").count()) await button("进入专注视图").click();
|
|
await page.waitForFunction(
|
|
() =>
|
|
document.querySelectorAll("video").length === 2 &&
|
|
[...document.querySelectorAll("video")].every((v) => v.readyState >= 2),
|
|
null,
|
|
{ timeout: 60000 },
|
|
);
|
|
const before = await readItem();
|
|
const workspace = before.subject.payload.annotationWorkspace;
|
|
workspace.segments.sort((a, b) => a.start - b.start);
|
|
await search("切片", phase === "slice" ? 4 : 1);
|
|
let original, field;
|
|
if (phase === "annotate") {
|
|
// Make the existing fourth/fifth intervals contiguous through normal editing.
|
|
await search("描述", 4);
|
|
field = page.getByRole("spinbutton", { name: "动作结束时间(秒)" });
|
|
original = workspace.segments[4].start;
|
|
await field.fill(String(original));
|
|
await field.blur();
|
|
let response = mutation();
|
|
if (await button("确认结束点").count()) await button("确认结束点").click();
|
|
await button("确认保存描述").click();
|
|
assert.ok((await response).ok());
|
|
await search("描述", 4);
|
|
} else {
|
|
original = workspace.sliceSegments[3].end;
|
|
field = page.getByRole("spinbutton", { name: "切片结束时间" });
|
|
}
|
|
// The slice interval is displayed in the fixed editor; annotation uses its
|
|
// accessible boundary field. Record the shared edge from the list when slicing.
|
|
const sliceEnd = async () => {
|
|
const text = await page.locator(".capture-slice-name-editor").innerText();
|
|
const m = text.match(/(\d+):(\d+)\.(\d+)\s*~/);
|
|
assert.ok(m);
|
|
const end = text.match(/~\s*(\d+):(\d+)\.(\d+)/);
|
|
assert.ok(end);
|
|
return Number(end[1]) * 60 + Number(end[2]) + Number(end[3]) / 1000;
|
|
};
|
|
const readBoundary = phase === "slice" ? sliceEnd : async () => Number(await field.inputValue());
|
|
const handle = () =>
|
|
page.getByRole("button", { name: phase === "slice" ? "拖动切片边界" : "拖动动作分界", exact: true }).last();
|
|
const drag = async (delta) => {
|
|
const r = await handle().boundingBox();
|
|
assert.ok(r);
|
|
const track = await page
|
|
.getByTestId(phase === "slice" ? "capture-slice-timeline" : "slice-annotation-timeline")
|
|
.boundingBox();
|
|
// Grab the visible left half of the page-edge handle before crossing the
|
|
// track edge. Pointer capture must keep the gesture active outside it.
|
|
const x = Math.min(r.x + 3, track.x + track.width - 3),
|
|
y = r.y + Math.min(r.height / 2, 15);
|
|
await page.mouse.move(x, y);
|
|
await page.mouse.down();
|
|
await page.mouse.move(x + delta, y, { steps: 3 });
|
|
const once = await readBoundary();
|
|
await page.mouse.move(x + delta, y + 1);
|
|
await page.mouse.move(x + delta, y);
|
|
const repeated = await readBoundary();
|
|
assert.equal(repeated, once, "the same horizontal coordinate cannot move a boundary twice");
|
|
await page.mouse.up();
|
|
return once;
|
|
};
|
|
const later = await drag(12);
|
|
assert.ok(later > original, `page-edge drag must extend later: ${later} > ${original}`);
|
|
const earlier = await drag(-24);
|
|
assert.ok(earlier < later, `page-edge drag must move earlier: ${earlier} < ${later}`);
|
|
console.log("PASS stable bidirectional page-edge pointer drag", JSON.stringify({ phase, original, later, earlier }));
|
|
if (phase === "annotate") {
|
|
let response = mutation();
|
|
if (await button("确认结束点").count()) await button("确认结束点").click();
|
|
await button("确认保存描述").click();
|
|
assert.ok((await response).ok());
|
|
const saved = await readItem();
|
|
const ss = saved.subject.payload.annotationWorkspace.segments;
|
|
assert.equal(ss[3].end, ss[4].start);
|
|
assert.ok(Math.abs(ss[3].end - earlier) < 0.0011);
|
|
console.log(
|
|
"PASS exact shared boundary API readback",
|
|
JSON.stringify({ version: saved.version, end: ss[3].end, nextStart: ss[4].start }),
|
|
);
|
|
// Restore only these two intervals through the same public UI save, so the
|
|
// established fixture remains repeatable and all original gaps survive.
|
|
await search("描述", 4);
|
|
await field.fill(String(workspace.segments[3].end));
|
|
await field.blur();
|
|
response = mutation();
|
|
if (await button("确认结束点").count()) await button("确认结束点").click();
|
|
await button("确认保存描述").click();
|
|
assert.ok((await response).ok());
|
|
await search("描述", 5);
|
|
await page.getByRole("spinbutton", { name: "动作开始时间(秒)" }).fill(String(workspace.segments[4].start));
|
|
await page.getByRole("spinbutton", { name: "动作开始时间(秒)" }).blur();
|
|
response = mutation();
|
|
if (await button("确认结束点").count()) await button("确认结束点").click();
|
|
await button("确认保存描述").click();
|
|
assert.ok((await response).ok());
|
|
} else assert.equal((await readItem()).version, before.version, "local slice drag never implicitly saves");
|
|
await page.screenshot({ path: `local-data/verification/annotation-workspace-layout/task04-boundary-${phase}.png` });
|
|
} catch (e) {
|
|
await page.screenshot({
|
|
path: `local-data/verification/annotation-workspace-layout/task04-boundary-${phase}-error.png`,
|
|
});
|
|
console.log(await page.locator("body").innerText());
|
|
throw e;
|
|
} finally {
|
|
await context.close();
|
|
await browser.close();
|
|
}
|