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 + "/")));
|
||||
|
||||
Reference in new issue
Block a user