No files matched your search
|
Before Width: | Height: | Size: 228 KiB After Width: | Height: | Size: 228 KiB |
|
Before Width: | Height: | Size: 175 KiB After Width: | Height: | Size: 185 KiB |
|
Before Width: | Height: | Size: 177 KiB After Width: | Height: | Size: 191 KiB |
|
Before Width: | Height: | Size: 269 KiB After Width: | Height: | Size: 270 KiB |
|
Before Width: | Height: | Size: 174 KiB After Width: | Height: | Size: 184 KiB |
|
Before Width: | Height: | Size: 165 KiB After Width: | Height: | Size: 177 KiB |
@@ -10,11 +10,24 @@ import { chromium } from "playwright";
|
||||
|
||||
const UPDATE_SNAPSHOTS = process.env.UPDATE_SNAPSHOTS === "1";
|
||||
const MAX_DIFF_PIXELS = Number(process.env.UI_MAX_DIFF_PIXELS ?? 220);
|
||||
const SAMPLE_MAX_CROSSINGS = Number(process.env.UI_SAMPLE_MAX_CROSSINGS ?? 1);
|
||||
const SAMPLE_MAX_OVERLAPS = Number(process.env.UI_SAMPLE_MAX_OVERLAPS ?? 1);
|
||||
const SAMPLE_MAX_DETOUR = Number(process.env.UI_SAMPLE_MAX_DETOUR ?? 3.2);
|
||||
const DRAG_MAX_CROSSINGS = Number(process.env.UI_DRAG_MAX_CROSSINGS ?? 3);
|
||||
const DRAG_MAX_OVERLAPS = Number(process.env.UI_DRAG_MAX_OVERLAPS ?? 3);
|
||||
const DRAG_MAX_DETOUR = Number(process.env.UI_DRAG_MAX_DETOUR ?? 3.5);
|
||||
const TIDY_MAX_CROSSINGS = Number(process.env.UI_TIDY_MAX_CROSSINGS ?? 2);
|
||||
const TIDY_MAX_OVERLAPS = Number(process.env.UI_TIDY_MAX_OVERLAPS ?? 2);
|
||||
const TIDY_MAX_DETOUR = Number(process.env.UI_TIDY_MAX_DETOUR ?? 2.0);
|
||||
const DENSE_MAX_CROSSINGS = Number(process.env.UI_DENSE_MAX_CROSSINGS ?? 2);
|
||||
const DENSE_MAX_OVERLAPS = Number(process.env.UI_DENSE_MAX_OVERLAPS ?? 2);
|
||||
const DENSE_MAX_DETOUR = Number(process.env.UI_DENSE_MAX_DETOUR ?? 3.0);
|
||||
const BASELINE_DIR = join(process.cwd(), "tests", "baselines", "ui");
|
||||
const OUTPUT_DIR = join(process.cwd(), "output", "playwright");
|
||||
const CURRENT_DIR = join(OUTPUT_DIR, "current");
|
||||
const DIFF_DIR = join(OUTPUT_DIR, "diff");
|
||||
const DENSE_ANALOG_PATH = join(process.cwd(), "examples", "dense-analog.json");
|
||||
const REPORT_PATH = join(OUTPUT_DIR, "ui-metrics-report.json");
|
||||
|
||||
async function getFreePort() {
|
||||
const probe = createNetServer();
|
||||
@@ -138,13 +151,32 @@ async function run() {
|
||||
const srv = await startServer(port);
|
||||
const browser = await chromium.launch({ headless: true });
|
||||
const page = await browser.newPage({ viewport: { width: 1600, height: 900 } });
|
||||
const report = {
|
||||
generated_at: new Date().toISOString(),
|
||||
thresholds: {
|
||||
sample: { crossings: SAMPLE_MAX_CROSSINGS, overlaps: SAMPLE_MAX_OVERLAPS, detour: SAMPLE_MAX_DETOUR },
|
||||
drag: { crossings: DRAG_MAX_CROSSINGS, overlaps: DRAG_MAX_OVERLAPS, detour: DRAG_MAX_DETOUR },
|
||||
tidy: { crossings: TIDY_MAX_CROSSINGS, overlaps: TIDY_MAX_OVERLAPS, detour: TIDY_MAX_DETOUR },
|
||||
dense: { crossings: DENSE_MAX_CROSSINGS, overlaps: DENSE_MAX_OVERLAPS, detour: DENSE_MAX_DETOUR }
|
||||
},
|
||||
snapshots: {},
|
||||
status: {}
|
||||
};
|
||||
|
||||
try {
|
||||
await page.goto(`${srv.baseUrl}/`);
|
||||
await page.waitForSelector("#compileStatus");
|
||||
await page.waitForFunction(() => document.querySelector("#compileStatus")?.textContent?.includes("Compiled"));
|
||||
const initialStatus = String((await page.locator("#compileStatus").textContent()) ?? "");
|
||||
const initialMetrics = parseStatusMetrics(initialStatus);
|
||||
report.status.initial = { text: initialStatus, metrics: initialMetrics };
|
||||
assert.ok(initialMetrics, `Unable to parse initial compile metrics from: ${initialStatus}`);
|
||||
assert.ok(initialMetrics.crossings <= SAMPLE_MAX_CROSSINGS, `sample crossings too high: ${initialMetrics.crossings}`);
|
||||
assert.ok(initialMetrics.overlaps <= SAMPLE_MAX_OVERLAPS, `sample overlaps too high: ${initialMetrics.overlaps}`);
|
||||
assert.ok(initialMetrics.detour <= SAMPLE_MAX_DETOUR, `sample detour too high: ${initialMetrics.detour}`);
|
||||
|
||||
await compareScene(page, "initial");
|
||||
report.snapshots.initial = "tests/baselines/ui/initial.png";
|
||||
await page.keyboard.press("Control+k");
|
||||
await page.getByRole("dialog", { name: "Command Palette" }).waitFor();
|
||||
await page.locator("#commandInput").fill("fit");
|
||||
@@ -161,6 +193,32 @@ async function run() {
|
||||
await page.getByRole("button", { name: "Reset view" }).click();
|
||||
await compareScene(page, "selected-u2");
|
||||
|
||||
const target = page.locator('[data-ref="U2"]');
|
||||
const box = await target.boundingBox();
|
||||
assert.ok(box, "selected U2 should be draggable");
|
||||
await page.mouse.move(box.x + box.width / 2, box.y + box.height / 2);
|
||||
await page.mouse.down();
|
||||
await page.mouse.move(box.x + box.width / 2 - 320, box.y + box.height / 2 + 220, { steps: 12 });
|
||||
await page.mouse.up();
|
||||
await page.waitForFunction(() => document.querySelector("#compileStatus")?.textContent?.includes("Compiled"));
|
||||
const dragStatus = String((await page.locator("#compileStatus").textContent()) ?? "");
|
||||
const dragMetrics = parseStatusMetrics(dragStatus);
|
||||
report.status.after_drag = { text: dragStatus, metrics: dragMetrics };
|
||||
assert.ok(dragMetrics, `Unable to parse drag compile metrics from: ${dragStatus}`);
|
||||
assert.ok(dragMetrics.crossings <= DRAG_MAX_CROSSINGS, `dragged layout crossings too high: ${dragMetrics.crossings}`);
|
||||
assert.ok(dragMetrics.overlaps <= DRAG_MAX_OVERLAPS, `dragged layout overlaps too high: ${dragMetrics.overlaps}`);
|
||||
assert.ok(dragMetrics.detour <= DRAG_MAX_DETOUR, `dragged layout detour too high: ${dragMetrics.detour}`);
|
||||
|
||||
await page.getByRole("button", { name: "Run automatic tidy layout" }).click();
|
||||
await page.waitForFunction(() => document.querySelector("#compileStatus")?.textContent?.includes("Compiled"));
|
||||
const tidyStatus = String((await page.locator("#compileStatus").textContent()) ?? "");
|
||||
const tidyMetrics = parseStatusMetrics(tidyStatus);
|
||||
report.status.after_drag_tidy = { text: tidyStatus, metrics: tidyMetrics };
|
||||
assert.ok(tidyMetrics, `Unable to parse tidy compile metrics from: ${tidyStatus}`);
|
||||
assert.ok(tidyMetrics.crossings <= TIDY_MAX_CROSSINGS, `drag+tidy crossings too high: ${tidyMetrics.crossings}`);
|
||||
assert.ok(tidyMetrics.overlaps <= TIDY_MAX_OVERLAPS, `drag+tidy overlaps too high: ${tidyMetrics.overlaps}`);
|
||||
assert.ok(tidyMetrics.detour <= TIDY_MAX_DETOUR, `drag+tidy detour too high: ${tidyMetrics.detour}`);
|
||||
|
||||
await page.locator("#canvasViewport").click({ position: { x: 40, y: 40 } });
|
||||
await expectText(page, "#selectedSummary", /Click a component, net, or pin/);
|
||||
|
||||
@@ -210,29 +268,47 @@ async function run() {
|
||||
await page.getByRole("button", { name: "Add Component" }).click();
|
||||
await waitFor(async () => (await page.locator("[data-ref-item]").count()) >= beforeInstanceCount + 1);
|
||||
|
||||
await page.locator("#newQuickNetClassSelect").selectOption("signal");
|
||||
await page.locator("#newQuickNetNameInput").fill("UI_TEST_NET");
|
||||
await page.getByRole("button", { name: "Add Net" }).click();
|
||||
await expectText(page, "#netList", /UI_TEST_NET/);
|
||||
|
||||
const dense = await readFile(DENSE_ANALOG_PATH, "utf8");
|
||||
await page.locator("#jsonEditor").fill(dense);
|
||||
await page.getByRole("button", { name: "Apply JSON" }).click();
|
||||
await expectText(page, "#jsonFeedback", /Applied JSON|blocked by validation/);
|
||||
await page.waitForFunction(() => document.querySelector("#compileStatus")?.textContent?.includes("Compiled"));
|
||||
const denseStatus = String((await page.locator("#compileStatus").textContent()) ?? "");
|
||||
const denseFeedback = String((await page.locator("#jsonFeedback").textContent()) ?? "");
|
||||
assert.ok(!/blocked by validation/i.test(denseFeedback), `dense fixture apply unexpectedly blocked: ${denseFeedback}`);
|
||||
const metrics = parseStatusMetrics(denseStatus);
|
||||
report.status.dense = { text: denseStatus, metrics, feedback: denseFeedback };
|
||||
assert.ok(metrics, `Unable to parse compile status metrics from: ${denseStatus}`);
|
||||
assert.equal(metrics.errors, 0, "dense analog scene should compile with no errors");
|
||||
assert.ok(metrics.crossings <= 2, `dense analog crossings too high: ${metrics.crossings}`);
|
||||
assert.ok(metrics.overlaps <= 2, `dense analog overlaps too high: ${metrics.overlaps}`);
|
||||
assert.equal(metrics.errors, 0, `dense analog scene should compile with no errors (feedback: ${denseFeedback})`);
|
||||
assert.ok(metrics.crossings <= DENSE_MAX_CROSSINGS, `dense analog crossings too high: ${metrics.crossings}`);
|
||||
assert.ok(metrics.overlaps <= DENSE_MAX_OVERLAPS, `dense analog overlaps too high: ${metrics.overlaps}`);
|
||||
assert.ok(metrics.detour <= DENSE_MAX_DETOUR, `dense analog detour too high: ${metrics.detour}`);
|
||||
await compareScene(page, "dense-analog");
|
||||
report.snapshots.dense = "tests/baselines/ui/dense-analog.png";
|
||||
|
||||
await page.setViewportSize({ width: 1280, height: 720 });
|
||||
await page.getByRole("button", { name: "Fit schematic to viewport" }).click();
|
||||
await expectText(page, "#compileStatus", /Compiled/);
|
||||
assert.ok(await page.locator("#applyJsonBtn").isVisible(), "Apply JSON button should remain visible at laptop viewport");
|
||||
await compareScene(page, "laptop-viewport");
|
||||
report.snapshots.laptop = "tests/baselines/ui/laptop-viewport.png";
|
||||
|
||||
const compileBeforeInvalidApply = String((await page.locator("#compileStatus").textContent()) ?? "");
|
||||
await page.locator("#jsonEditor").fill("{\"meta\":{\"title\":\"invalid\"},\"instances\":[],\"nets\":[]}");
|
||||
await page.getByRole("button", { name: "Apply JSON" }).click();
|
||||
await expectText(page, "#jsonFeedback", /blocked by validation/i);
|
||||
const compileAfterInvalidApply = String((await page.locator("#compileStatus").textContent()) ?? "");
|
||||
assert.equal(
|
||||
compileAfterInvalidApply,
|
||||
compileBeforeInvalidApply,
|
||||
"invalid JSON apply should not mutate compiled workspace state"
|
||||
);
|
||||
report.result = "pass";
|
||||
} finally {
|
||||
if (!report.result) {
|
||||
report.result = "fail";
|
||||
}
|
||||
await writeFile(REPORT_PATH, `${JSON.stringify(report, null, 2)}\n`);
|
||||
await page.close().catch(() => {});
|
||||
await browser.close().catch(() => {});
|
||||
await srv.stop().catch(() => {});
|
||||
|
||||