Files
anidev-design-system/tests/approved-dock.mjs
T

184 lines
6.1 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 browser = await chromium.launch({
executablePath:
process.env.PLAYWRIGHT_EXECUTABLE_PATH ||
"C:/Program Files (x86)/Microsoft/Edge/Application/msedge.exe",
headless: true,
});
const page = await browser.newPage({ viewport: { width: 1440, height: 700 } }),
errors = [];
page.on("pageerror", (e) => errors.push(e.message));
let passed = 0;
await mkdir("references/approved-dock", { recursive: true });
const frame = (p, theme) =>
`${base}/playground/frame.html?concept=dock&page=${p}&theme=${theme}&density=compact`;
try {
await page.goto(base + "/playground/");
await page.frameLocator("#preview-a").locator("h1").waitFor();
assert.equal(
await page
.locator("#concepts,#compare,#second,#preview-b,.version")
.count(),
0,
);
assert.equal(
/EXPLORATIONS|Relay|Ledger|Signal|Axis|Grid|Шесть точек|не выбрана/.test(
await page.locator("body").innerText(),
),
false,
);
passed++;
// A preference saved before approval must not restore an abandoned concept.
await page.evaluate(() =>
localStorage.setItem(
"anidev.lab",
JSON.stringify({
concept: "ledger",
second: "signal",
compare: true,
theme: "light",
page: "users",
locale: "ru",
}),
),
);
await page.reload();
await page.frameLocator("#preview-a").locator("#user-search").waitFor();
assert.equal(
await page
.frameLocator("#preview-a")
.locator("body")
.getAttribute("data-concept"),
"dock",
);
passed++;
for (const theme of ["light", "dark"]) {
for (const [p, selector] of [
["users", "tbody tr"],
["dashboard", ".service"],
["dashboard", ".activity-row"],
["security", ".identity-setting-row"],
["sessions", ".identity-session"],
["applications", ".identity-app"],
["tokens", ".token-row"],
]) {
await page.goto(frame(p, theme));
await page.locator(selector).first().waitFor();
await page.waitForTimeout(450);
const row = page.locator(selector).first();
await page.mouse.move(1430, 690);
const rest = await row.evaluate(
(el) => getComputedStyle(el).backgroundColor,
);
await row.hover();
await page.waitForTimeout(180);
const hover = await row.evaluate(
(el) => getComputedStyle(el).backgroundColor,
);
assert.notEqual(
hover,
rest,
`${theme}/${p}/${selector} hover; actual hover=${await row.evaluate((el) => el.matches(":hover"))}`,
);
assert.notEqual(hover, "rgba(0, 0, 0, 0)");
passed++;
if (p === "users") {
await page.screenshot({
path: `references/approved-dock/rows-${theme}-desktop.png`,
});
await row.locator("[data-edit]").focus();
assert.equal(
await row.evaluate((el) => getComputedStyle(el).backgroundColor),
hover,
);
passed++;
}
}
await page.goto(frame("profile", theme));
await page.locator("#identity-profile").waitFor();
await page.waitForTimeout(450);
await page.evaluate(() => scrollTo(0, 160));
const before = await page.locator(".main-column").boundingBox(),
scroll = await page.evaluate(() => scrollY);
assert.match(
await page
.locator("html")
.evaluate((el) => getComputedStyle(el).scrollbarGutter),
/stable/,
);
assert.notEqual(
await page
.locator("html")
.evaluate((el) => getComputedStyle(el).scrollbarColor),
"auto",
);
await page.locator(".dock-brand").hover();
await page.waitForTimeout(300);
const open = await page.locator(".main-column").boundingBox();
assert.equal(open.x, before.x);
assert.equal(open.width, before.width);
assert.equal(await page.evaluate(() => scrollY), scroll);
await page.keyboard.press("Escape");
await page.mouse.move(1430, 690);
await page.waitForTimeout(300);
const closed = await page.locator(".main-column").boundingBox();
assert.equal(closed.x, before.x);
assert.equal(closed.width, before.width);
passed++;
// Native modal / scroll locking must not move the shell either.
await page.goto(frame("users", theme));
await page.locator("#user-search").waitFor();
const baseBox = await page.locator(".main-column").boundingBox();
await page.locator("[data-edit]").first().click();
await page.waitForTimeout(300);
const modalBox = await page.locator(".main-column").boundingBox();
assert.equal(baseBox.x, modalBox.x);
assert.equal(baseBox.width, modalBox.width);
await page.keyboard.press("Escape");
passed++;
}
await page.goto(frame("profile", "light"));
await page.locator("#identity-profile").waitFor();
const long = await page.locator(".main-column").boundingBox();
await page.locator(".nav-links [data-page=applications]").click();
await page.locator(".identity-app").first().waitFor();
const short = await page.locator(".main-column").boundingBox();
assert.equal(long.width, short.width);
assert.equal(long.x, short.x);
passed++;
await page.setViewportSize({ width: 390, height: 844 });
await page.goto(base + "/playground/");
await page.frameLocator("#preview-a").locator("h1").waitFor();
assert.ok(
await page.evaluate(
() => document.documentElement.scrollWidth <= innerWidth,
),
);
await page.screenshot({
path: "references/approved-dock/gallery-mobile.png",
fullPage: true,
});
passed++;
assert.deepEqual(errors, []);
await writeFile(
"references/approved-dock/qa.json",
JSON.stringify(
{
passed,
failed: 0,
errors,
checks:
"Dock-only migration; hover/focus rows; stable geometry across nav and dialog open/close and long/short pages; themed native scrollbars; mobile",
},
null,
2,
),
);
console.log(`Approved Dock: ${passed} passed`);
} finally {
await browser.close();
}