Files
allmende/web/test/owner.test.ts
T
nilsandClaude Sonnet 5.5 fd439710df Let the owner change regions by place name, without a restart
The p2p node can now add and drop regions while running (SetRegions):
topics, validators, subscriptions and per-region peer discovery start and
stop with them, and a newly followed region catches up by sync.

PUT /api/v1/regions (owner token) applies a change and the node saves it in
regions.json, which wins over --region from then on. The owner's browser
gets a "Regions" page: search a place by name (GeoNames cities, offline,
CC BY 4.0), follow its cell plus any cell within about 40 km.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AeFqV96dVeBX94inzcgZKw
2026-11-18 10:28:16 +01:00

440 lines
23 KiB
TypeScript

import assert from "node:assert/strict";
import { afterEach, beforeEach, test } from "node:test";
import type { Address, Mine, OwnerMessage, Thread } from "../src/ownerApi.ts";
import { NOW, openPage, startGateway, type Gateway, type Page } from "./helpers.ts";
const TOKEN = "ab12".repeat(16);
const L1 = "11".repeat(16);
const L2 = "22".repeat(16);
const T_NEW = "a".repeat(60) + "a3f9"; // needs a reply
const T_LINK = "b".repeat(60) + "5b10"; // hid a link
const T_GRANT = "c".repeat(60) + "e204"; // address released
const XSS = `<img src=x onerror="window.__pwned=1"> noch frei?`;
/** A stand-in for the owner's node: state, and a record of what the page asked. */
function fakeNode() {
const s = {
token: TOKEN,
calls: [] as { method: string; path: string; body: string; auth: string }[],
address: { address: "Musterweg 7, 22765 Hamburg", phone: "+49 40 1" } as Address | null,
mine: [
{ id: L1, title: "Helle Wohnung", kind: "rent", price: { amount_cents: 115000, currency: "EUR", period: "month" }, expires_at: NOW + 86400 * 30, threads: 3, needs_reply: 1, hidden: 1, address_saved: true },
{ id: L2, title: "Gewerbefläche", kind: "rent", expires_at: NOW + 86400 * 30, threads: 0, needs_reply: 0, hidden: 0, address_saved: false },
] as Mine[],
threads: [
{ listing: L1, thread: T_NEW, messages: 1, hidden: 0, replied: false, first_at: NOW - 600, last_at: NOW - 600, last_dir: "in", needs_reply: true, preview: XSS, effort: 19 },
{ listing: L1, thread: T_LINK, messages: 1, hidden: 1, replied: false, first_at: NOW - 90000, last_at: NOW - 90000, last_dir: "in", needs_reply: false, effort: 15 },
{ listing: L1, thread: T_GRANT, messages: 3, hidden: 0, replied: true, first_at: NOW - 90000, last_at: NOW - 80000, last_dir: "out", needs_reply: false, effort: 17, grant_until: NOW + 86400 },
] as Thread[],
msgs: {
[T_NEW]: [{ hash: "h1", dir: "in", received_at: NOW - 600, type: "text", n: 1, sent_at: NOW - 600, text: XSS }],
[T_LINK]: [{ hash: "h2", dir: "in", hidden: true, reason: "x", received_at: NOW, type: "text", n: 1, sent_at: NOW - 90000 }],
[T_GRANT]: [
{ hash: "h3", dir: "in", received_at: NOW, type: "text", n: 1, sent_at: NOW - 90000, text: "Guten Tag" },
{ hash: "h4", dir: "out", received_at: NOW, type: "grant", n: 1, sent_at: NOW - 80000, address: "Musterweg 7, 22765 Hamburg", note: "Klingel: Meyer", valid_until: NOW + 86400 },
],
} as Record<string, OwnerMessage[]>,
};
const handler: NonNullable<Gateway["owner"]> = (r) => {
s.calls.push({ method: r.method, path: r.path + (r.query.size ? "?" + r.query : ""), body: r.body, auth: r.auth });
if (r.auth !== `Bearer ${s.token}`) return { status: 401, body: { error: "unauthorized" } };
if (r.path === "/api/v1/mine") return { status: 200, body: s.mine };
if (r.path === "/api/v1/regions" && r.method === "PUT") {
const { regions } = JSON.parse(r.body) as { regions: string[] };
if (regions.includes("zzz")) return { status: 400, body: { error: `"zzz" is not a region: use 3 geohash characters` } };
return { status: 200, body: { regions } };
}
if (r.path === "/api/v1/inbox") return { status: 200, body: s.threads.filter((t) => t.listing === r.query.get("listing")) };
const th = /^\/api\/v1\/inbox\/([0-9a-f]{32})\/([0-9a-f]{64})$/.exec(r.path);
if (th) {
const msgs = s.msgs[th[2]!];
if (!msgs) return { status: 404, body: { error: "no such conversation" } };
if (r.method === "POST") return { status: 200, body: { hash: "x" } };
if (r.method === "DELETE") return { status: 204 };
return { status: 200, body: msgs };
}
if (/\/address$/.test(r.path)) {
if (r.method === "PUT") { s.address = JSON.parse(r.body) as Address; return { status: 204 }; }
if (r.method === "DELETE") { s.address = null; return { status: 204 }; }
return s.address ? { status: 200, body: s.address } : { status: 404, body: { error: "no address saved for this listing" } };
}
return undefined;
};
return { s, handler };
}
let gw: Gateway;
let node: ReturnType<typeof fakeNode>;
let page: Page | undefined;
beforeEach(async () => {
gw = await startGateway({ listings: [] });
node = fakeNode();
gw.owner = node.handler;
});
afterEach(async () => {
page?.close();
page = undefined;
await gw.close();
});
const open = (hash: string) => (page = openPage(gw.url, hash));
const text = () => page!.document.body.textContent ?? "";
const q = <T extends Element = HTMLElement>(sel: string) => page!.document.querySelector<T>(sel);
const qa = (sel: string) => [...page!.document.querySelectorAll(sel)];
const button = (label: string) => qa("button").find((b) => b.textContent === label) as HTMLButtonElement | undefined;
const submit = (form: Element) => form.dispatchEvent(new page!.window.Event("submit", { cancelable: true }));
const posts = () => node.s.calls.filter((c) => c.method === "POST");
test("without a token the page asks for one, and a wrong token is refused", async () => {
open("#/mine");
await page!.waitFor(() => q('input[name="token"]') !== null, "the sign-in form");
assert.equal(node.s.calls.length, 0, "nothing is requested before signing in");
assert.equal(q("nav a[href='#/mine']"), null, "the owner link is hidden until signed in");
q<HTMLInputElement>('input[name="token"]')!.value = "not-the-token";
submit(q("form")!);
await page!.waitFor(() => /rejected the token/.test(text()), "a rejection notice");
assert.equal(page!.window.sessionStorage.getItem("allmende.owner.token"), null, "a refused token is forgotten");
q<HTMLInputElement>('input[name="token"]')!.value = TOKEN;
submit(q("form")!);
await page!.waitFor(() => qa(".pane-listings .ocard").length === 2, "the listings");
assert.ok(node.s.calls.every((c) => c.auth === "Bearer not-the-token" || c.auth === `Bearer ${TOKEN}`));
});
test("the login link signs in and disappears from the address bar", async () => {
open(`#/login/${TOKEN}`);
await page!.waitFor(() => qa(".pane-listings .ocard").length === 2, "the listings");
assert.equal(page!.window.location.hash, "#/mine", "the token is not left in the URL");
assert.equal(page!.window.sessionStorage.getItem("allmende.owner.token"), TOKEN);
assert.equal(page!.window.localStorage.getItem("allmende.owner.token"), null, "never in localStorage");
assert.ok(q("nav a[href='#/mine']"), "the owner link appears");
assert.ok(node.s.calls.every((c) => c.auth === `Bearer ${TOKEN}`));
const [first, second] = qa(".pane-listings .ocard");
assert.match(first!.textContent!, /Helle Wohnung/);
assert.match(first!.textContent!, /1 need a reply/);
assert.match(first!.textContent!, /Address saved/);
assert.match(first!.textContent!, /1,150\.00/);
assert.match(second!.textContent!, /No requests/);
assert.match(second!.textContent!, /No address saved/);
});
test("a listing's requests show status, preview and effort, and can be filtered", async () => {
open(`#/login/${TOKEN}`);
await page!.waitFor(() => qa(".pane-listings .ocard").length === 2, "the listings");
page!.window.location.hash = `#/mine/${L1}`;
await page!.waitFor(() => qa(".pane-requests .olist .ocard").length === 3, "three requests");
const rows = qa(".pane-requests .olist .ocard");
const [neu, link, grant] = rows.map((r) => r.textContent!);
assert.match(neu!, /#a3f9/);
assert.match(neu!, /Needs reply/);
assert.match(neu!, /Effort 19 bit/);
assert.match(link!, /#5b10/);
assert.match(link!, /Link hidden/);
assert.match(link!, /Hidden: contains a link/);
assert.match(grant!, /#e204/);
assert.match(grant!, /Address until/);
assert.match(text(), /Musterweg 7, 22765 Hamburg/, "the saved address is shown");
button("Needs reply 1")!.click();
assert.equal(qa(".pane-requests .olist .ocard").length, 1);
button("Link hidden 1")!.click();
assert.equal(qa(".pane-requests .olist .ocard").length, 1);
assert.match(qa(".pane-requests .olist .ocard")[0]!.textContent!, /#5b10/);
button("All 3")!.click();
assert.equal(qa(".pane-requests .olist .ocard").length, 3);
assert.equal(button("All 3")!.getAttribute("aria-pressed"), "true");
});
test("buyer text is shown as text only, and the first-message note disappears once you replied", async () => {
open(`#/login/${TOKEN}`);
await page!.waitFor(() => qa(".pane-listings .ocard").length === 2, "the listings");
page!.window.location.hash = `#/mine/${L1}/${T_NEW}`;
await page!.waitFor(() => qa(".pane-thread .msg").length === 1, "the conversation");
assert.equal(q(".pane-thread .msg img"), null, "no element is created from buyer text");
assert.equal((page!.window as unknown as { __pwned?: number }).__pwned, undefined);
assert.ok(q(".pane-thread .msg .pre")!.textContent!.includes("<img src=x"), "the markup is visible as text");
assert.equal(q<HTMLElement>(".pane-thread .note")!.hidden, false, "first message: the rules are explained");
assert.match(text(), /Request #a3f9/);
// An answered conversation does not show that note.
page!.window.location.hash = `#/mine/${L1}/${T_GRANT}`;
await page!.waitFor(() => qa(".pane-thread .msg").length === 2, "the second conversation");
assert.equal(q<HTMLElement>(".pane-thread .note")!.hidden, true);
assert.match(q(".pane-thread .grant")!.textContent!, /Address released until/);
assert.match(q(".pane-thread .grant")!.textContent!, /Klingel: Meyer/);
// A hidden message never shows its text, only why.
page!.window.location.hash = `#/mine/${L1}/${T_LINK}`;
await page!.waitFor(() => /Hidden: a first message must be short/.test(text()), "hidden explanation");
});
test("a reply is sent as text and the box is cleared", async () => {
open(`#/login/${TOKEN}`);
await page!.waitFor(() => qa(".pane-listings .ocard").length === 2, "the listings");
page!.window.location.hash = `#/mine/${L1}/${T_NEW}`;
await page!.waitFor(() => qa(".pane-thread .msg").length === 1, "the conversation");
const area = q<HTMLTextAreaElement>(".pane-thread textarea")!;
area.value = "Ja, noch frei. Besichtigung am Samstag?";
submit(q(".pane-thread form.compose")!);
await page!.waitFor(() => posts().length === 1, "the reply");
assert.equal(posts()[0]!.path, `/api/v1/inbox/${L1}/${T_NEW}`);
assert.deepEqual(JSON.parse(posts()[0]!.body), { type: "text", text: "Ja, noch frei. Besichtigung am Samstag?" });
await page!.waitFor(() => area.value === "", "the box to clear");
// Empty text is not sent.
submit(q(".pane-thread form.compose")!);
await new Promise((r) => setTimeout(r, 50));
assert.equal(posts().length, 1);
});
test("Ctrl+Enter sends a reply; plain Enter only adds a line", async () => {
open(`#/login/${TOKEN}`);
await page!.waitFor(() => qa(".pane-listings .ocard").length === 2, "the listings");
page!.window.location.hash = `#/mine/${L1}/${T_NEW}`;
await page!.waitFor(() => qa(".pane-thread .msg").length === 1, "the conversation");
const area = q<HTMLTextAreaElement>(".pane-thread textarea")!;
const press = (init: KeyboardEventInit) => area.dispatchEvent(new page!.window.KeyboardEvent("keydown", { key: "Enter", bubbles: true, cancelable: true, ...init }));
area.value = "Hallo";
assert.equal(press({}), true, "a plain Enter is left alone, so it adds a line");
assert.equal(press({ shiftKey: true }), true);
await new Promise((r) => setTimeout(r, 50));
assert.equal(posts().length, 0, "nothing sent without Ctrl");
assert.match(area.placeholder, /Ctrl\+Enter/);
assert.equal(press({ ctrlKey: true }), false, "Ctrl+Enter is handled");
await page!.waitFor(() => posts().length === 1, "the reply");
assert.deepEqual(JSON.parse(posts()[0]!.body), { type: "text", text: "Hallo" });
await page!.waitFor(() => area.value === "", "the box to clear");
area.value = "Von einem Mac";
press({ metaKey: true });
await page!.waitFor(() => posts().length === 2, "Cmd+Enter works too");
area.value = "";
press({ ctrlKey: true });
await new Promise((r) => setTimeout(r, 50));
assert.equal(posts().length, 2, "an empty box sends nothing");
});
test("releasing the address: prefilled sheet, signed grant request, closes", async () => {
open(`#/login/${TOKEN}`);
await page!.waitFor(() => qa(".pane-listings .ocard").length === 2, "the listings");
page!.window.location.hash = `#/mine/${L1}/${T_NEW}`;
await page!.waitFor(() => qa(".pane-thread .msg").length === 1, "the conversation");
button("Release address")!.click();
await page!.waitFor(() => q('.sheet input[name="address"]') !== null, "the sheet");
await page!.waitFor(() => q<HTMLInputElement>('.sheet input[name="address"]')!.value !== "", "prefill from the saved address");
assert.equal(q<HTMLInputElement>('.sheet input[name="address"]')!.value, "Musterweg 7, 22765 Hamburg");
assert.equal(q<HTMLInputElement>('.sheet input[name="phone"]')!.value, "+49 40 1");
assert.equal(q<HTMLSelectElement>('.sheet select[name="valid"]')!.value, "7", "a week by default");
assert.equal(q<HTMLInputElement>('.sheet input[name="remember"]')!.checked, false, "already saved: not offered again");
assert.match(q(".sheet")!.textContent!, /could still have copied it/);
q<HTMLTextAreaElement>('.sheet textarea[name="note"]')!.value = "Samstag 10 Uhr, bitte zweimal klingeln";
q<HTMLSelectElement>('.sheet select[name="valid"]')!.value = "3";
submit(q(".sheet form")!);
await page!.waitFor(() => posts().length === 1, "the grant");
assert.deepEqual(JSON.parse(posts()[0]!.body), {
type: "grant",
address: "Musterweg 7, 22765 Hamburg",
phone: "+49 40 1",
note: "Samstag 10 Uhr, bitte zweimal klingeln",
valid_days: 3,
});
await page!.waitFor(() => q(".sheet") === null, "the sheet to close");
assert.equal(node.s.calls.filter((c) => c.method === "PUT").length, 0, "an unchanged address is not saved again");
});
test("releasing without a saved address offers to keep it, and refuses an empty one", async () => {
node.s.address = null;
open(`#/login/${TOKEN}`);
await page!.waitFor(() => qa(".pane-listings .ocard").length === 2, "the listings");
page!.window.location.hash = `#/mine/${L1}/${T_NEW}`;
await page!.waitFor(() => qa(".pane-thread .msg").length === 1, "the conversation");
button("Release address")!.click();
await page!.waitFor(() => q<HTMLInputElement>('.sheet input[name="remember"]')?.checked === true, "remember is on by default");
submit(q(".sheet form")!);
await page!.waitFor(() => /enter an address/.test(text()), "a refusal");
assert.equal(posts().length, 0);
q<HTMLInputElement>('.sheet input[name="address"]')!.value = "Neue Straße 3, 20095 Hamburg";
submit(q(".sheet form")!);
await page!.waitFor(() => posts().length === 1, "the grant");
const put = node.s.calls.find((c) => c.method === "PUT")!;
assert.deepEqual(JSON.parse(put.body), { address: "Neue Straße 3, 20095 Hamburg" });
assert.deepEqual(node.s.address, { address: "Neue Straße 3, 20095 Hamburg" });
assert.equal(JSON.parse(posts()[0]!.body).valid_days, 7);
});
test("the sheet closes with Escape and with the backdrop, and sends nothing", async () => {
open(`#/login/${TOKEN}`);
await page!.waitFor(() => qa(".pane-listings .ocard").length === 2, "the listings");
page!.window.location.hash = `#/mine/${L1}/${T_NEW}`;
await page!.waitFor(() => qa(".pane-thread .msg").length === 1, "the conversation");
button("Release address")!.click();
await page!.waitFor(() => q(".sheet") !== null, "the sheet");
q<HTMLElement>(".sheet input")!.dispatchEvent(new page!.window.KeyboardEvent("keydown", { key: "Escape", bubbles: true }));
assert.equal(q(".sheet"), null);
button("Release address")!.click();
await page!.waitFor(() => q(".sheet") !== null, "the sheet again");
q<HTMLElement>(".backdrop")!.dispatchEvent(new page!.window.MouseEvent("click", { bubbles: true }));
assert.equal(q(".sheet"), null);
assert.equal(posts().length, 0);
});
test("the saved address can be changed and removed", async () => {
open(`#/login/${TOKEN}`);
await page!.waitFor(() => qa(".pane-listings .ocard").length === 2, "the listings");
page!.window.location.hash = `#/mine/${L1}`;
await page!.waitFor(() => /Musterweg 7/.test(text()), "the saved address");
button("Change")!.click();
const form = q(".addr form")!;
q<HTMLInputElement>('.addr input[name="address"]')!.value = "Hafenstraße 9, 20459 Hamburg";
q<HTMLInputElement>('.addr input[name="phone"]')!.value = "";
submit(form);
await page!.waitFor(() => /Hafenstraße 9/.test(q(".addr")!.textContent!), "the new address");
assert.deepEqual(node.s.address, { address: "Hafenstraße 9, 20459 Hamburg" });
button("Change")!.click();
button("Remove")!.click();
await page!.waitFor(() => /No address saved yet/.test(text()), "the address removed");
assert.equal(node.s.address, null);
});
test("deleting a conversation asks first, then goes back to the requests", async () => {
open(`#/login/${TOKEN}`);
await page!.waitFor(() => qa(".pane-listings .ocard").length === 2, "the listings");
page!.window.location.hash = `#/mine/${L1}/${T_LINK}`;
await page!.waitFor(() => button("Delete conversation") !== undefined, "the delete button");
button("Delete conversation")!.click();
assert.equal(node.s.calls.filter((c) => c.method === "DELETE").length, 0, "nothing is deleted by one click");
button("Yes, delete")!.click();
await page!.waitFor(() => page!.window.location.hash === `#/mine/${L1}`, "back to the requests");
assert.equal(node.s.calls.filter((c) => c.method === "DELETE")[0]!.path, `/api/v1/inbox/${L1}/${T_LINK}`);
});
test("a token that stops working sends the owner back to sign in", async () => {
open(`#/login/${TOKEN}`);
await page!.waitFor(() => qa(".pane-listings .ocard").length === 2, "the listings");
page!.window.location.hash = `#/mine/${L1}/${T_NEW}`;
await page!.waitFor(() => qa(".pane-thread .msg").length === 1, "the conversation");
node.s.token = "rotated"; // e.g. after `recover`
q<HTMLTextAreaElement>(".pane-thread textarea")!.value = "Hallo";
submit(q(".pane-thread form.compose")!);
await page!.waitFor(() => /rejected the token/.test(text()), "a rejection");
assert.equal(page!.window.sessionStorage.getItem("allmende.owner.token"), null);
});
test("the sheet offers an email, prefilled from the saved address, and sends it", async () => {
node.s.address = { address: "Musterweg 7, 22765 Hamburg", phone: "+49 40 1", email: "vermietung@example.org" };
open(`#/login/${TOKEN}`);
await page!.waitFor(() => qa(".pane-listings .ocard").length === 2, "the listings");
page!.window.location.hash = `#/mine/${L1}/${T_NEW}`;
await page!.waitFor(() => qa(".pane-thread .msg").length === 1, "the conversation");
button("Release address")!.click();
await page!.waitFor(() => q<HTMLInputElement>('.sheet input[name="email"]')?.value === "vermietung@example.org", "email prefill");
submit(q(".sheet form")!);
await page!.waitFor(() => posts().length === 1, "the grant");
assert.equal(JSON.parse(posts()[0]!.body).email, "vermietung@example.org");
// Cleared, it is not sent at all.
button("Release address")!.click();
await page!.waitFor(() => q<HTMLInputElement>('.sheet input[name="email"]')?.value === "vermietung@example.org", "prefill again");
q<HTMLInputElement>('.sheet input[name="email"]')!.value = "";
submit(q(".sheet form")!);
await page!.waitFor(() => posts().length === 2, "the second grant");
assert.equal("email" in JSON.parse(posts()[1]!.body), false);
});
test("a buyer asking where the place is gets a suggestion to release the address", async () => {
const ask = async (text: string, dir: "in" | "out" = "in", hidden = false) => {
node.s.msgs[T_NEW] = [{ hash: "q", dir, hidden, received_at: NOW, type: "text", n: 1, sent_at: NOW - 60, text }];
page?.close();
open(`#/login/${TOKEN}`);
await page!.waitFor(() => qa(".pane-listings .ocard").length === 2, "the listings");
page!.window.location.hash = `#/mine/${L1}/${T_NEW}`;
await page!.waitFor(() => qa(".pane-thread .msg").length === 1, "the conversation");
return q<HTMLElement>(".pane-thread .hint")!.hidden;
};
assert.equal(await ask("Sehr gerne! Wo genau ist die Wohnung?"), false, "German question");
assert.equal(await ask("Could you send me the address please?"), false, "English request");
assert.equal(await ask("Ist die Wohnung noch frei?"), true, "an unrelated question");
assert.equal(await ask("Wo genau ist die Wohnung?", "out"), true, "only the buyer's words count");
assert.equal(await ask("Wie ist die Adresse?", "in", true), true, "a hidden message is never read");
});
test("signing out forgets the token", async () => {
open(`#/login/${TOKEN}`);
await page!.waitFor(() => qa(".pane-listings .ocard").length === 2, "the listings");
button("Sign out")!.click();
assert.equal(page!.window.sessionStorage.getItem("allmende.owner.token"), null);
await page!.waitFor(() => q("nav a[href='#/mine']") === null, "the owner link to vanish");
});
test("the owner picks regions by place name and the node follows them at once", async () => {
open(`#/login/${TOKEN}`);
await page!.waitFor(() => qa(".pane-listings .ocard").length === 2, "the listings");
qa(".pane-listings a").find((a) => a.textContent === "Regions")!.click();
await page!.waitFor(() => q('[name="place"]') !== null, "the regions page");
assert.ok(q(".rp-chips")!.textContent!.includes("u1x"), "what the node follows now");
const search = q<HTMLInputElement>('[name="place"]')!;
await page!.waitFor(() => !search.disabled, "the place list is loaded");
search.value = "köln";
search.dispatchEvent(new page!.window.Event("input", { bubbles: true }));
await page!.waitFor(() => q(".rp-result") !== null, "a result");
q(".rp-result")!.click();
await page!.waitFor(() => /Regions around/.test(text()), "the cells around it");
button("Add")!.click();
assert.ok(qa(".rp-chip").length >= 2, "the new regions are added next to the old one");
submit(q("form")!);
await page!.waitFor(() => /Saved/.test(text()), "saved");
const put = node.s.calls.find((c) => c.method === "PUT" && c.path === "/api/v1/regions")!;
assert.equal(put.auth, `Bearer ${TOKEN}`, "only the owner can change regions");
const sent = (JSON.parse(put.body) as { regions: string[] }).regions;
assert.equal(sent[0], "u1x");
assert.ok(sent.includes("u1j"), `Köln's own cell is followed: ${sent}`);
assert.ok(q("#status")!.textContent!.includes(sent.join(", ")), "the status line shows the new regions");
});
test("a region the node refuses is explained and the page stays usable", async () => {
open(`#/login/${TOKEN}`);
await page!.waitFor(() => qa(".pane-listings .ocard").length === 2, "the listings");
location_(`#/mine/regions`);
await page!.waitFor(() => q('[name="regions"]') !== null, "the regions page");
q<HTMLInputElement>('[name="regions"]')!.value = "zzz";
submit(q("form")!);
await page!.waitFor(() => /not a region/.test(text()), "the node's explanation");
assert.ok(!button("Save")?.disabled, "saving can be tried again");
});
test("without signing in the regions page leads to the sign-in", async () => {
open("#/mine/regions");
await page!.waitFor(() => q('input[name="token"]') !== null, "the sign-in form");
assert.equal(node.s.calls.length, 0);
});
/** Moves the open page to another hash, as a click on a link would. */
function location_(hash: string): void {
page!.window.location.hash = hash;
}