forked from longtao.wu/droboticflow
273 lines
12 KiB
JavaScript
273 lines
12 KiB
JavaScript
// Real isolated tasks: pagination must not hide history targets, change global
|
|
// keyboard adjacency, save parked drafts or make an empty final page stick.
|
|
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 || "annotate";
|
|
const task = process.env.ANNOTATION_TASK_ID || `annotation-task-workspace-layout-acceptance-many-${phase}-04`;
|
|
assert.match(task, /^annotation-task-workspace-layout-acceptance-many-(slice|annotate)-04[-\w]*$/);
|
|
const button = (name) => page.getByRole("button", { name, exact: true });
|
|
const pageNumber = (label) => page.getByLabel(`${label}页码`, { exact: true });
|
|
const matchPage = async (label, pattern, message) => {
|
|
await page.waitForFunction(
|
|
({ label, source }) =>
|
|
new RegExp(source).test(document.querySelector(`[aria-label="${label}页码"]`)?.textContent || ""),
|
|
{ label, source: pattern.source },
|
|
);
|
|
assert.match(await pageNumber(label).innerText(), pattern, message);
|
|
};
|
|
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 reachable = async (locator) =>
|
|
assert.ok(
|
|
await locator.evaluate((e) => {
|
|
const r = e.getBoundingClientRect();
|
|
return (
|
|
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))
|
|
);
|
|
}),
|
|
await locator.getAttribute("aria-label"),
|
|
);
|
|
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 workbench = page.getByTestId("capture-annotation-workbench");
|
|
await pageNumber("切片").waitFor();
|
|
await matchPage("切片", /^1\/4/);
|
|
assert.equal(await page.getByTestId("capture-slice-timeline").locator("[data-slice-id]").count(), 4);
|
|
const before = await readItem();
|
|
let lastWidth = 0;
|
|
for (const [width, height] of [
|
|
[1280, 640],
|
|
[1366, 680],
|
|
[1440, 800],
|
|
[1920, 980],
|
|
[2560, 1320],
|
|
]) {
|
|
await page.setViewportSize({ width, height });
|
|
const g = await page.evaluate(() => ({
|
|
pictures: [...document.querySelectorAll("video")].map((v) => {
|
|
const r = v.getBoundingClientRect(),
|
|
s = Math.min(r.width / v.videoWidth, r.height / v.videoHeight);
|
|
return [v.videoWidth * s, v.videoHeight * s];
|
|
}),
|
|
scroll:
|
|
document.documentElement.scrollHeight > innerHeight + 1 ||
|
|
[...document.querySelectorAll("main,.capture-workbench-body")].some(
|
|
(e) => e.scrollHeight > e.clientHeight + 1 && getComputedStyle(e).overflowY !== "visible",
|
|
),
|
|
}));
|
|
for (const [w, h] of g.pictures) assert.ok(w >= 400 && h >= 325);
|
|
assert.ok(g.pictures[0][0] >= lastWidth);
|
|
lastWidth = g.pictures[0][0];
|
|
assert.equal(g.scroll, false);
|
|
for (const label of phase === "annotate" ? ["切片", "描述"] : ["切片"])
|
|
for (const name of [`${label}上一页`, `${label}下一页`, `定位当前${label}`, `查找下一${label}`])
|
|
await reachable(button(name));
|
|
console.log(JSON.stringify({ viewport: [width, height], ...g }));
|
|
}
|
|
await page.setViewportSize({ width: 1280, height: 640 });
|
|
await workbench.focus();
|
|
for (let i = 0; i < 4; i++) await page.keyboard.press("Control+ArrowRight");
|
|
await matchPage("切片", /^2\/4/);
|
|
await page.getByLabel("查找切片", { exact: true }).fill("#13");
|
|
await button("查找下一切片").click();
|
|
await matchPage("切片", /^4\/4/);
|
|
await workbench.focus();
|
|
await page.keyboard.press("Control+ArrowLeft");
|
|
await matchPage("切片", /^3\/4/);
|
|
assert.equal((await readItem()).version, before.version, "page/search/navigation never saves");
|
|
console.log("PASS global adjacency and search across pages");
|
|
const locateSlice = async (number) => {
|
|
await page.getByLabel("查找切片", { exact: true }).fill(`#${number}`);
|
|
await button("查找下一切片").click();
|
|
};
|
|
if (phase === "slice") {
|
|
await locateSlice(13);
|
|
await button("删除切片").click();
|
|
await matchPage("切片", /^3\/3/);
|
|
assert.ok(await page.getByTestId("capture-slice-timeline").locator('[data-selected="true"]').count());
|
|
await button("切片上一页").click();
|
|
await button("撤销").click();
|
|
await matchPage("切片", /^4\/4/);
|
|
await page.waitForTimeout(1100);
|
|
await button("切片上一页").click();
|
|
await button("重做").click();
|
|
await matchPage("切片", /^3\/3/);
|
|
await page.waitForTimeout(1100);
|
|
await button("撤销").click();
|
|
await matchPage("切片", /^4\/4/);
|
|
await workbench.focus();
|
|
await page.keyboard.press("ArrowRight");
|
|
await page.keyboard.press("c");
|
|
await matchPage("切片", /^4\/4.*14/);
|
|
assert.ok(await page.getByTestId("capture-slice-timeline").locator('[data-selected="true"]').count());
|
|
await button("切片上一页").click();
|
|
await workbench.focus();
|
|
await page.keyboard.press("b");
|
|
await matchPage("切片", /^4\/4/);
|
|
await page.keyboard.press("v");
|
|
await matchPage("切片", /^1\/4/, "V returns to the original global work position");
|
|
await locateSlice(13);
|
|
await page.getByText("当前切片 013", { exact: true }).waitFor();
|
|
assert.match(
|
|
await page.locator(".capture-slice-name-editor").innerText(),
|
|
/0\.03s/,
|
|
"ordinal search directly selects the one-frame slice",
|
|
);
|
|
assert.ok(await page.getByTestId("capture-slice-timeline").locator('[data-selected="true"]').count());
|
|
assert.equal((await readItem()).version, before.version, "slice paging and local edits do not save implicitly");
|
|
console.log("PASS slice delete empty last page, cross-page undo/redo, split reveal and B/V");
|
|
} else {
|
|
await locateSlice(1);
|
|
for (let i = 0; i < 3; i++) await button("描述下一页").click();
|
|
await page.getByTestId("annotation-description-block").last().click();
|
|
const input = page.getByRole("textbox", { name: "动作描述", exact: true });
|
|
const original = await input.inputValue();
|
|
const value = `Task04 saved description ${Date.now()}`;
|
|
await input.fill(value);
|
|
const videos = await page.locator("video").elementHandles();
|
|
await workbench.focus();
|
|
await page.keyboard.press("Control+ArrowRight");
|
|
await page.keyboard.press("n");
|
|
for (let i = 0; i < 6; i++) await page.keyboard.press("ArrowRight");
|
|
await page.keyboard.press("n");
|
|
await input.fill("Task04 parked second-slice draft");
|
|
await workbench.focus();
|
|
await page.keyboard.press("Control+ArrowLeft");
|
|
assert.equal(await input.inputValue(), value);
|
|
await matchPage("描述", /^4\/4/);
|
|
for (const label of ["切回原布局", "进入专注视图"]) {
|
|
await button(label).click();
|
|
assert.equal(await input.inputValue(), value);
|
|
for (const v of videos) assert.ok(await v.evaluate((e) => e.isConnected));
|
|
}
|
|
assert.equal((await readItem()).version, before.version);
|
|
await button("描述上一页").click();
|
|
await workbench.focus();
|
|
await page.keyboard.press("b");
|
|
await matchPage("描述", /^4\/4/);
|
|
await page.keyboard.press("v");
|
|
const mutation = () =>
|
|
page.waitForResponse((r) => r.url().endsWith("annotation-confirmations") && r.request().method() === "POST");
|
|
let response = mutation();
|
|
await button("确认保存描述").click();
|
|
assert.ok((await response).ok());
|
|
await input.waitFor({ state: "detached" });
|
|
await matchPage("描述", /^4\/4/, "saving keeps affected description visible");
|
|
assert.ok((await readItem()).subject.payload.annotationWorkspace.segments.some((x) => x.description === value));
|
|
await button("描述上一页").click();
|
|
response = mutation();
|
|
await button("撤销").click();
|
|
assert.ok((await response).ok());
|
|
await matchPage("描述", /^4\/4/);
|
|
assert.ok((await readItem()).subject.payload.annotationWorkspace.segments.some((x) => x.description === original));
|
|
await page.waitForTimeout(1100);
|
|
await button("描述上一页").click();
|
|
await workbench.focus();
|
|
await page.keyboard.press("Control+ArrowRight");
|
|
response = mutation();
|
|
await button("重做").click();
|
|
assert.ok((await response).ok());
|
|
await input.waitFor({ state: "detached" });
|
|
await matchPage("描述", /^4\/4/, "redo reveals the saved item even without an open editor");
|
|
await page.getByTestId("annotation-description-block").last().click();
|
|
response = mutation();
|
|
await button("删除此动作(保留空白)").click();
|
|
assert.ok((await response).ok());
|
|
await input.waitFor({ state: "detached" });
|
|
await matchPage("描述", /^3\/3/);
|
|
assert.equal((await readItem()).subject.payload.annotationWorkspace.segments.length, 12);
|
|
await page.waitForTimeout(1100);
|
|
await button("描述上一页").click();
|
|
response = mutation();
|
|
await button("撤销").click();
|
|
assert.ok((await response).ok());
|
|
await matchPage("描述", /^4\/4/);
|
|
assert.equal((await readItem()).subject.payload.annotationWorkspace.segments.length, 13);
|
|
await workbench.focus();
|
|
await page.keyboard.press("Control+ArrowRight");
|
|
assert.equal(await input.inputValue(), "Task04 parked second-slice draft");
|
|
await button("取消新增").click();
|
|
await locateSlice(1);
|
|
if (await button("取消编辑").count()) await button("取消编辑").click();
|
|
await workbench.focus();
|
|
await page.keyboard.press("n");
|
|
await page.keyboard.press("ArrowRight");
|
|
await page.keyboard.press("n");
|
|
await input.fill("Task04 tiny one-frame description");
|
|
response = mutation();
|
|
await button("确认保存描述").click();
|
|
assert.ok((await response).ok());
|
|
await input.waitFor({ state: "detached" });
|
|
await page.getByLabel("查找描述", { exact: true }).fill("#14");
|
|
await button("查找下一描述").click();
|
|
await matchPage("描述", /^4\/4/);
|
|
await page.getByLabel("查找描述", { exact: true }).fill("#1");
|
|
await button("查找下一描述").click();
|
|
await matchPage("描述", /^1\/4/);
|
|
assert.equal(await input.inputValue(), "Task04 tiny one-frame description");
|
|
await reachable(input);
|
|
await reachable(button("确认保存描述"));
|
|
const tinyStart = Number(await page.getByRole("spinbutton", { name: "动作开始时间(秒)" }).inputValue());
|
|
const tinyEnd = Number(await page.getByRole("spinbutton", { name: "动作结束时间(秒)" }).inputValue());
|
|
assert.ok(tinyEnd > tinyStart && tinyEnd - tinyStart < 0.05, "search opens the one-frame description directly");
|
|
response = mutation();
|
|
await button("删除此动作(保留空白)").click();
|
|
assert.ok((await response).ok());
|
|
await input.waitFor({ state: "detached" });
|
|
const finalItem = await readItem();
|
|
assert.equal(finalItem.subject.payload.annotationWorkspace.segments.length, 13);
|
|
assert.equal(finalItem.version, before.version + 7, "only explicit saves/history mutate the item");
|
|
console.log(
|
|
"PASS public final readback",
|
|
JSON.stringify({
|
|
beforeVersion: before.version,
|
|
version: finalItem.version,
|
|
slices: finalItem.subject.payload.annotationWorkspace.sliceSegments.length,
|
|
descriptions: finalItem.subject.payload.annotationWorkspace.segments.length,
|
|
}),
|
|
);
|
|
console.log(
|
|
"PASS description draft/toggle, API save, cross-page undo/redo, empty-tail deletion and tiny ordinal search",
|
|
);
|
|
}
|
|
await page.screenshot({ path: `local-data/verification/annotation-workspace-layout/task04-${phase}.png` });
|
|
} catch (error) {
|
|
await page.screenshot({ path: `local-data/verification/annotation-workspace-layout/task04-${phase}-error.png` });
|
|
console.log(await page.locator("body").innerText());
|
|
throw error;
|
|
} finally {
|
|
await context.close();
|
|
await browser.close();
|
|
}
|