313 lines
12 KiB
JavaScript
313 lines
12 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();
|
|
const errors = [];
|
|
p.on("pageerror", (e) => errors.push(e.message));
|
|
let passed = 0;
|
|
await mkdir("references/navigation-feedback", { recursive: true });
|
|
try {
|
|
for (const theme of ["light", "dark"])
|
|
for (const width of [1440, 768, 390])
|
|
for (const locale of ["ru", "en"]) {
|
|
await p.setViewportSize({ width, height: 900 });
|
|
await p.goto(
|
|
`${base}/?page=components&theme=${theme}&locale=${locale}`,
|
|
);
|
|
const field = p.locator(".sample-control-row input");
|
|
await field.waitFor();
|
|
const before = await field.inputValue();
|
|
await field.click();
|
|
await p.keyboard.type("should not edit");
|
|
assert.equal(await field.inputValue(), before);
|
|
assert.equal(
|
|
await field.evaluate((e) => document.activeElement === e),
|
|
true,
|
|
);
|
|
assert.equal(
|
|
await p
|
|
.locator("#content")
|
|
.evaluate((e) => getComputedStyle(e).outlineStyle),
|
|
"none",
|
|
);
|
|
const { select, input } = await p
|
|
.locator(".sample-control-row")
|
|
.evaluate((e) => ({
|
|
select: e.querySelector("select").getBoundingClientRect().toJSON(),
|
|
input: e.querySelector("input").getBoundingClientRect().toJSON(),
|
|
}));
|
|
assert.ok(Math.abs(select.height - input.height) < 0.1);
|
|
if (width > 600) assert.ok(input.x - select.x - select.width >= 11.5);
|
|
else assert.ok(input.y - select.y - select.height >= 11.5);
|
|
for (const label of await p.locator(".choice-pill").all()) {
|
|
const { rect, control, text } = await label.evaluate((e) => ({
|
|
rect: e.getBoundingClientRect().toJSON(),
|
|
control: e.querySelector("input").getBoundingClientRect().toJSON(),
|
|
text: e.querySelector("span").getBoundingClientRect().toJSON(),
|
|
}));
|
|
assert.ok(
|
|
Math.abs(
|
|
control.y + control.height / 2 - text.y - text.height / 2,
|
|
) < 0.1,
|
|
);
|
|
assert.ok(
|
|
Math.abs(
|
|
control.y + control.height / 2 - rect.y - rect.height / 2,
|
|
) < 0.1,
|
|
);
|
|
}
|
|
await p.locator('input[name=retention][value="90"]').check();
|
|
assert.equal(
|
|
await p.locator('input[name=retention][value="30"]').isChecked(),
|
|
false,
|
|
);
|
|
await p.locator("#check-demo").uncheck();
|
|
assert.equal(await p.locator("#check-demo").isChecked(), false);
|
|
assert.ok(
|
|
await p.evaluate(
|
|
() => document.documentElement.scrollWidth <= innerWidth,
|
|
),
|
|
);
|
|
passed++;
|
|
if (locale === "ru")
|
|
await p.locator(".sample-control-row").screenshot({
|
|
path: `references/navigation-feedback/inputs-${theme}-${width}.png`,
|
|
});
|
|
await p.locator(".dock-brand").click();
|
|
await p.waitForTimeout(280);
|
|
const parent = p.locator(".nav-group-toggle"),
|
|
submenu = p.locator("#administration-submenu");
|
|
assert.equal(await parent.getAttribute("aria-expanded"), "false");
|
|
assert.equal(await submenu.evaluate((e) => e.inert), true);
|
|
await parent.click();
|
|
await p.waitForTimeout(220);
|
|
assert.equal(await parent.getAttribute("aria-expanded"), "true");
|
|
assert.equal(await submenu.evaluate((e) => e.inert), false);
|
|
assert.equal(await submenu.locator("button").count(), 2);
|
|
const textBounds = await parent
|
|
.locator(".nav-group-label")
|
|
.evaluate((e) => {
|
|
const range = document.createRange();
|
|
range.setStart(e.firstChild, 0);
|
|
range.setEnd(e.firstChild, e.firstChild.textContent.length);
|
|
return {
|
|
right: range.getBoundingClientRect().right,
|
|
chevron: e.querySelector("svg").getBoundingClientRect().left,
|
|
};
|
|
});
|
|
assert.ok(
|
|
textBounds.right <= textBounds.chevron - 3,
|
|
JSON.stringify(textBounds),
|
|
);
|
|
await submenu.locator("[data-page=ssh]").click();
|
|
await p.locator(".xterm-rows").waitFor();
|
|
assert.equal(
|
|
await p.locator(".dock-brand").getAttribute("aria-expanded"),
|
|
"true",
|
|
);
|
|
assert.equal(
|
|
await p.locator(".nav-group-toggle").getAttribute("data-active"),
|
|
"true",
|
|
);
|
|
assert.equal(
|
|
await p
|
|
.locator("#administration-submenu [data-page=ssh]")
|
|
.getAttribute("aria-current"),
|
|
"page",
|
|
);
|
|
await p.locator("#administration-submenu [data-page=logs]").click();
|
|
await p.locator(".log-row").first().waitFor();
|
|
assert.equal(
|
|
await p.locator(".dock-brand").getAttribute("aria-expanded"),
|
|
"true",
|
|
);
|
|
assert.equal(
|
|
await p.locator(".nav-group-toggle").getAttribute("aria-expanded"),
|
|
"true",
|
|
);
|
|
if (locale === "ru")
|
|
await p.locator(".navigation").screenshot({
|
|
path: `references/navigation-feedback/submenu-${theme}-${width}.png`,
|
|
});
|
|
await p.locator(".nav-group-toggle").focus();
|
|
await p.keyboard.press("ArrowLeft");
|
|
assert.equal(
|
|
await p.locator(".nav-group-toggle").getAttribute("aria-expanded"),
|
|
"false",
|
|
);
|
|
await p.keyboard.press("ArrowRight");
|
|
assert.equal(
|
|
await p
|
|
.locator("#administration-submenu button")
|
|
.first()
|
|
.evaluate((e) => document.activeElement === e),
|
|
true,
|
|
);
|
|
await p.keyboard.press("Escape");
|
|
assert.equal(
|
|
await p.locator(".nav-group-toggle").getAttribute("aria-expanded"),
|
|
"false",
|
|
);
|
|
assert.equal(
|
|
await p.locator(".dock-brand").getAttribute("aria-expanded"),
|
|
"true",
|
|
);
|
|
await p.keyboard.press("Escape");
|
|
assert.equal(
|
|
await p.locator(".dock-brand").getAttribute("aria-expanded"),
|
|
"false",
|
|
);
|
|
assert.equal(
|
|
await p.locator("#administration-submenu").evaluate((e) => e.inert),
|
|
true,
|
|
);
|
|
passed++;
|
|
await p.goto(
|
|
`${base}/?page=components&theme=${theme}&locale=${locale}`,
|
|
);
|
|
for (const type of ["success", "info", "warning", "error"]) {
|
|
await p.locator(`[data-action=toast-${type}]`).click();
|
|
await p.locator("#toast:popover-open").waitFor();
|
|
await p.waitForTimeout(200);
|
|
assert.equal(
|
|
await p.locator("#toast").getAttribute("data-type"),
|
|
type,
|
|
);
|
|
assert.equal(
|
|
await p.locator("#toast").getAttribute("role"),
|
|
type === "error" ? "alert" : "status",
|
|
);
|
|
assert.ok(await p.locator(".toast-message").innerText());
|
|
const rect = await p.locator("#toast").boundingBox();
|
|
assert.ok(rect.x >= 12 && rect.x + rect.width <= width - 12);
|
|
if (locale === "ru" && width === 1440)
|
|
await p.locator("#toast").screenshot({
|
|
path: `references/navigation-feedback/toast-${type}-${theme}.png`,
|
|
});
|
|
await p.locator("[data-toast-dismiss]").click();
|
|
assert.equal(await p.locator("#toast").isVisible(), false);
|
|
passed++;
|
|
}
|
|
if (locale === "ru")
|
|
await p
|
|
.locator(".choice-pill")
|
|
.first()
|
|
.locator("..")
|
|
.screenshot({
|
|
path: `references/navigation-feedback/choices-${theme}-${width}.png`,
|
|
});
|
|
}
|
|
await p.setViewportSize({ width: 1440, height: 900 });
|
|
await p.goto(base + "/?page=components&theme=dark");
|
|
await p.locator("[data-action=create-key]").click();
|
|
await p.locator("#copy-key").click();
|
|
await p.locator("#toast:popover-open").waitFor();
|
|
assert.equal(
|
|
await p
|
|
.locator("#toast")
|
|
.evaluate((e) => Boolean(e.closest("dialog[open]"))),
|
|
true,
|
|
);
|
|
await p.locator("[data-toast-dismiss]").click();
|
|
assert.equal(await p.locator("#dialog").evaluate((e) => e.open), true);
|
|
assert.equal(await p.locator("#toast").isVisible(), false);
|
|
assert.equal(await p.evaluate(() => document.activeElement?.id), "copy-key");
|
|
await p.keyboard.press("Escape");
|
|
passed++;
|
|
await p.evaluate(async () => {
|
|
const { createNotifier } = await import("/components/toast.js");
|
|
const node = document.createElement("div");
|
|
node.id = "timer-toast";
|
|
document.body.append(node);
|
|
window.notifyFixture = createNotifier(node, { t: (ru, en) => en });
|
|
});
|
|
await p.evaluate(() =>
|
|
window.notifyFixture("Pause timer test", { duration: 500 }),
|
|
);
|
|
await p.locator("#timer-toast").hover();
|
|
await p.waitForTimeout(650);
|
|
assert.equal(await p.locator("#timer-toast").isVisible(), true);
|
|
await p.mouse.move(10, 10);
|
|
await p.waitForTimeout(600);
|
|
assert.equal(await p.locator("#timer-toast").isVisible(), false);
|
|
passed++;
|
|
await p.evaluate(() =>
|
|
window.notifyFixture("<img src=x onerror=alert(1)>", { type: "error" }),
|
|
);
|
|
await p.waitForTimeout(5200);
|
|
assert.equal(await p.locator("#timer-toast").isVisible(), true);
|
|
assert.equal(await p.locator("#timer-toast img").count(), 0);
|
|
await p.locator("#timer-toast [data-toast-dismiss]").click();
|
|
passed++;
|
|
await p.evaluate(() =>
|
|
window.notifyFixture("Unknown type fallback", {
|
|
type: "constructor",
|
|
duration: 0,
|
|
}),
|
|
);
|
|
assert.equal(
|
|
await p.locator("#timer-toast").getAttribute("data-type"),
|
|
"info",
|
|
);
|
|
await p.evaluate(() => window.notifyFixture.dismiss());
|
|
passed++;
|
|
await p.emulateMedia({ reducedMotion: "reduce" });
|
|
await p.evaluate(() =>
|
|
window.notifyFixture("Reduced motion", { type: "info" }),
|
|
);
|
|
assert.equal(
|
|
await p
|
|
.locator("#timer-toast")
|
|
.evaluate((e) => getComputedStyle(e).animationName),
|
|
"none",
|
|
);
|
|
await p.evaluate(() => window.notifyFixture.dismiss());
|
|
passed++;
|
|
await p.goto(base + "/?page=ssh&theme=dark");
|
|
await p.locator(".xterm-rows").waitFor();
|
|
await p.locator(".dock-brand").click();
|
|
await p.waitForTimeout(300);
|
|
assert.equal(
|
|
await p.locator(".nav-group-toggle").getAttribute("aria-expanded"),
|
|
"true",
|
|
);
|
|
await p.keyboard.press("Escape");
|
|
passed++;
|
|
await p.setViewportSize({ width: 390, height: 600 });
|
|
await p.goto(base + "/?page=logs");
|
|
await p.locator(".dock-brand").click();
|
|
await p.waitForTimeout(300);
|
|
const nav = p.locator(".nav-links");
|
|
await nav.evaluate((e) => (e.scrollTop = e.scrollHeight));
|
|
assert.equal(await p.locator(".dock-account").isVisible(), true);
|
|
const account = await p.locator(".dock-account").boundingBox();
|
|
assert.ok(account.y + account.height <= 600);
|
|
passed++;
|
|
assert.deepEqual(errors, []);
|
|
await writeFile(
|
|
"references/navigation-feedback/qa.json",
|
|
JSON.stringify(
|
|
{
|
|
passed,
|
|
errors,
|
|
checks:
|
|
"Submenu hierarchy/routes/active section/keys/inert/short viewport; readonly and no landmark outline; control spacing/heights; choice pill centering and behavior; four toast variants/roles/layout; modal close hit testing; paused timers/persistent errors/text safety/reduced motion",
|
|
},
|
|
null,
|
|
2,
|
|
) + "\n",
|
|
);
|
|
console.log(
|
|
`Navigation and feedback: ${passed} checks passed, no runtime errors`,
|
|
);
|
|
} finally {
|
|
await b.close();
|
|
}
|