droboticflow/tests/browser/workbench-entry-shortcuts.mjs

87 lines
3.8 KiB
JavaScript

// Explicit isolated fixture only. C/undo affect local drafts; no task is submitted.
import assert from "node:assert/strict";
import { chromium } from "playwright";
const {
ANNOTATION_BASE_URL: base,
ANNOTATION_PROJECT_ID: project,
ANNOTATION_TASK_ID: task,
ANNOTATION_STORAGE_STATE: auth,
} = process.env;
assert.ok(base && project && task && auth);
assert.match(project, /continuous-actions|acceptance/);
const browser = await chromium.launch({
executablePath:
process.env.PLAYWRIGHT_EXECUTABLE_PATH || "/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge",
headless: true,
args: ["--no-proxy-server"],
});
try {
const context = await browser.newContext({ storageState: auth, viewport: { width: 1440, height: 900 } });
context.setDefaultTimeout(30000);
const page = await context.newPage();
await page.goto(`${base}/plugins/annotation-qa/workflows/all/annotate?projectId=${project}&taskId=${task}`);
const bench = page.getByTestId("capture-annotation-workbench");
await bench.waitFor();
await page.getByTestId("frame-timeline-status").waitFor({ state: "hidden", timeout: 180000 });
await page.waitForTimeout(100);
assert.equal(
await bench.evaluate((root) => root.contains(document.activeElement)),
true,
"ready task must receive keyboard focus without an extra click",
);
await page.keyboard.press("g");
const discard = page.getByRole("dialog", { name: "舍弃片段", exact: true });
await discard.waitFor();
await page.keyboard.press("Escape");
await discard.waitFor({ state: "hidden" });
const blocks = bench.getByTestId("capture-slice-timeline").locator("[data-slice-id]");
const count = await blocks.count();
const slider = bench.locator('input[type="range"]').first();
const min = Number(await slider.getAttribute("min")),
max = Number(await slider.getAttribute("max"));
await slider.fill(String((min + max) / 2));
await page.keyboard.press("c");
await page.waitForFunction(
(n) => document.querySelectorAll('[data-testid="capture-slice-timeline"] [data-slice-id]').length === n,
count + 1,
);
await page.keyboard.press("Control+z");
await page.waitForFunction(
(n) => document.querySelectorAll('[data-testid="capture-slice-timeline"] [data-slice-id]').length === n,
count,
);
await page.keyboard.press("f");
const search = page.getByRole("textbox", { name: "搜索切片字典", exact: true });
await search.waitFor();
await search.pressSequentially("cg");
assert.equal(await search.inputValue(), "cg");
assert.equal(await blocks.count(), count);
await page.keyboard.press("Escape");
console.log("PASS normal entry focus, G, range → C, undo, dictionary typing protection");
await page.getByRole("button", { name: "开始工作", exact: true }).click();
await page.waitForURL("**/work?**", { timeout: 180000, waitUntil: "domcontentloaded" });
await bench.waitFor();
await page.getByTestId("frame-timeline-status").waitFor({ state: "hidden", timeout: 180000 });
await page.waitForTimeout(100);
assert.equal(await bench.evaluate((root) => root.contains(document.activeElement)), true);
await page.keyboard.press("g");
await discard.waitFor();
await page.keyboard.press("Escape");
await discard.waitFor({ state: "hidden" });
const focusedCount = await blocks.count();
await slider.fill(String((min + max) / 2));
await page.keyboard.press("c");
await page.waitForFunction(
(n) => document.querySelectorAll('[data-testid="capture-slice-timeline"] [data-slice-id]').length === n,
focusedCount + 1,
);
await page.keyboard.press("Control+z");
await page.waitForFunction(
(n) => document.querySelectorAll('[data-testid="capture-slice-timeline"] [data-slice-id]').length === n,
focusedCount,
);
console.log("PASS focus-mode entry, G, range → C, undo");
} finally {
await browser.close();
}