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

149 lines
4.6 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,
});
let passed = 0;
const errors = [];
await mkdir("references/dock-revision", { recursive: true });
try {
const p = await browser.newPage();
p.on("pageerror", (e) => errors.push(e.message));
for (const theme of ["light", "dark"])
for (const [device, width, height] of [
["desktop", 1440, 900],
["tablet", 768, 1024],
["mobile", 390, 844],
]) {
await p.setViewportSize({ width, height });
await p.goto(
`${base}/playground/frame.html?concept=dock&density=compact&theme=${theme}`,
);
await p.locator("h1").waitFor();
await p.waitForTimeout(400);
assert.ok(
await p
.locator(".navigation")
.evaluate((el) => el.getBoundingClientRect().width <= 68),
);
assert.equal(
await p
.locator(".nav-links button>span")
.first()
.evaluate((el) => getComputedStyle(el).opacity),
"0",
);
const before = await p.locator(".main-column").boundingBox();
await p.screenshot({
path: `references/dock-revision/${theme}-${device}-collapsed.png`,
});
await p.locator(".dock-toggle").click();
await p.waitForTimeout(300);
const after = await p.locator(".main-column").boundingBox();
assert.equal(before.x, after.x);
assert.equal(before.width, after.width);
assert.equal(
await p.locator(".main-column").evaluate((el) => el.inert),
true,
);
assert.equal(
await p
.locator(".dock-scrim")
.evaluate((el) => getComputedStyle(el).opacity),
"1",
);
assert.equal(
await p
.locator(".nav-links button>span")
.first()
.evaluate((el) => getComputedStyle(el).opacity),
"1",
);
await p.screenshot({
path: `references/dock-revision/${theme}-${device}-expanded.png`,
});
await p.locator(".dock-account").click();
await p.locator("#account-menu").waitFor({ state: "visible" });
await p.waitForTimeout(220);
await p.screenshot({
path: `references/dock-revision/${theme}-${device}-account.png`,
});
await p.locator("#account-menu [data-action=switch-account]").click();
await p.locator("#dialog").waitFor({ state: "visible" });
await p.locator('[data-account="Mikhail Orlov"]').click();
assert.equal(
await p.locator(".account-identity b").innerText(),
"Mikhail Orlov",
);
await p.locator(".dock-toggle").click();
await p.keyboard.press("Escape");
assert.equal(
await p.locator(".main-column").evaluate((el) => el.inert),
false,
);
await p.locator(".dock-toggle").click();
await p.waitForTimeout(300);
await p.mouse.click(width - 12, Math.floor(height / 2));
assert.equal(
await p.locator(".dock-toggle").getAttribute("aria-expanded"),
"false",
);
assert.ok(
await p.evaluate(
() => document.documentElement.scrollWidth <= innerWidth + 1,
),
);
passed++;
}
await p.locator(".dock-toggle").click();
await p.locator(".dock-account").focus();
await p.keyboard.press("Enter");
assert.equal(
await p.evaluate(() => document.activeElement.closest("[popover]")?.id),
"account-menu",
);
await p.keyboard.press("Escape");
assert.equal(
await p.locator(".dock-toggle").getAttribute("aria-expanded"),
"true",
);
await p.keyboard.press("Escape");
assert.equal(
await p.locator(".dock-toggle").getAttribute("aria-expanded"),
"false",
);
passed++;
await p.emulateMedia({ reducedMotion: "reduce" });
await p.reload();
assert.equal(
await p
.locator(".panel")
.first()
.evaluate((el) => getComputedStyle(el).animationName),
"none",
);
passed++;
assert.deepEqual(errors, []);
await writeFile(
"references/dock-revision/qa.json",
JSON.stringify(
{
passed,
errors,
checks:
"6 theme/viewport scenarios: overlay geometry, inert background, scrim, icons/labels, account switch, Escape/outside close; reduced motion",
},
null,
2,
),
);
console.log("Dock revision:", passed, "passed");
} finally {
await browser.close();
}