192 lines
6.0 KiB
JavaScript
192 lines
6.0 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.goto(`${base}/playground/frame.html?concept=dock`);
|
|
await p.locator(".dock-toggle").waitFor();
|
|
const brand = await p.locator(".navigation .wordmark").boundingBox();
|
|
const trigger = await p.locator(".dock-toggle").boundingBox();
|
|
assert.ok(brand.y < trigger.y, "Brand is above menu trigger");
|
|
await p.locator(".dock-toggle").hover();
|
|
await p.waitForTimeout(300);
|
|
assert.equal(
|
|
await p.locator(".dock-toggle").getAttribute("aria-expanded"),
|
|
"true",
|
|
);
|
|
await p.locator(".nav-links button").first().hover();
|
|
await p.waitForTimeout(250);
|
|
assert.equal(
|
|
await p.locator(".dock-toggle").getAttribute("aria-expanded"),
|
|
"true",
|
|
);
|
|
await p.mouse.move(380, 400);
|
|
await p.waitForTimeout(450);
|
|
assert.equal(
|
|
await p.locator(".dock-toggle").getAttribute("aria-expanded"),
|
|
"false",
|
|
);
|
|
passed++;
|
|
const touch = await browser.newContext({
|
|
viewport: { width: 390, height: 844 },
|
|
hasTouch: true,
|
|
isMobile: true,
|
|
});
|
|
const tp = await touch.newPage();
|
|
await tp.goto(`${base}/playground/frame.html?concept=dock`);
|
|
await tp.locator(".dock-toggle").tap();
|
|
assert.equal(
|
|
await tp.locator(".dock-toggle").getAttribute("aria-expanded"),
|
|
"true",
|
|
);
|
|
await tp.locator(".dock-toggle").tap();
|
|
assert.equal(
|
|
await tp.locator(".dock-toggle").getAttribute("aria-expanded"),
|
|
"false",
|
|
);
|
|
await touch.close();
|
|
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; logo order, hover enter/leave, touch fallback; reduced motion",
|
|
},
|
|
null,
|
|
2,
|
|
),
|
|
);
|
|
console.log("Dock revision:", passed, "passed");
|
|
} finally {
|
|
await browser.close();
|
|
}
|