forked from longtao.wu/droboticflow
182 lines
7.0 KiB
JavaScript
182 lines
7.0 KiB
JavaScript
// Visible error controls and original portal ownership replace the obsolete source-text assertion.
|
|
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();
|
|
const button = (name) => page.getByRole("button", { name, exact: true });
|
|
const task = "annotation-task-workspace-layout-acceptance-pool-01";
|
|
const base = "http://127.0.0.1:5173";
|
|
const read = async () => {
|
|
const r = await context.request.get(`${base}/api/human-items/${task.replace("annotation-task-", "human-item-")}`);
|
|
assert.ok(r.ok());
|
|
return (await r.json()).item;
|
|
};
|
|
const reachable = async (locator) =>
|
|
assert.ok(
|
|
await locator.evaluate((e) => {
|
|
const r = e.getBoundingClientRect();
|
|
return (
|
|
r.width > 0 &&
|
|
r.height > 0 &&
|
|
r.x >= 0 &&
|
|
r.y >= 0 &&
|
|
r.right <= innerWidth &&
|
|
r.bottom <= innerHeight &&
|
|
e.contains(document.elementFromPoint(r.x + r.width / 2, r.y + r.height / 2))
|
|
);
|
|
}),
|
|
`control remains hit-test reachable: ${await locator.innerText()}`,
|
|
);
|
|
const writes = [];
|
|
page.on("request", (r) => {
|
|
if (r.method() !== "GET" && /random-claims|\/tasks\//.test(r.url())) writes.push(r.url());
|
|
});
|
|
try {
|
|
const before = await read();
|
|
await page.goto(
|
|
`${base}/plugins/annotation-qa/workflows/all/work?projectId=project-workspace-layout-acceptance&taskId=${task}`,
|
|
);
|
|
await page.getByRole("button").filter({ hasText: task }).click();
|
|
await button("继续工作").click();
|
|
const bench = page.getByTestId("capture-annotation-workbench");
|
|
await bench.waitFor();
|
|
await page.waitForFunction(
|
|
() =>
|
|
document.querySelectorAll("video").length === 2 &&
|
|
[...document.querySelectorAll("video")].every((v) => v.readyState >= 2),
|
|
);
|
|
await bench.focus();
|
|
await page.keyboard.press("c");
|
|
await bench.getByRole("alert").waitFor();
|
|
for (const [width, height] of [
|
|
[1280, 640],
|
|
[1366, 680],
|
|
[1440, 800],
|
|
[1920, 980],
|
|
[2560, 1320],
|
|
]) {
|
|
await page.setViewportSize({ width, height });
|
|
await page.waitForTimeout(200);
|
|
for (const name of [
|
|
"播放",
|
|
"上一帧",
|
|
"下一帧",
|
|
"在播放头分割切片",
|
|
"从切片字典选择",
|
|
"确认全部切片",
|
|
"撤销",
|
|
"重做",
|
|
"切回原布局",
|
|
"开始连续工作",
|
|
])
|
|
await reachable(button(name));
|
|
assert.ok(
|
|
await page.evaluate(
|
|
() =>
|
|
document.documentElement.scrollWidth <= innerWidth && document.documentElement.scrollHeight <= innerHeight,
|
|
),
|
|
);
|
|
await reachable(bench.getByRole("alert"));
|
|
if (width === 1920)
|
|
await page.screenshot({ path: "local-data/verification/annotation-workspace-layout/task08-error-fixed.png" });
|
|
console.log("PASS actual error-state controls", width, height);
|
|
}
|
|
await page.setViewportSize({ width: 1280, height: 640 });
|
|
await button("切回原布局").click();
|
|
await button("从切片字典选择").click();
|
|
const dialog = page.getByRole("dialog", { name: "选择切片名称", exact: true });
|
|
await dialog.waitFor();
|
|
const search = dialog.getByRole("textbox", { name: "搜索切片字典", exact: true });
|
|
await reachable(search);
|
|
await search.fill("布局验收切片 003");
|
|
const option = dialog.getByRole("button", { name: "布局验收切片 003", exact: true });
|
|
await reachable(option);
|
|
await option.click();
|
|
assert.equal(await page.getByLabel("切片名称:").inputValue(), "布局验收切片 003");
|
|
await bench.focus();
|
|
await page.keyboard.press("f");
|
|
await search.fill("布局验收切片 002");
|
|
await search.press("ArrowDown");
|
|
await page.keyboard.press("Enter");
|
|
assert.equal(await page.getByLabel("切片名称:").inputValue(), "布局验收切片 002");
|
|
await bench.focus();
|
|
await page.keyboard.press("d");
|
|
await dialog.waitFor();
|
|
await page.keyboard.press("Escape");
|
|
await dialog.waitFor({ state: "detached" });
|
|
assert.ok(await bench.evaluate((e) => e === document.activeElement));
|
|
await page.keyboard.press("Space");
|
|
await page.waitForFunction(() => !document.querySelector("video").paused);
|
|
await page.keyboard.press("Space");
|
|
assert.equal((await read()).version, before.version);
|
|
assert.equal(writes.length, 0);
|
|
console.log(
|
|
"PASS original dictionary visible portal, pointer/search/keyboard selection, one-Esc and Space ownership; no writes",
|
|
);
|
|
await button("进入专注视图").click();
|
|
await bench.focus();
|
|
for (let i = 0; i < 3; i++) await page.keyboard.press("Control+ArrowLeft");
|
|
do {
|
|
await button("从切片字典选择").click();
|
|
const picker = page.getByRole("dialog", { name: "选择切片名称", exact: true });
|
|
await picker.getByRole("textbox").fill("布局验收切片 001");
|
|
await picker.getByRole("button", { name: "布局验收切片 001", exact: true }).click();
|
|
if (await button("下一片").isDisabled()) break;
|
|
await button("下一片").click();
|
|
} while (true);
|
|
for (const stage of ["slice", "annotate"]) {
|
|
if (stage === "annotate") {
|
|
const id = "annotation-task-workspace-layout-acceptance-annotate-primary";
|
|
await page.goto(
|
|
`${base}/plugins/annotation-qa/workflows/all/work?projectId=project-workspace-layout-acceptance&taskId=${id}`,
|
|
);
|
|
await page.getByRole("button").filter({ hasText: id }).click();
|
|
await button("继续工作").click();
|
|
await button("完成任务并提交质检").waitFor();
|
|
}
|
|
await button(stage === "slice" ? "确认全部切片" : "完成任务并提交质检").click();
|
|
const confirm = page.getByRole("dialog", {
|
|
name: stage === "slice" ? "确认生成切片" : "确认提交质检",
|
|
exact: true,
|
|
});
|
|
await confirm.waitFor();
|
|
for (const [width, height] of [
|
|
[1280, 640],
|
|
[1366, 680],
|
|
[1440, 800],
|
|
[1920, 980],
|
|
[2560, 1320],
|
|
]) {
|
|
await page.setViewportSize({ width, height });
|
|
await page.waitForTimeout(100);
|
|
await reachable(confirm.getByRole("button", { name: stage === "slice" ? "确认生成" : "确认送检", exact: true }));
|
|
await reachable(confirm.getByRole("button", { name: "返回编辑", exact: true }));
|
|
assert.ok(
|
|
await page.evaluate(
|
|
() =>
|
|
document.documentElement.scrollWidth <= innerWidth && document.documentElement.scrollHeight <= innerHeight,
|
|
),
|
|
);
|
|
}
|
|
await confirm.getByRole("button", { name: "返回编辑", exact: true }).click();
|
|
console.log("PASS five-size stage confirmation actions without submission", stage);
|
|
}
|
|
assert.equal(writes.length, 0);
|
|
} catch (e) {
|
|
await page.screenshot({
|
|
path: "local-data/verification/annotation-workspace-layout/task08-error-legacy-failure.png",
|
|
});
|
|
throw e;
|
|
} finally {
|
|
await context.close();
|
|
await browser.close();
|
|
}
|