Keep account controls permanent and add system error pages
This commit is contained in:
1 parent
61b05abe44
commit
60b584b7c1
50 files changed
+1287
-56
No files matched your search
+173
-9
@@ -99,6 +99,11 @@ let config = structuredClone(original),
|
||||
configDelay = 0,
|
||||
failMenu = false,
|
||||
failPage = false;
|
||||
let account = JSON.parse(
|
||||
await readFile(path.join(consumer, "api/account.json"), "utf8"),
|
||||
),
|
||||
pageFailure = null,
|
||||
menuFailure = null;
|
||||
const pageDelays = {};
|
||||
const mime = {
|
||||
".html": "text/html",
|
||||
@@ -111,7 +116,24 @@ const server = http.createServer(async (req, res) => {
|
||||
try {
|
||||
const url = new URL(req.url, "http://localhost"),
|
||||
pathname = decodeURIComponent(url.pathname);
|
||||
if (pathname === "/api/account.json") {
|
||||
res.writeHead(200, { "Content-Type": "application/json" });
|
||||
res.end(JSON.stringify(account));
|
||||
return;
|
||||
}
|
||||
if (pageFailure && pathname.startsWith("/api/pages/")) {
|
||||
res.writeHead(pageFailure.status, { "Content-Type": "application/json" });
|
||||
res.end(JSON.stringify(pageFailure.body));
|
||||
return;
|
||||
}
|
||||
if (pathname === "/api/navigation.json") {
|
||||
if (menuFailure) {
|
||||
res.writeHead(menuFailure.status, {
|
||||
"Content-Type": "application/json",
|
||||
});
|
||||
res.end(JSON.stringify(menuFailure.body));
|
||||
return;
|
||||
}
|
||||
const snapshot = JSON.stringify(config),
|
||||
delay = configDelay;
|
||||
if (failMenu) {
|
||||
@@ -252,6 +274,13 @@ try {
|
||||
path: "references/integration/dynamic-menu-dark.png",
|
||||
});
|
||||
await page.keyboard.press("Tab");
|
||||
assert.equal(
|
||||
await page
|
||||
.locator(".dock-account")
|
||||
.evaluate((e) => e === document.activeElement),
|
||||
true,
|
||||
);
|
||||
await page.keyboard.press("Tab");
|
||||
assert.equal(
|
||||
await page
|
||||
.locator(".dock-brand")
|
||||
@@ -259,6 +288,13 @@ try {
|
||||
true,
|
||||
);
|
||||
await page.keyboard.press("Shift+Tab");
|
||||
assert.equal(
|
||||
await page
|
||||
.locator(".dock-account")
|
||||
.evaluate((e) => e === document.activeElement),
|
||||
true,
|
||||
);
|
||||
await page.keyboard.press("Shift+Tab");
|
||||
assert.equal(
|
||||
await page.evaluate(() => document.activeElement?.dataset.navId),
|
||||
"logs",
|
||||
@@ -304,10 +340,7 @@ try {
|
||||
await page.locator("#refresh-navigation").click();
|
||||
await page.locator('[data-nav-id="injected"]').waitFor();
|
||||
assert.equal(await page.locator(".navigation img").count(), 0);
|
||||
await page
|
||||
.locator("#page-title")
|
||||
.filter({ hasText: "Раздел недоступен" })
|
||||
.waitFor();
|
||||
await page.locator('[data-error-status="404"]').waitFor();
|
||||
passed++;
|
||||
config = { items: [{ id: "bad", label: "Bad", icon: "unknown" }] };
|
||||
await page.locator("#refresh-navigation").click();
|
||||
@@ -334,10 +367,7 @@ try {
|
||||
await page.locator(".dock-brand").click();
|
||||
await page.locator('[data-nav-id="projects"]').click();
|
||||
await page.keyboard.press("Escape");
|
||||
await page
|
||||
.locator("#page-title")
|
||||
.filter({ hasText: "Раздел недоступен" })
|
||||
.waitFor();
|
||||
await page.locator('[data-error-status="503"]').waitFor();
|
||||
failPage = false;
|
||||
await page.getByRole("button", { name: "Повторить", exact: true }).click();
|
||||
await page.locator("#page-title").filter({ hasText: "Проекты" }).waitFor();
|
||||
@@ -358,9 +388,131 @@ try {
|
||||
assert.equal(await page.locator("#page-title").innerText(), "Логи");
|
||||
pageDelays["/api/pages/overview.json"] = 0;
|
||||
passed++;
|
||||
// Fixed account routes survive an empty service menu and reloads.
|
||||
config = { items: [] };
|
||||
await page.locator("#refresh-navigation").click();
|
||||
await page
|
||||
.locator("#page-title")
|
||||
.filter({ hasText: "Нет доступных разделов" })
|
||||
.waitFor();
|
||||
await page.locator(".dock-brand").click();
|
||||
await page.locator(".dock-account").click();
|
||||
await page.locator('[data-account-page="account"]').click();
|
||||
await page.keyboard.press("Escape");
|
||||
await page.locator("#page-title").filter({ hasText: "Аккаунт" }).waitFor();
|
||||
assert.equal(await page.locator("[data-nav-id]").count(), 0);
|
||||
await page
|
||||
.getByRole("button", { name: "Настройки аккаунта", exact: true })
|
||||
.click();
|
||||
await page.locator('input[name="account-theme"][value="light"]').check();
|
||||
assert.equal(await page.locator("body").getAttribute("data-theme"), "light");
|
||||
await page.reload();
|
||||
await page
|
||||
.locator("#page-title")
|
||||
.filter({ hasText: "Настройки аккаунта" })
|
||||
.waitFor();
|
||||
passed++;
|
||||
// Normal service clicks still render after leaving a fixed account route.
|
||||
config = structuredClone(original);
|
||||
await page.locator("#refresh-navigation").click();
|
||||
await page.locator('[data-nav-id="projects"]').waitFor();
|
||||
assert.equal(
|
||||
new URL(page.url()).searchParams.get("page"),
|
||||
"account-settings",
|
||||
);
|
||||
await page.locator(".dock-brand").click();
|
||||
await page.locator('[data-nav-id="projects"]').click();
|
||||
await page.keyboard.press("Escape");
|
||||
await page.locator("#page-title").filter({ hasText: "Проекты" }).waitFor();
|
||||
passed++;
|
||||
// Live ban: plain 403 is distinct from ACCOUNT_BANNED and never leaks HTML.
|
||||
pageFailure = { status: 403, body: { error: { code: "FORBIDDEN" } } };
|
||||
await page.locator(".dock-brand").click();
|
||||
await page.locator('[data-nav-id="overview"]').click();
|
||||
await page.keyboard.press("Escape");
|
||||
await page.locator('[data-error-status="403"]').waitFor();
|
||||
assert.equal(await page.locator(".error-page-reason").count(), 0);
|
||||
passed++;
|
||||
pageFailure = {
|
||||
status: 403,
|
||||
body: {
|
||||
error: {
|
||||
code: "ACCOUNT_BANNED",
|
||||
reason: "<img src=x>\nПричина из API",
|
||||
requestId: "req-test",
|
||||
},
|
||||
},
|
||||
};
|
||||
await page.locator(".dock-brand").click();
|
||||
await page.locator('[data-nav-id="projects"]').click();
|
||||
await page.keyboard.press("Escape");
|
||||
await page.locator('[data-error-status="banned"]').waitFor();
|
||||
assert.equal(await page.locator(".error-page-reason img").count(), 0);
|
||||
assert.equal(
|
||||
await page.locator(".error-page-reason p").innerText(),
|
||||
"<img src=x>\nПричина из API",
|
||||
);
|
||||
assert.equal(await page.locator("[data-nav-id]").count(), 0);
|
||||
assert.equal(await page.locator(".integration-form").isVisible(), false);
|
||||
await page.locator('[data-error-action="account"]').click();
|
||||
await page.locator("#page-title").filter({ hasText: "Аккаунт" }).waitFor();
|
||||
passed++;
|
||||
// Server reports a ban at bootstrap; account/settings remain reachable.
|
||||
pageFailure = null;
|
||||
account = {
|
||||
...account,
|
||||
status: "banned",
|
||||
banReason: "Блокировка на сервере",
|
||||
};
|
||||
await page.goto(origin + "/?page=logs");
|
||||
await page.locator('[data-error-status="banned"]').waitFor();
|
||||
assert.equal(await page.locator("[data-nav-id]").count(), 0);
|
||||
await page.locator('[data-error-action="account"]').click();
|
||||
await page
|
||||
.getByRole("button", { name: "Настройки аккаунта", exact: true })
|
||||
.click();
|
||||
await page
|
||||
.locator("#page-title")
|
||||
.filter({ hasText: "Настройки аккаунта" })
|
||||
.waitFor();
|
||||
passed++;
|
||||
account = { ...account, status: "active", banReason: null };
|
||||
await page.goto(origin + "/?page=missing-page");
|
||||
await page.locator('[data-error-status="404"]').waitFor();
|
||||
await page.locator('[data-error-action="home"]').click();
|
||||
await page.locator("#page-title").filter({ hasText: "Обзор" }).waitFor();
|
||||
passed++;
|
||||
config = { items: [] };
|
||||
await page.goto(origin + "/?page=logs");
|
||||
await page.locator('[data-error-status="403"]').waitFor();
|
||||
passed++;
|
||||
config = structuredClone(original);
|
||||
await page.goto(origin + "/?page=overview");
|
||||
await page.locator("#page-title").filter({ hasText: "Обзор" }).waitFor();
|
||||
menuFailure = { status: 401, body: { error: { code: "UNAUTHENTICATED" } } };
|
||||
await page.locator("#refresh-navigation").click();
|
||||
await page.locator('[data-error-status="401"]').waitFor();
|
||||
assert.equal(await page.locator("[data-nav-id]").count(), 0);
|
||||
assert.equal(await page.locator(".resource-row").count(), 0);
|
||||
passed++;
|
||||
menuFailure = {
|
||||
status: 403,
|
||||
body: { error: { code: "ACCOUNT_BANNED", reason: "Изменение доступа" } },
|
||||
};
|
||||
await page.locator("#refresh-navigation").click();
|
||||
await page.locator('[data-error-status="banned"]').waitFor();
|
||||
await page.locator('[data-error-action="account"]').click();
|
||||
await page.locator("#page-title").filter({ hasText: "Аккаунт" }).waitFor();
|
||||
passed++;
|
||||
menuFailure = null;
|
||||
// Core modules also work independently of the starter's host logic.
|
||||
await page.goto(origin + "/?page=error-502");
|
||||
await page.locator('[data-error-status="502"]').waitFor();
|
||||
assert.equal(await page.locator(".error-page-code").innerText(), "502");
|
||||
assert.equal(await page.locator(".integration-form").isVisible(), false);
|
||||
passed++;
|
||||
await page.evaluate(async () => {
|
||||
const { createNotifier, mountCopyField } =
|
||||
const { createNotifier, mountCopyField, mountAccountMenu } =
|
||||
await import("/anidev/runtime/index.js");
|
||||
const toast = document.createElement("div");
|
||||
document.body.append(toast);
|
||||
@@ -389,6 +541,18 @@ try {
|
||||
cleanup();
|
||||
root.remove();
|
||||
toast.remove();
|
||||
const accountRoot = document.createElement("div");
|
||||
document.body.append(accountRoot);
|
||||
const menu = mountAccountMenu(accountRoot, { onNavigate: () => {} }),
|
||||
trigger = accountRoot.querySelector(".dock-account");
|
||||
trigger.click();
|
||||
if (!accountRoot.querySelector(".account-menu").matches(":popover-open"))
|
||||
throw Error("Account menu did not open");
|
||||
menu.dispose();
|
||||
trigger.click();
|
||||
if (accountRoot.querySelector(".account-menu").matches(":popover-open"))
|
||||
throw Error("Account menu survived dispose");
|
||||
accountRoot.remove();
|
||||
});
|
||||
passed++;
|
||||
assert.ok(requests.every((url) => url.startsWith(origin + "/")));
|
||||
|
||||
@@ -0,0 +1,135 @@
|
||||
import { chromium } from "playwright";
|
||||
import assert from "node:assert/strict";
|
||||
import { mkdir, writeFile } from "node:fs/promises";
|
||||
import { errorStatuses } from "../components/error-page.js";
|
||||
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();
|
||||
const errors = [];
|
||||
page.on("pageerror", (error) => errors.push(error.message));
|
||||
await mkdir("references/system-pages", { recursive: true });
|
||||
let passed = 0;
|
||||
try {
|
||||
for (const theme of ["light", "dark"])
|
||||
for (const locale of ["ru", "en"])
|
||||
for (const width of [1440, 768, 390]) {
|
||||
await page.setViewportSize({ width, height: 900 });
|
||||
await page.goto(
|
||||
`${base}/?page=errors&status=404&theme=${theme}&locale=${locale}`,
|
||||
);
|
||||
for (const status of errorStatuses) {
|
||||
await page
|
||||
.locator("#error-preview-status")
|
||||
.selectOption(String(status));
|
||||
const card = page.locator(`[data-error-status="${status}"]`);
|
||||
await card.waitFor();
|
||||
assert.equal(await page.locator("#content h1").count(), 1);
|
||||
assert.ok(await card.locator("h1").innerText());
|
||||
if (typeof status === "number")
|
||||
assert.equal(
|
||||
await card.locator(".error-page-code").innerText(),
|
||||
String(status),
|
||||
);
|
||||
if (status === "banned")
|
||||
assert.ok(await card.locator(".error-page-reason p").innerText());
|
||||
assert.equal(
|
||||
await page.evaluate(
|
||||
() => document.documentElement.scrollWidth <= innerWidth,
|
||||
),
|
||||
true,
|
||||
);
|
||||
const rect = await card.boundingBox();
|
||||
assert.ok(rect.x >= 0 && rect.x + rect.width <= width);
|
||||
if (
|
||||
locale === "ru" &&
|
||||
width !== 768 &&
|
||||
[404, 500, 502, "banned"].includes(status)
|
||||
)
|
||||
await card.screenshot({
|
||||
path: `references/system-pages/${status}-${theme}-${width}.png`,
|
||||
});
|
||||
passed++;
|
||||
}
|
||||
}
|
||||
await page.goto(`${base}/?page=errors&status=599&locale=ru`);
|
||||
await page.locator('[data-error-status="500"]').waitFor();
|
||||
await page.getByRole("button", { name: "Повторить", exact: true }).click();
|
||||
await page.locator("#toast:popover-open").waitFor();
|
||||
await page.locator("[data-toast-dismiss]").click();
|
||||
await page
|
||||
.getByRole("button", { name: "К доступным разделам", exact: true })
|
||||
.click();
|
||||
await page
|
||||
.getByRole("button", { name: "Страницы ошибок", exact: true })
|
||||
.click();
|
||||
await page.locator("#error-preview-status").waitFor();
|
||||
passed++;
|
||||
await page.evaluate(async () => {
|
||||
const { errorPageMarkup, mountErrorPage } =
|
||||
await import("/components/error-page.js");
|
||||
const root = document.createElement("div");
|
||||
const numeric = document.createElement("div");
|
||||
numeric.innerHTML = errorPageMarkup({ status: "502", id: "numeric-code" });
|
||||
if (numeric.querySelector(".error-page-code").textContent !== "502")
|
||||
throw Error("Numeric string status lost");
|
||||
root.innerHTML = errorPageMarkup({
|
||||
id: "safety-example",
|
||||
status: "banned",
|
||||
reason: "<img src=x onerror=alert(1)>\nПричина из API",
|
||||
requestId: "<script>bad</script>",
|
||||
});
|
||||
document.body.append(root);
|
||||
if (root.querySelector("img,script"))
|
||||
throw Error("Error page did not escape server strings");
|
||||
if (
|
||||
!root.querySelector(".error-page-reason p").textContent.includes("<img")
|
||||
)
|
||||
throw Error("Reason text lost");
|
||||
let clicked = 0;
|
||||
const cleanup = mountErrorPage(root, { onAccount: () => clicked++ });
|
||||
root.querySelector("button").click();
|
||||
cleanup();
|
||||
root.querySelector("button").click();
|
||||
if (clicked !== 1) throw Error("Error page handlers survived cleanup");
|
||||
root.remove();
|
||||
const missing = document.createElement("div");
|
||||
missing.innerHTML = errorPageMarkup({
|
||||
id: "missing-reason",
|
||||
status: "banned",
|
||||
});
|
||||
if (
|
||||
!missing
|
||||
.querySelector(".error-page-reason")
|
||||
.textContent.includes("Причина не указана")
|
||||
)
|
||||
throw Error("Missing reason fallback");
|
||||
});
|
||||
passed++;
|
||||
await page.emulateMedia({ reducedMotion: "reduce" });
|
||||
await page.goto(`${base}/?page=errors&status=banned&theme=dark&locale=ru`);
|
||||
await page.locator('[data-error-action="account"]').click();
|
||||
assert.equal(new URL(page.url()).searchParams.get("page"), "profile");
|
||||
passed++;
|
||||
assert.deepEqual(errors, []);
|
||||
await writeFile(
|
||||
"references/system-pages/qa.json",
|
||||
JSON.stringify(
|
||||
{
|
||||
passed,
|
||||
errors,
|
||||
checks:
|
||||
"All status pages in both themes/RU/EN/three widths; preview actions/fallback; escaped reason/reference, missing reason, cleanup, account access",
|
||||
},
|
||||
null,
|
||||
2,
|
||||
) + "\n",
|
||||
);
|
||||
console.log(`System pages: ${passed} checks passed, no runtime errors`);
|
||||
} finally {
|
||||
await browser.close();
|
||||
}
|
||||
Reference in new issue
Block a user