Files
anidev-design-system/tests/site.mjs
T

133 lines
4.4 KiB
JavaScript

import { chromium } from "playwright";
import assert from "node:assert/strict";
import { mkdir, writeFile } from "node:fs/promises";
const base = process.env.BASE_URL || "http://127.0.0.1:4173";
const b = await chromium.launch({
executablePath:
process.env.PLAYWRIGHT_EXECUTABLE_PATH ||
"C:/Program Files (x86)/Microsoft/Edge/Application/msedge.exe",
headless: true,
});
const p = await b.newPage({
viewport: { width: 1440, height: 900 },
acceptDownloads: true,
});
const errors = [];
p.on("pageerror", (e) => errors.push(e.message));
let passed = 0;
await mkdir("references/site", { recursive: true });
try {
for (const theme of ["light", "dark"])
for (const [device, width, height] of [
["desktop", 1440, 900],
["mobile", 390, 844],
]) {
await p.setViewportSize({ width, height });
await p.goto(`${base}/?page=dashboard&theme=${theme}`);
await p.locator(".health-line").waitFor();
assert.equal(
await p
.locator(
"iframe,.mast,.intro,.toolbar select#page,#preview-a,#workspace",
)
.count(),
0,
);
assert.equal(
await p.locator("body").getAttribute("data-concept"),
"dock",
);
assert.ok(
await p.evaluate(
() => document.documentElement.scrollWidth <= innerWidth,
),
);
await p.waitForTimeout(400);
await p.screenshot({
path: `references/site/${theme}-${device}.png`,
fullPage: true,
});
passed++;
await p.locator(".dock-brand").click();
await p.waitForTimeout(320);
for (const target of ["users", "settings", "components", "tokens"]) {
const item = p.locator(`.nav-links [data-page=${target}]`);
await p.mouse.move(width - 12, height - 12);
await item.blur();
await p.waitForTimeout(150);
const rest = await item.evaluate(
(e) => getComputedStyle(e).backgroundColor,
);
await item.hover();
await p.waitForTimeout(160);
const hover = await item.evaluate(
(e) => getComputedStyle(e).backgroundColor,
);
assert.notEqual(hover, rest, `${theme}/${device}/${target}`);
await item.focus();
assert.equal(
await item.evaluate((e) => getComputedStyle(e).backgroundColor),
hover,
);
passed++;
}
await p.screenshot({
path: `references/site/navigation-${theme}-${device}.png`,
});
await p.locator(".nav-links [data-page=users]").click();
await p.locator("#user-search").waitFor();
assert.equal(new URL(p.url()).searchParams.get("page"), "users");
assert.equal(
await p
.locator(".nav-links [data-page=users]")
.getAttribute("aria-current"),
"page",
);
await p.reload();
await p.locator("#user-search").waitFor();
await p.goBack();
await p.locator(".health-line").waitFor();
passed++;
const before = await p.locator(".main-column").boundingBox();
await p.locator(".dock-brand").click();
await p.waitForTimeout(280);
const after = await p.locator(".main-column").boundingBox();
assert.equal(before.x, after.x);
assert.equal(before.width, after.width);
await p.keyboard.press("Escape");
passed++;
}
await p.goto(base + "/playground/?page=users&theme=dark");
await p.locator("#user-search").waitFor();
assert.equal(new URL(p.url()).pathname, "/");
assert.equal(await p.locator("iframe").count(), 0);
passed++;
await p.goto(base + "/?page=appearance&theme=light");
await p.locator("[data-identity=theme][data-theme=dark]").click();
await p.reload();
assert.equal(await p.locator("body").getAttribute("data-theme"), "dark");
passed++;
await p.goto(base + "/?page=tokens");
const download = p.waitForEvent("download");
await p.locator("[data-action=download-system]").click();
await (await download).saveAs("test-results/site-export.zip");
passed++;
assert.deepEqual(errors, []);
await writeFile(
"references/site/qa.json",
JSON.stringify(
{
passed,
errors,
checks:
"Root app without wrapper; all navigation hover/focus; routes/reload/back; legacy redirects; theme persistence; no layout jump; export",
},
null,
2,
),
);
console.log("Standalone Dock:", passed, "passed");
} finally {
await b.close();
}