forked from longtao.wu/droboticflow
573 lines
27 KiB
JavaScript
573 lines
27 KiB
JavaScript
// Real authenticated application, decoded videos and public API; isolated review fixtures only.
|
|
// Covers the confirmed F-first problem editor flow: scope picking, independent ids,
|
|
// select-vs-edit, stable order, Esc semantics, guarded transitions, serial writes,
|
|
// deletion, view anchors, refresh persistence and save reconciliation.
|
|
import { chromium } from "playwright";
|
|
import fs from "node:fs/promises";
|
|
import assert from "node:assert/strict";
|
|
const dir = process.env.REVIEW_FIXTURES || "local-data/verification/review-focused-20260922";
|
|
const base = process.env.REVIEW_EDITOR_URL || process.env.REVIEW_TEST_URL || "http://127.0.0.1:5192";
|
|
const hostname = new URL(base).hostname;
|
|
const fixtures = JSON.parse(await fs.readFile(`${dir}/fixture-index.json`, "utf8"));
|
|
// Dedicated fixture items keep this suite independent from legacy scenario data.
|
|
const QUALITY_INDEX = Number(process.env.REVIEW_EDITOR_QUALITY_INDEX || 2);
|
|
// Acceptance cards map to the fixture order; the first card is this item.
|
|
const ACCEPTANCE_INDEX = Number(process.env.REVIEW_EDITOR_ACCEPTANCE_INDEX || 0);
|
|
const browser = await chromium.launch({
|
|
executablePath: process.env.BROWSER_EXECUTABLE || "/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge",
|
|
headless: true,
|
|
args: [`--host-resolver-rules=MAP ${hostname} 127.0.0.1`, "--no-proxy-server"],
|
|
});
|
|
const reports = [];
|
|
try {
|
|
for (const mode of process.env.REVIEW_EDITOR_MODE ? [process.env.REVIEW_EDITOR_MODE] : ["quality", "acceptance"]) {
|
|
const auth = JSON.parse(
|
|
await fs.readFile(`${dir}/fixture-${mode === "quality" ? "qc" : "acceptance"}-auth.json`, "utf8"),
|
|
);
|
|
auth.cookies = auth.cookies.map((c) => ({ ...c, domain: hostname }));
|
|
const fixture = mode === "quality" ? fixtures.quality[QUALITY_INDEX] : fixtures.acceptance[ACCEPTANCE_INDEX];
|
|
const focusedList = mode === "quality" ? [false, true] : [false];
|
|
for (const focused of focusedList) {
|
|
const context = await browser.newContext({
|
|
storageState: auth,
|
|
viewport: { width: 1413, height: focused ? 615 : 1000 },
|
|
});
|
|
const page = await context.newPage();
|
|
page.setDefaultTimeout(25000);
|
|
const errors = [],
|
|
formalRequests = [];
|
|
page.on("pageerror", (e) => errors.push(e.stack || e.message));
|
|
page.on("request", (r) => {
|
|
if (r.method() === "POST" && /\/(?:review|decisions)$/.test(new URL(r.url()).pathname))
|
|
formalRequests.push(r.url());
|
|
});
|
|
const url = `${base}/plugins/annotation-qa/workflows/all/${mode}?projectId=${fixtures.projectId}${fixture.taskId ? `&taskId=${fixture.taskId}` : ""}`;
|
|
const open = async () => {
|
|
await page.goto(url);
|
|
await page.getByRole("button", { name: /^我的任务/ }).click();
|
|
if (mode === "acceptance")
|
|
await page
|
|
.getByTestId("acceptance-task-card")
|
|
.nth(ACCEPTANCE_INDEX)
|
|
.getByRole("button", { name: /^预览 / })
|
|
.click();
|
|
else await page.getByRole("button", { name: /^我的任务/ }).click();
|
|
await page
|
|
.getByRole("status")
|
|
.filter({ hasText: /本页可编辑审查意见|本页只读/ })
|
|
.waitFor();
|
|
const takeover = page.getByRole("button", { name: "在本页接管审查", exact: true });
|
|
if (await takeover.count()) await takeover.click();
|
|
await page.getByText("本页可编辑审查意见", { exact: true }).waitFor();
|
|
await page.getByRole("region", { name: "审查问题草稿" }).waitFor();
|
|
if (focused) await page.getByRole("button", { name: "进入专注审查", exact: true }).click();
|
|
};
|
|
await open();
|
|
const bench = page.getByTestId("capture-annotation-workbench").first();
|
|
const range = bench.getByRole("slider", { name: "Capture 播放位置", exact: true });
|
|
const panel = page.getByRole("region", { name: "审查问题草稿" });
|
|
const input = page.getByRole("textbox", { name: "审查问题说明", exact: true });
|
|
const picker = page.getByRole("radiogroup", { name: "问题范围", exact: true });
|
|
const options = panel.getByRole("listbox", { name: "已保存问题", exact: true }).getByRole("option");
|
|
const confirmBar = page.getByRole("alertdialog", { name: "确认删除问题", exact: true });
|
|
const read = () =>
|
|
page.evaluate(async (id) => {
|
|
const r = await fetch(`/api/human-items/${id}/review-draft`);
|
|
if (!r.ok) throw Error(`read ${r.status}`);
|
|
return r.json();
|
|
}, fixture.humanItemId);
|
|
const settle = async () =>
|
|
page.waitForFunction(() => {
|
|
const videos = [...document.querySelectorAll("video")].filter((v) => v.getBoundingClientRect().width > 0);
|
|
const step = [...document.querySelectorAll("button")].find(
|
|
(button) => button.textContent.trim() === "上一帧",
|
|
);
|
|
return step && !step.disabled && videos.length && videos.every((v) => v.readyState >= 2 && !v.seeking);
|
|
});
|
|
const seek = async (time) => {
|
|
const b = await range.boundingBox();
|
|
const min = Number(await range.getAttribute("min")),
|
|
max = Number(await range.getAttribute("max"));
|
|
await range.click({ position: { x: 8 + ((b.width - 16) * (time - min)) / (max - min), y: b.height / 2 } });
|
|
await settle();
|
|
};
|
|
const workbenchFocused = () =>
|
|
Boolean(
|
|
document.activeElement?.matches?.(
|
|
"[data-testid='capture-annotation-workbench'], [data-testid='final-acceptance-workspace']",
|
|
),
|
|
);
|
|
const activeIsWorkbench = () => page.evaluate(workbenchFocused);
|
|
const waitWorkbenchFocus = () => page.waitForFunction(workbenchFocused);
|
|
// Remove leftovers from earlier runs so order assertions stay deterministic.
|
|
await settle();
|
|
for (let guard = 0; guard < 20 && (await options.count()) > 0; guard++) {
|
|
await options.nth(0).click();
|
|
await waitWorkbenchFocus();
|
|
await page.keyboard.press("Shift+Delete");
|
|
await confirmBar.waitFor();
|
|
await confirmBar.getByRole("button", { name: "确认删除", exact: true }).click();
|
|
await panel
|
|
.getByRole("status")
|
|
.filter({ hasText: /^已删除问题$/ })
|
|
.waitFor();
|
|
}
|
|
assert.equal((await read()).draft.problems.length, 0, "fixture item starts without saved problems");
|
|
|
|
// F is the only recording letter: Q must not open anything.
|
|
await settle();
|
|
await page.keyboard.press("q");
|
|
await page.waitForTimeout(400);
|
|
assert.equal(await picker.count(), 0, "Q no longer records problems");
|
|
|
|
// F pauses on the ready frame and opens scope picking in the right panel.
|
|
if (mode === "quality") await bench.getByTestId("annotation-description-block").first().click();
|
|
else
|
|
await page
|
|
.getByTestId("acceptance-action-timeline")
|
|
.getByRole("button", { name: /^动作 / })
|
|
.first()
|
|
.click();
|
|
await settle();
|
|
await seek(18);
|
|
await page.keyboard.press("f");
|
|
await picker.waitFor();
|
|
const paused = await page
|
|
.locator("video")
|
|
.evaluateAll((vs) => vs.filter((v) => v.getBoundingClientRect().width > 0).every((v) => v.paused));
|
|
assert.ok(paused, "F pauses playback before scope picking");
|
|
await assertFocused(picker);
|
|
async function assertFocused(locator) {
|
|
await page.waitForFunction(() => document.activeElement?.getAttribute("role") === "radio");
|
|
await locator.waitFor();
|
|
}
|
|
const scopeRadio = (name) => picker.getByRole("radio", { name, exact: true });
|
|
assert.equal(await scopeRadio("动作").getAttribute("aria-checked"), "true", "default scope is current action");
|
|
await page.keyboard.press("ArrowDown");
|
|
assert.equal(await scopeRadio("切片").getAttribute("aria-checked"), "true");
|
|
await page.keyboard.press("ArrowUp");
|
|
assert.equal(await scopeRadio("动作").getAttribute("aria-checked"), "true");
|
|
// Esc cancels scope picking and returns focus to the workbench.
|
|
await page.keyboard.press("Escape");
|
|
await picker.waitFor({ state: "detached" });
|
|
await waitWorkbenchFocus();
|
|
|
|
// F again → Enter enters the text box; Ctrl+Enter saves and exits.
|
|
await page.keyboard.press("f");
|
|
await picker.waitFor();
|
|
await page.keyboard.press("Enter");
|
|
await page.waitForFunction(() => document.activeElement?.getAttribute("aria-label") === "审查问题说明");
|
|
const first = `${mode}/${focused ? "focus" : "ordinary"} 第一条 ${Date.now()}`;
|
|
await input.fill(first);
|
|
await input.press("Control+Enter");
|
|
await panel
|
|
.getByRole("status")
|
|
.filter({ hasText: /^已保存$/ })
|
|
.waitFor();
|
|
assert.equal(await input.inputValue(), "", "successful save clears the input");
|
|
await waitWorkbenchFocus();
|
|
let draft = (await read()).draft;
|
|
const firstSaved = draft.problems.find((p) => p.text === first);
|
|
assert.ok(firstSaved?.id, "first problem persisted");
|
|
assert.equal(await options.count(), draft.problems.length);
|
|
assert.equal(await options.nth(0).getAttribute("aria-selected"), "true", "saved record becomes selected");
|
|
|
|
// F on the same target creates an independent second record.
|
|
await page.keyboard.press("f");
|
|
await picker.waitFor();
|
|
await page.keyboard.press("Enter");
|
|
const second = `${mode}/${focused ? "focus" : "ordinary"} 第二条同对象 ${Date.now()}`;
|
|
await input.fill(second);
|
|
await input.press("Control+Enter");
|
|
await panel
|
|
.getByRole("status")
|
|
.filter({ hasText: /^已保存$/ })
|
|
.waitFor();
|
|
draft = (await read()).draft;
|
|
const sameTarget = draft.problems.filter((p) => p.actionId && p.actionId === firstSaved.actionId);
|
|
assert.ok(sameTarget.length >= 2, "same action target allows multiple problems");
|
|
assert.notEqual(sameTarget[0].id, sameTarget[1].id, "independent ids per F");
|
|
const ids = draft.problems.map((p) => p.id);
|
|
assert.ok(ids.indexOf(firstSaved.id) < ids.indexOf(sameTarget[1].id), "first-save order is stable");
|
|
|
|
// Clicking a row only selects and recalls the picture; it never enters text.
|
|
await options.nth(0).click();
|
|
await settle();
|
|
assert.equal(await options.nth(0).getAttribute("aria-selected"), "true");
|
|
assert.equal(await input.inputValue(), "", "clicking a saved problem does not enter text");
|
|
await waitWorkbenchFocus();
|
|
assert.ok(
|
|
Math.abs(Number(await range.inputValue()) - firstSaved.atSeconds) < 0.07 || firstSaved.scope === "task",
|
|
"selection recalls the recorded picture",
|
|
);
|
|
|
|
// Ctrl+Up/Down walks the list and stops at both ends.
|
|
await page.keyboard.press("Control+ArrowDown");
|
|
assert.equal(await options.nth(1).getAttribute("aria-selected"), "true");
|
|
await page.keyboard.press("Control+ArrowDown");
|
|
assert.equal(await options.nth(1).getAttribute("aria-selected"), "true", "stops at the last record");
|
|
await page.keyboard.press("Control+ArrowUp");
|
|
assert.equal(await options.nth(0).getAttribute("aria-selected"), "true");
|
|
await page.keyboard.press("Control+ArrowUp");
|
|
assert.equal(await options.nth(0).getAttribute("aria-selected"), "true", "stops at the first record");
|
|
assert.equal(await input.inputValue(), "", "navigation never enters text");
|
|
|
|
// Enter edits the selected record; the edit keeps its list position.
|
|
await page.keyboard.press("Enter");
|
|
await page.waitForFunction(() => document.activeElement?.getAttribute("aria-label") === "审查问题说明");
|
|
assert.equal(await input.inputValue(), first, "Enter loads the selected record's text");
|
|
const firstEdited = `${first}(已修改)`;
|
|
await input.fill(firstEdited);
|
|
await input.press("Control+Enter");
|
|
await panel
|
|
.getByRole("status")
|
|
.filter({ hasText: /^已保存$/ })
|
|
.waitFor();
|
|
draft = (await read()).draft;
|
|
assert.equal(draft.problems[0].text, firstEdited, "edit stays at the original index");
|
|
assert.ok(
|
|
draft.problems.some((p) => p.text === second),
|
|
"editing one record never overwrites another",
|
|
);
|
|
|
|
// Unsaved text survives watching navigation without retargeting.
|
|
await options.nth(1).click();
|
|
await page.keyboard.press("Enter");
|
|
const unsaved = `未保存仍可观看 ${Date.now()}`;
|
|
await input.fill(unsaved);
|
|
await seek(8);
|
|
await page.keyboard.press("ArrowDown");
|
|
await settle();
|
|
assert.equal(await input.inputValue(), unsaved, "watching keeps unsaved text");
|
|
assert.match(await panel.getByLabel("批注对象").innerText(), /动作/, "edit target stays fixed");
|
|
|
|
// F with unsaved text asks to save/discard/cancel instead of jumping.
|
|
await page.keyboard.press("f");
|
|
await panel.getByRole("button", { name: "保存并继续", exact: true }).waitFor();
|
|
await panel.getByRole("button", { name: "继续编辑", exact: true }).click();
|
|
assert.equal(await input.inputValue(), unsaved, "cancel keeps editing");
|
|
// The panel button offers the same path while the text box owns focus.
|
|
await panel.getByRole("button", { name: "记录当前画面问题", exact: true }).click();
|
|
await panel.getByRole("button", { name: "放弃文字", exact: true }).click();
|
|
// After discarding, the pending F intent continues into scope picking.
|
|
await picker.waitFor();
|
|
assert.equal(
|
|
await panel.getByRole("button", { name: "保存并继续", exact: true }).count(),
|
|
0,
|
|
"discard closes the guard instead of reopening it",
|
|
);
|
|
assert.equal(await input.inputValue(), "", "discard clears the unsaved text");
|
|
await page.keyboard.press("Escape");
|
|
await picker.waitFor({ state: "detached" });
|
|
await waitWorkbenchFocus();
|
|
|
|
// Guard save-continuation (no Esc): focus lands in the scope picker and
|
|
// Enter opens a fresh text box; an older workbench refocus never wins.
|
|
const guarded = `${mode}/${focused} 守卫后继续 ${Date.now()}`;
|
|
await page.keyboard.press("f");
|
|
await picker.waitFor();
|
|
await page.keyboard.press("Enter");
|
|
await input.fill(guarded);
|
|
await panel.getByRole("button", { name: "记录当前画面问题", exact: true }).click();
|
|
await panel.getByRole("button", { name: "保存并继续", exact: true }).click();
|
|
await picker.waitFor();
|
|
await page.evaluate(() => new Promise((resolve) => requestAnimationFrame(() => requestAnimationFrame(resolve))));
|
|
assert.equal(
|
|
await page.evaluate(() => document.activeElement?.getAttribute("role")),
|
|
"radio",
|
|
"guarded save continuation lands in the scope picker",
|
|
);
|
|
await page.keyboard.press("Enter");
|
|
await page.waitForFunction(() => document.activeElement?.getAttribute("aria-label") === "审查问题说明");
|
|
assert.equal(await input.inputValue(), "", "continuation opened a fresh new problem");
|
|
await page.keyboard.press("Escape");
|
|
await waitWorkbenchFocus();
|
|
|
|
// Enter-on-another with dirty text: discard continues into that record.
|
|
await options.nth(0).click();
|
|
await page.keyboard.press("Enter");
|
|
await input.fill("临时守卫文字");
|
|
await options.nth(1).click();
|
|
await page.keyboard.press("Enter");
|
|
await panel.getByRole("button", { name: "放弃文字", exact: true }).click();
|
|
await page.waitForFunction(() => document.activeElement?.getAttribute("aria-label") === "审查问题说明");
|
|
assert.equal(await input.inputValue(), second, "discard continuation opens the other record");
|
|
await page.keyboard.press("Escape");
|
|
await waitWorkbenchFocus();
|
|
|
|
// Empty text is never saved and never deletes the record.
|
|
await options.nth(0).click();
|
|
await page.keyboard.press("Enter");
|
|
await input.fill("");
|
|
await input.press("Control+Enter");
|
|
await page.waitForTimeout(400);
|
|
draft = (await read()).draft;
|
|
assert.ok(
|
|
draft.problems.some((p) => p.text === firstEdited),
|
|
"empty save never deletes",
|
|
);
|
|
await page.keyboard.press("Escape");
|
|
assert.equal(await input.inputValue(), "", "Esc clears the input");
|
|
await waitWorkbenchFocus();
|
|
draft = (await read()).draft;
|
|
assert.ok(
|
|
draft.problems.some((p) => p.text === firstEdited),
|
|
"Esc leaves saved records untouched",
|
|
);
|
|
|
|
// Shift+Delete asks for a short confirmation, then persists immediately.
|
|
await page.keyboard.press("Shift+Delete");
|
|
await confirmBar.waitFor();
|
|
await page.keyboard.press("Escape");
|
|
await confirmBar.waitFor({ state: "detached" });
|
|
assert.equal((await read()).draft.problems.length, draft.problems.length, "cancelled delete changes nothing");
|
|
await page.keyboard.press("Shift+Delete");
|
|
await confirmBar.waitFor();
|
|
await confirmBar.getByRole("button", { name: "确认删除", exact: true }).click();
|
|
await panel
|
|
.getByRole("status")
|
|
.filter({ hasText: /^已删除问题$/ })
|
|
.waitFor();
|
|
draft = (await read()).draft;
|
|
assert.ok(!draft.problems.some((p) => p.text === firstEdited), "confirmed delete persists");
|
|
assert.equal(await options.nth(0).getAttribute("aria-selected"), "true", "selection moves to the neighbor");
|
|
await waitWorkbenchFocus();
|
|
|
|
// In-flight save: Esc exits the input, the operation still reconciles, and a
|
|
// late success updates the list without resurrecting the editor.
|
|
const third = `${mode}/${focused} 迟到成功 ${Date.now()}`;
|
|
let releasePut;
|
|
const putGate = new Promise((resolve) => (releasePut = resolve));
|
|
let holdPut = true;
|
|
await page.route("**/review-draft", async (route) => {
|
|
if (route.request().method() === "PUT" && holdPut) {
|
|
await putGate;
|
|
return route.continue();
|
|
}
|
|
return route.continue();
|
|
});
|
|
await page.keyboard.press("f");
|
|
await picker.waitFor();
|
|
await page.keyboard.press("Enter");
|
|
await input.fill(third);
|
|
await input.press("Control+Enter");
|
|
await panel
|
|
.getByRole("status")
|
|
.filter({ hasText: /^保存中$/ })
|
|
.waitFor();
|
|
await page.keyboard.press("Escape");
|
|
assert.equal(await input.inputValue(), "", "Esc exits the input during the in-flight save");
|
|
await waitWorkbenchFocus();
|
|
releasePut();
|
|
await panel
|
|
.getByRole("status")
|
|
.filter({ hasText: /^已保存$/ })
|
|
.waitFor();
|
|
await page.unroute("**/review-draft");
|
|
draft = (await read()).draft;
|
|
assert.ok(
|
|
draft.problems.some((p) => p.text === third),
|
|
"in-flight save still reconciles",
|
|
);
|
|
assert.equal(await input.inputValue(), "", "late success never resurrects the editor");
|
|
await waitWorkbenchFocus();
|
|
|
|
// A delayed guard-save must drop its continuation when Esc intervenes:
|
|
// no scope picker resurrection and no focus theft after the late success.
|
|
const guardDelayed = `${mode}/${focused} 守卫延迟 ${Date.now()}`;
|
|
await options.nth(0).click();
|
|
await page.keyboard.press("Enter");
|
|
await input.fill(guardDelayed);
|
|
let releaseGuardPut;
|
|
const guardGate = new Promise((resolve) => (releaseGuardPut = resolve));
|
|
await page.route("**/review-draft", async (route) => {
|
|
if (route.request().method() === "PUT") {
|
|
await guardGate;
|
|
return route.continue();
|
|
}
|
|
return route.continue();
|
|
});
|
|
await panel.getByRole("button", { name: "记录当前画面问题", exact: true }).click();
|
|
await panel.getByRole("button", { name: "保存并继续", exact: true }).click();
|
|
await panel
|
|
.getByRole("status")
|
|
.filter({ hasText: /^保存中$/ })
|
|
.waitFor();
|
|
await page.keyboard.press("Escape");
|
|
await waitWorkbenchFocus();
|
|
assert.equal(await input.inputValue(), "", "Esc during the guarded save clears the input");
|
|
releaseGuardPut();
|
|
await panel
|
|
.getByRole("status")
|
|
.filter({ hasText: /^已保存$/ })
|
|
.waitFor();
|
|
await page.unroute("**/review-draft");
|
|
assert.equal(await picker.count(), 0, "late guard-save success never resurrects the scope picker");
|
|
assert.equal(
|
|
await panel.getByRole("button", { name: "保存并继续", exact: true }).count(),
|
|
0,
|
|
"late guard-save success never resurrects the guard",
|
|
);
|
|
await waitWorkbenchFocus();
|
|
draft = (await read()).draft;
|
|
assert.equal(
|
|
draft.problems.filter((p) => p.text === guardDelayed).length,
|
|
1,
|
|
"guarded save persisted exactly once",
|
|
);
|
|
|
|
// Failed save keeps text; the identical retry reconciles without duplicates.
|
|
const fourth = `${mode}/${focused} 失败重试 ${Date.now()}`;
|
|
await page.route("**/review-draft", (route) =>
|
|
route.request().method() === "PUT" ? route.abort("failed") : route.continue(),
|
|
);
|
|
await page.keyboard.press("f");
|
|
await picker.waitFor();
|
|
await page.keyboard.press("Enter");
|
|
await input.fill(fourth);
|
|
await input.press("Control+Enter");
|
|
await panel.getByRole("alert").first().waitFor();
|
|
assert.equal(await input.inputValue(), fourth, "failure preserves the text");
|
|
await page.unroute("**/review-draft");
|
|
// A 409 on the exact retry is definitive: release pending, keep text, then
|
|
// an explicit save against the fresh version succeeds.
|
|
await page.route("**/review-draft", (route) =>
|
|
route.request().method() === "PUT"
|
|
? route.fulfill({
|
|
status: 409,
|
|
contentType: "application/json",
|
|
body: JSON.stringify({
|
|
code: "review_draft_version_conflict",
|
|
error: "已保存草稿已有新版本,请核对后再保存",
|
|
}),
|
|
})
|
|
: route.continue(),
|
|
);
|
|
await panel.getByRole("button", { name: "保存批注", exact: true }).click();
|
|
await panel
|
|
.getByRole("alert")
|
|
.filter({ hasText: /上次保存未写入/ })
|
|
.waitFor();
|
|
await page.unroute("**/review-draft");
|
|
assert.equal(await input.inputValue(), fourth, "conflict keeps the text for an explicit retry");
|
|
await panel.getByRole("button", { name: "保存批注", exact: true }).click();
|
|
await panel
|
|
.getByRole("status")
|
|
.filter({ hasText: /^已保存$/ })
|
|
.waitFor();
|
|
draft = (await read()).draft;
|
|
assert.equal(
|
|
draft.problems.filter((p) => p.text === fourth).length,
|
|
1,
|
|
"reconciliation never duplicates the record",
|
|
);
|
|
|
|
// IME composition and key repeat never trigger saves.
|
|
const version = draft.version;
|
|
let puts = 0;
|
|
page.on("request", (r) => {
|
|
if (r.method() === "PUT" && r.url().endsWith("/review-draft")) puts++;
|
|
});
|
|
await options.nth(0).click();
|
|
await page.keyboard.press("Enter");
|
|
await input.evaluate((el) => {
|
|
el.dispatchEvent(new KeyboardEvent("keydown", { key: "Enter", ctrlKey: true, repeat: true, bubbles: true }));
|
|
el.dispatchEvent(
|
|
new KeyboardEvent("keydown", { key: "Enter", ctrlKey: true, isComposing: true, bubbles: true }),
|
|
);
|
|
});
|
|
await page.evaluate(() => new Promise((resolve) => requestAnimationFrame(() => requestAnimationFrame(resolve))));
|
|
assert.equal(puts, 0);
|
|
assert.equal((await read()).draft.version, version);
|
|
await page.keyboard.press("Escape");
|
|
|
|
// Refresh keeps first-save order and the select/recall behavior.
|
|
await open();
|
|
await settle();
|
|
const persisted = (await read()).draft;
|
|
assert.deepEqual(
|
|
persisted.problems.map((p) => p.id),
|
|
draft.problems.map((p) => p.id),
|
|
"refresh keeps first-save order",
|
|
);
|
|
assert.equal(await input.inputValue(), "", "refresh does not resurrect an editor");
|
|
await options.nth(0).click();
|
|
await settle();
|
|
assert.equal(await options.nth(0).getAttribute("aria-selected"), "true");
|
|
|
|
// Acceptance whole-task problems keep a frozen view anchor for recall.
|
|
if (mode === "acceptance") {
|
|
await page.keyboard.press("f");
|
|
await picker.waitFor();
|
|
await picker.getByRole("radio", { name: "整体", exact: true }).click();
|
|
await page.waitForFunction(() => document.activeElement?.getAttribute("aria-label") === "审查问题说明");
|
|
const taskNote = `acceptance 整体问题 ${Date.now()}`;
|
|
await input.fill(taskNote);
|
|
await input.press("Control+Enter");
|
|
await panel
|
|
.getByRole("status")
|
|
.filter({ hasText: /^已保存$/ })
|
|
.waitFor();
|
|
draft = (await read()).draft;
|
|
const taskProblem = draft.problems.find((p) => p.text === taskNote);
|
|
assert.equal(taskProblem.scope, "task");
|
|
assert.ok(!taskProblem.sliceId && !taskProblem.actionId, "task targeting stays global");
|
|
assert.ok(taskProblem.viewAnchor?.sliceId, "task problem carries the frozen F frame anchor");
|
|
const slicePick = () => page.locator('[aria-label="验收切片选择"] button');
|
|
const pressedGroup = async () => {
|
|
const count = await slicePick().count();
|
|
for (let i = 0; i < count; i++)
|
|
if ((await slicePick().nth(i).getAttribute("aria-pressed")) === "true") return i;
|
|
return -1;
|
|
};
|
|
const anchoredGroup = await pressedGroup();
|
|
// Move to a different source/slice first: recall must cross sources.
|
|
const otherGroup = anchoredGroup === 0 ? 2 : 0;
|
|
await slicePick().nth(otherGroup).click();
|
|
await settle();
|
|
assert.equal(await pressedGroup(), otherGroup, "switched away from the anchored source");
|
|
await panel.getByRole("option").filter({ hasText: taskNote }).click();
|
|
await settle();
|
|
assert.equal(await pressedGroup(), anchoredGroup, "mouse recall restores the anchored source");
|
|
assert.ok(
|
|
Math.abs(Number(await range.inputValue()) - taskProblem.viewAnchor.atSeconds) < 0.5,
|
|
"task anchor recalls the recorded picture",
|
|
);
|
|
// Ctrl/Cmd+Up/Down recall crosses sources the same way.
|
|
await slicePick().nth(otherGroup).click();
|
|
await settle();
|
|
await page.keyboard.press("Control+ArrowUp");
|
|
await settle();
|
|
await page.keyboard.press("Control+ArrowDown");
|
|
await settle();
|
|
assert.equal(
|
|
await panel.getByRole("option").filter({ hasText: taskNote }).getAttribute("aria-selected"),
|
|
"true",
|
|
"Ctrl navigation reselects the task problem",
|
|
);
|
|
assert.equal(await pressedGroup(), anchoredGroup, "Ctrl navigation restores the anchored source");
|
|
assert.ok(
|
|
Math.abs(Number(await range.inputValue()) - taskProblem.viewAnchor.atSeconds) < 0.5,
|
|
"Ctrl navigation restores the anchored picture",
|
|
);
|
|
}
|
|
|
|
assert.equal(formalRequests.length, 0, "no formal decision was issued");
|
|
assert.deepEqual(errors, []);
|
|
await page.screenshot({
|
|
path: `${dir}/problem-editor-flow-${mode}-${focused ? "focus" : "ordinary"}.png`,
|
|
fullPage: true,
|
|
});
|
|
reports.push({ mode, focused, ok: true, problems: (await read()).draft.problems.length });
|
|
console.log("PASS", mode, focused ? "focus" : "ordinary");
|
|
await context.close();
|
|
}
|
|
}
|
|
await fs.writeFile(
|
|
`${dir}/review-problem-editor-flow-${process.env.REVIEW_EDITOR_MODE || "all"}.json`,
|
|
JSON.stringify(reports, null, 2),
|
|
);
|
|
} finally {
|
|
await browser.close();
|
|
}
|