forked from longtao.wu/droboticflow
107 lines
5.4 KiB
JavaScript
107 lines
5.4 KiB
JavaScript
import { createServer } from "vite";
|
|
import { chromium } from "playwright";
|
|
import assert from "node:assert/strict";
|
|
import fs from "node:fs/promises";
|
|
import { browserExecutableOptions } from "../../scripts/lib/browser-executable.mjs";
|
|
import { closeBrowserFixture } from "../../scripts/lib/browser-test-lifecycle.mjs";
|
|
const out = "local-data/test-results/acceptance-timeline-pan";
|
|
await fs.mkdir(out, { recursive: true });
|
|
let server, browser, page;
|
|
const cases = [];
|
|
try {
|
|
server = await createServer({
|
|
configFile: "tests/browser/vite.platform-feedback.config.ts",
|
|
cacheDir: `${out}/vite-cache`,
|
|
server: { host: "127.0.0.1", port: 0 },
|
|
});
|
|
await server.listen();
|
|
browser = await chromium.launch({ ...browserExecutableOptions(), headless: true, args: ["--no-proxy-server"] });
|
|
page = await browser.newPage({ viewport: { width: 1200, height: 800 } });
|
|
page.setDefaultTimeout(5000);
|
|
const errors = [];
|
|
page.on("pageerror", (e) => errors.push(e.message));
|
|
await page.route("**/__timeline_pan*", (route) =>
|
|
route.fulfill({
|
|
contentType: "text/html",
|
|
body: `<!doctype html><html><body><div id="root"></div><script type="module">import F from '/@react-refresh';F.injectIntoGlobalHook(window);window.$RefreshReg$=()=>{};window.$RefreshSig$=()=>x=>x;window.__vite_plugin_react_preamble_installed__=true;await import('/tests/browser/fixtures/acceptance-timeline-pan.tsx');</script></body></html>`,
|
|
}),
|
|
);
|
|
for (const mode of ["normal", "focused", "focused&readonly"]) {
|
|
await page.goto(`${server.resolvedUrls.local[0]}__timeline_pan?${mode}`);
|
|
const timeline = page.getByTestId("acceptance-action-timeline");
|
|
const viewport = timeline.locator(":scope > div").first();
|
|
await viewport.waitFor();
|
|
assert(await viewport.evaluate((el) => el.scrollWidth > el.clientWidth));
|
|
const scrollbar = page.getByLabel("动作时间轴横向滚动", { exact: true });
|
|
await scrollbar.waitFor();
|
|
assert((await scrollbar.boundingBox()).height >= 14, "scroll control remains visible independently of OS settings");
|
|
const viewportBox = await viewport.boundingBox();
|
|
const timelineBox = await timeline.boundingBox();
|
|
const scrollBox = await scrollbar.boundingBox();
|
|
assert(
|
|
timelineBox.y + timelineBox.height >= scrollBox.y + scrollBox.height,
|
|
"focused layout must not clip the scrollbar",
|
|
);
|
|
await page.getByRole("button", { name: /^动作 3 / }).click();
|
|
assert.equal(await page.getByLabel("已定位时间").textContent(), "4");
|
|
const action = page.getByRole("button", { name: /^动作 1 / });
|
|
const box = await action.boundingBox();
|
|
await page.mouse.move(box.x + box.width / 2, box.y + 20);
|
|
await page.mouse.down();
|
|
await page.mouse.move(box.x + box.width / 2 - 220, box.y + 20, { steps: 8 });
|
|
await page.mouse.up();
|
|
assert((await viewport.evaluate((el) => el.scrollLeft)) > 100, "mouse drag must pan overflowing actions");
|
|
assert.equal(await page.getByLabel("已定位时间").textContent(), "4", "panning must not seek or select an action");
|
|
await page.getByRole("button", { name: /^动作 4 / }).click();
|
|
assert.equal(await page.getByLabel("已定位时间").textContent(), "6", "ordinary clicks still seek after a drag");
|
|
await page.getByRole("button", { name: "定位末条动作" }).click();
|
|
await page.waitForFunction(
|
|
() => document.querySelector('[data-testid="acceptance-action-viewport"]').scrollLeft > 2000,
|
|
);
|
|
const last = await page.getByRole("button", { name: /^动作 30 / }).boundingBox();
|
|
assert(
|
|
last.x >= viewportBox.x && last.x + last.width <= viewportBox.x + viewportBox.width + 1,
|
|
"selected last action scrolls fully into view",
|
|
);
|
|
await viewport.evaluate((el) => (el.scrollLeft = 0));
|
|
await page.mouse.move(viewportBox.x + viewportBox.width / 2, viewportBox.y + 20);
|
|
await page.mouse.wheel(250, 0);
|
|
await page.waitForFunction(
|
|
() => document.querySelector('[data-testid="acceptance-action-viewport"]').scrollLeft > 100,
|
|
);
|
|
await viewport.evaluate((el) => (el.scrollLeft = 0));
|
|
await page.mouse.click(scrollBox.x + scrollBox.width * 0.75, scrollBox.y + scrollBox.height / 2);
|
|
await page.waitForFunction(
|
|
() => document.querySelector('[data-testid="acceptance-action-viewport"]').scrollLeft > 100,
|
|
);
|
|
assert.equal(await page.getByLabel("已定位时间").textContent(), "58", "scrollbar and wheel never seek");
|
|
await page.screenshot({ path: `${out}/${mode.replaceAll("&", "-")}.png`, fullPage: true });
|
|
cases.push(mode);
|
|
}
|
|
assert.deepEqual(errors, []);
|
|
await fs.writeFile(`${out}/report.json`, JSON.stringify({ passed: true, cases }, null, 2));
|
|
console.log(JSON.stringify({ passed: true, cases }));
|
|
} catch (error) {
|
|
await page?.screenshot({ path: `${out}/failure.png`, fullPage: true }).catch(() => {});
|
|
console.error(error);
|
|
console.log(
|
|
await page?.evaluate(() => {
|
|
const el = document.querySelector('[data-testid="acceptance-action-viewport"]');
|
|
return (
|
|
el && {
|
|
height: el.offsetHeight,
|
|
client: el.clientHeight,
|
|
width: el.clientWidth,
|
|
scrollWidth: el.scrollWidth,
|
|
overflow: getComputedStyle(el).overflowX,
|
|
bar: getComputedStyle(el, "::-webkit-scrollbar").height,
|
|
scrollbarWidth: getComputedStyle(el).scrollbarWidth,
|
|
}
|
|
);
|
|
}),
|
|
);
|
|
throw error;
|
|
} finally {
|
|
await closeBrowserFixture({ browser, vite: server });
|
|
}
|