Public: anyone can read this; the crew can change it.
Every page has a skip link and a visible focus ring, checked by one test over all layouts #13017
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/13007-every-page-has-a-skip-link-and-a-visible → main 4 commits fork 4 threads · 4 unresolved
2 files
changed +109
−1
src/web/studio/asks_page.ts +1 −1
| @@ -451,7 +451,7 @@ function renderAsks(ctx: Ctx, top: AsksTop | undefined): Response { | ||
| 451 | 451 | const response = page({ |
| 452 | 452 | ctx, |
| 453 | 453 | title: "Asks", |
| 454 | body: html`<main class="stack"><h1 class="sr-only">Asks</h1>${muteFlash(ctx, user)}${onYouRegion(ctx, user, undefined, section.body)}<p class="small muted"><a href="/review">Review: one row per ask</a></p></main>`, | |
| 454 | body: html`<div class="stack"><h1 class="sr-only">Asks</h1>${muteFlash(ctx, user)}${onYouRegion(ctx, user, undefined, section.body)}<p class="small muted"><a href="/review">Review: one row per ask</a></p></div>`, | |
| 455 | 455 | scriptJs: `${liveClientJs}\n${liveRegionsJs}\n${section.scriptJs}`, |
| 456 | 456 | }); |
| 457 | 457 | notePhase(ctx.request, "render", performance.now() - rendering); |
test/a11y-landmarks.test.ts added +108
| @@ -0,0 +1,108 @@ | ||
| 1 | /** | |
| 2 | * Every layout has a skip link first, one main landmark it points at, and a focus ring the | |
| 3 | * served stylesheet draws (#13007). | |
| 4 | * | |
| 5 | * Left out on purpose: the static shells (the offline page, the maintenance page, the app | |
| 6 | * holding page) and the bare layout (the board wall, /board: its own header, no topbar). None | |
| 7 | * has a topbar or navigation, so a skip link would skip nothing. | |
| 8 | */ | |
| 9 | import { afterAll, beforeAll, describe, expect, test } from "bun:test"; | |
| 10 | import { mkdtemp, rm } from "node:fs/promises"; | |
| 11 | import { tmpdir } from "node:os"; | |
| 12 | import { join } from "node:path"; | |
| 13 | import { createApp, type App } from "../src/app.ts"; | |
| 14 | import { createUser } from "../src/core/users.ts"; | |
| 15 | import { serve, type Servers } from "../src/http/server.ts"; | |
| 16 | import { stylesheetAsset } from "../src/web/asset.ts"; | |
| 17 | import { quietLogs } from "./helpers/globals.ts"; | |
| 18 | ||
| 19 | quietLogs(); | |
| 20 | ||
| 21 | let dir: string; | |
| 22 | let app: App; | |
| 23 | let servers: Servers; | |
| 24 | let cookie: string; | |
| 25 | ||
| 26 | beforeAll(async () => { | |
| 27 | dir = await mkdtemp(join(tmpdir(), "forge-a11y-landmarks-")); | |
| 28 | app = createApp({ dataDir: dir, port: 0 }); | |
| 29 | servers = await serve(app); | |
| 30 | const made = await createUser(app.db, { | |
| 31 | origin: "seed", | |
| 32 | trusted: true, | |
| 33 | username: "alice", | |
| 34 | email: "[email protected]", | |
| 35 | password: "a-good-passphrase", | |
| 36 | adminIfFirst: true, | |
| 37 | }); | |
| 38 | if (!made.ok) throw new Error(made.error); | |
| 39 | const signin = await fetch(`${servers.url}/signin`, { | |
| 40 | method: "POST", | |
outdated
Silent early return: a non-HTML response passes with no assertion. Assert status and content-type instead. |
||
| 41 | body: new URLSearchParams({ username: "alice", password: "a-good-passphrase" }), | |
| 42 | redirect: "manual", | |
| 43 | }); | |
| 44 | cookie = (signin.headers.get("set-cookie") ?? "").split(";")[0]!; | |
| 45 | if (cookie === "") throw new Error("sign-in gave no session cookie"); | |
outdated
Tie the single <main> to id="main" in one match, so the two checks cannot pass on different elements. |
||
| 46 | }, 30_000); | |
| 47 | afterAll(async () => { | |
| 48 | servers.stop(); | |
| 49 | app.close(); | |
| 50 | await rm(dir, { recursive: true, force: true }); | |
| 51 | }); | |
| 52 | ||
| 53 | // Signed out: the public shell, the not-found shell (failed_page) and the sign-in forms. | |
outdated
Exact-whitespace regexes on the source stylesheet are brittle. Loosen them, or test the served CSS. |
||
| 54 | const SIGNED_OUT = ["/", "/signin", "/signup", "/explore", "/search", "/no-such-page-here"]; | |
| 55 | // Signed in (as the admin): the authenticated shell and its topbar tools. | |
| 56 | const SIGNED_IN = ["/", "/feed", "/asks", "/notes", "/talk", "/map", "/settings", "/system", "/family"]; | |
| 57 | ||
| 58 | async function layout(path: string, signedIn: boolean): Promise<string> { | |
| 59 | const res = await fetch(`${servers.url}${path}`, { | |
| 60 | headers: signedIn ? { cookie } : {}, | |
| 61 | redirect: "manual", | |
| 62 | }); | |
| 63 | // A page is HTML with a status that is a page's (the not-found shell answers 404). | |
| 64 | expect([200, 404]).toContain(res.status); | |
| 65 | expect(res.headers.get("content-type") ?? "").toContain("text/html"); | |
| 66 | return res.text(); | |
| 67 | } | |
| 68 | ||
| 69 | function expectLandmarks(text: string): void { | |
| 70 | const body = text.slice(text.indexOf("<body")); | |
| 71 | const firstLink = body.match(/<a\b[^>]*>/)?.[0] ?? ""; | |
| 72 | expect(firstLink).toMatch(/class="skip"/); | |
| 73 | expect(firstLink).toMatch(/href="#main"/); | |
| 74 | // One <main> that carries the id the skip link points at, and nothing else has that id. | |
| 75 | expect(text.match(/<main\b/g)?.length).toBe(1); | |
| 76 | expect(text.match(/<main\b[^>]*\bid="main"/g)?.length).toBe(1); | |
| 77 | expect(text.match(/\bid="main"/g)?.length).toBe(1); | |
| 78 | } | |
| 79 | ||
| 80 | describe("every layout", () => { | |
| 81 | for (const path of SIGNED_OUT) { | |
| 82 | test(`signed out, ${path} opens with a skip link to its one main landmark`, async () => { | |
| 83 | expectLandmarks(await layout(path, false)); | |
| 84 | }); | |
| 85 | } | |
| 86 | for (const path of SIGNED_IN) { | |
| 87 | test(`signed in, ${path} opens with a skip link to its one main landmark`, async () => { | |
| 88 | expectLandmarks(await layout(path, true)); | |
| 89 | }); | |
| 90 | } | |
| 91 | }); | |
| 92 | ||
| 93 | describe("the served stylesheet", () => { | |
| 94 | let css: string; | |
| 95 | beforeAll(async () => { | |
| 96 | const res = await fetch(`${servers.url}${stylesheetAsset().path}`); | |
| 97 | expect(res.status).toBe(200); | |
| 98 | expect(res.headers.get("content-type") ?? "").toContain("text/css"); | |
| 99 | css = (await res.text()).replace(/\s+/g, " "); | |
| 100 | }); | |
| 101 | test("draws a focus ring on every control", () => { | |
| 102 | expect(css).toMatch(/(^|[}\s]):focus-visible\s*\{\s*outline:\s*2px solid var\(--accent\)/); | |
| 103 | }); | |
| 104 | test("keeps the skip link off-screen until focused, without moving layout", () => { | |
| 105 | expect(css).toMatch(/\.skip\s*\{[^}]*position:\s*absolute[^}]*top:\s*-\d+px/); | |
| 106 | expect(css).toMatch(/\.skip:focus-visible\s*\{\s*top:\s*\d+px/); | |
| 107 | }); | |
| 108 | }); |
new above
offline
Only signed-out shells are listed. Add the signed-in layout paths, or the claim 'every layout' is false.