forked from longtao.wu/droboticflow
116 lines
5.4 KiB
JavaScript
116 lines
5.4 KiB
JavaScript
// Actual slice edit panel and stylesheet, using synthetic dictionaries only.
|
|
import assert from "node:assert/strict";
|
|
import { chromium } from "playwright";
|
|
|
|
const base = process.env.DICTIONARY_TEST_URL || "http://localhost:5173";
|
|
assert.ok(["localhost", "127.0.0.1", "[::1]"].includes(new URL(base).hostname), "local replica only");
|
|
const browser = await chromium.launch({
|
|
executablePath: process.env.BROWSER_EXECUTABLE || "/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge",
|
|
headless: true,
|
|
args: ["--no-proxy-server"],
|
|
});
|
|
try {
|
|
const page = await browser.newPage();
|
|
await page.goto(`${base}/__capture-workbench`, { waitUntil: "domcontentloaded" });
|
|
await page.evaluate(async () => {
|
|
const source = await (await fetch("/src/main.tsx")).text();
|
|
const React = (await import(source.match(/from "([^"]*\/react\.js\?[^"]*)"/)[1])).default;
|
|
const { createRoot } = (await import(source.match(/from "([^"]*\/react-dom_client\.js\?[^"]*)"/)[1])).default;
|
|
const { SliceEditPanel } = await import("/src/components/SliceEditPanel.tsx");
|
|
document.getElementById("root").style.display = "none";
|
|
const mount = document.createElement("div");
|
|
mount.className = "annotation-operations-page";
|
|
mount.style = "position:relative;height:100vh";
|
|
document.body.append(mount);
|
|
let root;
|
|
window.mountDictionaryTest = (compact) => {
|
|
root?.unmount();
|
|
mount.toggleAttribute("data-workspace-compact", compact);
|
|
window.dictionaryApplied = null;
|
|
function Harness() {
|
|
const [name, setName] = React.useState("原名称");
|
|
const [draft, setDraft] = React.useState(null);
|
|
const [discarded, setDiscarded] = React.useState(false);
|
|
const noop = () => {};
|
|
return React.createElement(SliceEditPanel, {
|
|
target: { id: "synthetic", start: 0, end: 180, name, deliveryDisposition: discarded ? "discard" : "keep" },
|
|
ordinal: 1,
|
|
total: 2,
|
|
focusBoundary: "end",
|
|
fixed: { start: true, end: false },
|
|
exactFrames: false,
|
|
frameIndexOf: (t) => Math.round(t * 30),
|
|
saving: false,
|
|
playheadLabel: "60s",
|
|
onFocusBoundary: noop,
|
|
onStep: noop,
|
|
onCoarse: noop,
|
|
onSetBoundary: noop,
|
|
onSplit: noop,
|
|
onDiscard: () => setDraft({ discard: true }),
|
|
onMerge: noop,
|
|
onCancel: noop,
|
|
onApply: () => {
|
|
window.dictionaryApplied = { name, discarded };
|
|
},
|
|
dictionary: {
|
|
items: Array.from({ length: 21 }, (_, i) => ({ id: `name-${i}`, name: `切片名称${i}` })),
|
|
onSelect: setName,
|
|
},
|
|
discard: {
|
|
draft,
|
|
reasons: Array.from({ length: 7 }, (_, i) => ({ id: `reason-${i}`, name: `舍弃原因${i}`, version: 1 })),
|
|
allowManual: false,
|
|
loading: false,
|
|
error: "",
|
|
onDraftChange: setDraft,
|
|
onConfirm: () => {
|
|
setDiscarded(true);
|
|
setDraft(null);
|
|
},
|
|
onCancel: () => setDraft(null),
|
|
},
|
|
});
|
|
}
|
|
root = createRoot(mount);
|
|
root.render(React.createElement(Harness));
|
|
};
|
|
});
|
|
const results = [];
|
|
for (const height of [900, 720, 615]) {
|
|
await page.setViewportSize({ width: 1280, height });
|
|
for (const compact of [false, true]) {
|
|
await page.evaluate((c) => window.mountDictionaryTest(c), compact);
|
|
const panel = page.getByTestId("slice-edit-panel");
|
|
await panel.getByRole("button", { name: "从切片字典选择", exact: true }).click();
|
|
const dictionary = panel.getByRole("dialog", { name: "选择切片名称", exact: true });
|
|
assert.ok(
|
|
await dictionary.locator(".workspace-dictionary-results").evaluate((el) => el.clientHeight >= 26),
|
|
"name options have visible height",
|
|
);
|
|
await dictionary.getByRole("button", { name: "下一页", exact: true }).click();
|
|
assert.match(await dictionary.locator("nav").innerText(), /2\s*\//);
|
|
await dictionary.getByRole("textbox", { name: "搜索切片字典", exact: true }).fill("切片名称20");
|
|
await dictionary.getByRole("button", { name: "切片名称20", exact: true }).click();
|
|
await panel.getByTestId("slice-edit-panel-apply").click();
|
|
assert.equal(await page.evaluate(() => window.dictionaryApplied.name), "切片名称20");
|
|
await panel.getByRole("button", { name: "G 舍弃当前切片", exact: true }).click();
|
|
const reasons = panel.getByRole("dialog", { name: "选择舍弃原因", exact: true });
|
|
assert.ok(
|
|
await reasons.locator(".workspace-dictionary-results").evaluate((el) => el.clientHeight >= 26),
|
|
"discard options have visible height",
|
|
);
|
|
await reasons.getByRole("button", { name: "下一页", exact: true }).click();
|
|
await reasons.getByRole("textbox", { name: "搜索舍弃字典", exact: true }).fill("舍弃原因6");
|
|
await reasons.getByRole("button", { name: "舍弃原因6", exact: true }).click();
|
|
await panel.getByRole("button", { name: "记入预览", exact: true }).click();
|
|
await panel.getByTestId("slice-edit-panel-apply").click();
|
|
assert.equal(await page.evaluate(() => window.dictionaryApplied.discarded), true);
|
|
results.push({ height, compact, nameSelection: "passed", discardSelection: "passed", applyButtons: "passed" });
|
|
}
|
|
}
|
|
console.log(JSON.stringify(results, null, 2));
|
|
} finally {
|
|
await browser.close();
|
|
}
|