From 8b713ed44d02ab3e002b147cd4e77a34d5ca7cb8 Mon Sep 17 00:00:00 2001 From: Matthias Endler Date: Fri, 13 Nov 2026 23:27:12 +0100 Subject: [PATCH] Keep chapter navigation reachable at intermediate widths --- README.md | 7 ++- scripts/check-admin-browser.mjs | 85 +++++++++++++++++++++++++++++++-- static/css/base.css | 30 +++++++----- templates/base.html | 2 + 4 files changed, 107 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index df9c656..22428b8 100644 --- a/README.md +++ b/README.md @@ -153,8 +153,11 @@ SIGINT/SIGTERM; the whole run has a two-minute deadline. Coverage includes special characters in the admin token, real HTMX filter/sort requests and focus preservation, Move submissions and redirects, and admin back links. Team-page checks at 320, 390, and 1440px cover overflow, a named and -focusable roster, keyboard scrolling, and access to row controls. These are -focused regression checks, not a full accessibility audit. The Rust CI job runs +focusable roster, keyboard scrolling, and access to row controls. Participant +chapter checks cover navigation, keyboard access, the chapter picker, and sticky +editor controls from 320 to 1440px, including a long chapter title. Add +`--screenshot-dir=target/navigation-screenshots` to capture those layouts. +These are focused regression checks, not a full accessibility audit. The Rust CI job runs the same command after building and testing, using the runner's installed Chrome. `npm test` runs the separate JavaScript unit tests. diff --git a/scripts/check-admin-browser.mjs b/scripts/check-admin-browser.mjs index 7904478..e720838 100644 --- a/scripts/check-admin-browser.mjs +++ b/scripts/check-admin-browser.mjs @@ -3,7 +3,7 @@ import assert from "node:assert/strict"; import { spawn } from "node:child_process"; import { constants } from "node:fs"; -import { access, mkdtemp, readFile, rm, symlink, writeFile } from "node:fs/promises"; +import { access, mkdir, mkdtemp, readFile, rm, symlink, writeFile } from "node:fs/promises"; import { createServer } from "node:net"; import { tmpdir } from "node:os"; import { delimiter, join, resolve } from "node:path"; @@ -11,7 +11,10 @@ import { DatabaseSync } from "node:sqlite"; import { fileURLToPath } from "node:url"; import { parseArgs } from "node:util"; -const { values } = parseArgs({ options: { chrome: { type: "string" } } }); +const { values } = parseArgs({ options: { + chrome: { type: "string" }, + "screenshot-dir": { type: "string" }, +} }); const root = fileURLToPath(new URL("../", import.meta.url)); const token = "browser-only&plus+question?hash#percent%"; const query = new URLSearchParams({ token }); @@ -351,11 +354,87 @@ try { assert.equal(await js("document.querySelector('.admin-cell-name').textContent.trim()"), "Alice"); await follow(".team-back a", "/admin"); for (const request of requests) assert.equal(new URL(request.url).searchParams.get("token"), token, request.url); + console.log("PASS: Move from swapped partial and mobile team page, persisted membership, 303 redirects, and back links"); + + // Use server-rendered participant navigation: the offline editor fixture has + // only an empty topbar and cannot catch crowded breadcrumbs or missing links. + async function chapter(path) { + // Picker links use slugs; the server redirects them to numbered file stems. + const response = await fetch(base + path, { signal: AbortSignal.timeout(5000) }); + assert.equal(response.status, 200); + path = new URL(response.url).pathname; + await response.body.cancel(); + await js("window.oldDocument = true"); + await cdp("Page.navigate", { url: base + path }); + await until(() => js(`!window.oldDocument && document.readyState === 'complete' + && location.pathname === ${JSON.stringify(path)} && !!document.querySelector('.chapter-picker')`), `chapter navigation to ${path}`); + await js("document.fonts.ready.then(() => true)"); + } + await chapter(`/exercise/${alice}/00_numbers_in_rust`); + const longChapter = await js(`[...document.querySelectorAll('.chapter-picker-item')] + .sort((a, b) => b.querySelector('.chapter-picker-title').textContent.length - a.querySelector('.chapter-picker-title').textContent.length)[0].pathname`); + for (const path of [`/exercise/${alice}/00_numbers_in_rust`, longChapter]) { + await chapter(path); + const title = await js("document.querySelector('.chapter-picker-label').textContent.trim()"); + for (const width of [320, 375, 768, 800, 1024, 1200, 1201, 1440]) { + await cdp("Emulation.setDeviceMetricsOverride", { width, height: 450, deviceScaleFactor: 1, mobile: false }); + await js("window.scrollTo(0, 0); new Promise(resolve => requestAnimationFrame(() => requestAnimationFrame(resolve)))"); + const layout = await js(`(() => { + const header = document.querySelector('.topbar').getBoundingClientRect(); + const controls = [...document.querySelectorAll('.topbar-home, .chapter-picker-btn, .topbar-link, .topbar .theme-toggle')]; + const label = document.querySelector('.chapter-picker-label'); + const actionCenters = [...document.querySelectorAll('.topbar-link, .topbar .theme-toggle')] + .map(el => { const r = el.getBoundingClientRect(); return r.y + r.height / 2; }); + return {viewport: innerWidth, page: document.documentElement.scrollWidth, + actionsTogether: Math.max(...actionCenters) - Math.min(...actionCenters) <= 1, + clippedPage: [document.documentElement, document.body].some(el => ['hidden', 'clip'].includes(getComputedStyle(el).overflowX)), + progress: document.querySelector('.topbar-progress').getBoundingClientRect().width, + titleFits: label.scrollWidth <= label.clientWidth + 1, + controls: controls.map(el => { + const r = el.getBoundingClientRect(); + return {name: el.textContent.trim() || el.getAttribute('aria-label'), + fits: r.width > 0 && r.left >= 0 && r.right <= innerWidth + 1 && r.top >= header.top && r.bottom <= header.bottom && r.bottom <= innerHeight, + hit: el.contains(document.elementFromPoint(r.x + r.width / 2, r.y + r.height / 2))}; + })}; + })()`); + assert.equal(layout.viewport, width); + assert.ok(layout.page <= width + 1 && !layout.clippedPage && layout.titleFits && layout.progress > 0, + `${width}px ${title}: ${JSON.stringify(layout)}`); + if (width > 768) assert.ok(layout.actionsTogether, `${width}px: keep labelled navigation actions on the same row`); + assert.equal(layout.controls.length, 8); + for (const control of layout.controls) assert.ok(control.fits && control.hit, `${width}px ${title}: ${JSON.stringify(control)}`); + await js("document.querySelector('.topbar-home').focus()"); + for (let i = 1; i < layout.controls.length; i++) { + await key("Tab", 9); + assert.equal(await js(`document.activeElement === document.querySelectorAll('.topbar-home, .chapter-picker-btn, .topbar-link, .topbar .theme-toggle')[${i}] && scrollX === 0`), true); + } + if (values["screenshot-dir"]) { + const dir = resolve(values["screenshot-dir"]); + await mkdir(dir, { recursive: true }); + const image = await cdp("Page.captureScreenshot"); + await writeFile(join(dir, `navigation-${path.split('/').at(-1)}-${width}.png`), Buffer.from(image.data, "base64")); + } + await click('.chapter-picker-btn'); + assert.equal(await js("document.querySelector('.chapter-picker-btn').getAttribute('aria-expanded')"), "true"); + assert.equal(await js(`(() => { + const r = document.querySelector('.chapter-picker-menu').getBoundingClientRect(); + return r.width > 0 && r.left >= 0 && r.right <= innerWidth + 1 && r.top >= 0 && r.bottom <= innerHeight; + })()`), true, `${width}px: chapter menu fits`); + await key("Escape", 27); + assert.equal(await js("document.querySelector('.chapter-picker-menu').hidden"), true); + await js(`document.querySelector('.exercise-section').scrollIntoView(); window.scrollBy(0, 200)`); + await until(() => js(`(() => { + const bar = document.querySelector('.topbar').getBoundingClientRect(); + const toolbar = document.querySelector('[data-role="editor-toolbar"]').getBoundingClientRect(); + return Math.abs(toolbar.top - bar.bottom) <= 1 && toolbar.bottom < innerHeight; + })()`), `${width}px: editor toolbar clears wrapped navigation`); + console.log(`PASS: ${width}px ${title}: navigation fits, keyboard reaches all controls, chapter menu opens, editor toolbar clears header`); + } + } // Chrome requests this optional icon even though the app does not serve one. assert.deepEqual(responses.filter((r) => r.status >= 400 && !(r.status === 404 && new URL(r.url).pathname === "/favicon.ico")).map((r) => [r.status, r.url]), []); assert.deepEqual(browserErrors, []); - console.log("PASS: Move from swapped partial and mobile team page, persisted membership, 303 redirects, and back links"); } catch (error) { console.error(error); if (socket?.readyState === WebSocket.OPEN) { diff --git a/static/css/base.css b/static/css/base.css index 854f0cb..e06e500 100644 --- a/static/css/base.css +++ b/static/css/base.css @@ -776,7 +776,7 @@ html[data-theme="dark"] select.admin-input { position: sticky; top: 0; z-index: 900; - height: 3rem; + min-height: 3rem; background: var(--color-background); /* The hairline scroll-progress bar (`.topbar-progress-bar`) sits at the bottom edge of the topbar and acts as the @@ -784,17 +784,25 @@ html[data-theme="dark"] select.admin-input { itself doesn't draw a border. */ display: flex; align-items: center; - padding: 0 1.5rem; + padding: 0.25rem 1.5rem; } .topbar-inner { width: 100%; max-width: 1100px; margin: 0 auto; display: flex; + flex-wrap: wrap; align-items: center; gap: 0.4rem; font-size: 0.875rem; } +.topbar-actions { + display: flex; + flex-wrap: wrap; + align-items: center; + gap: 0.4rem; + max-width: 100%; +} .topbar-home { color: var(--color-text-muted); text-decoration: none; @@ -1250,29 +1258,27 @@ html[data-theme="dark"] .theme-toggle .icon-moon { .admin-table { font-size: 0.875rem; } + .topbar-link span:not(.sr-only) { + /* Drop the labels on phones, keep just the icons. */ + display: none; + } +} + +@media (max-width: 1200px) { .topbar { - height: auto; - min-height: 3rem; padding: 0.5rem 0.75rem; } - .topbar-inner { - flex-wrap: wrap; - } .chapter-picker { flex: 1; min-width: 0; } - /* Keep the full chapter title above the navigation controls on phones. */ + /* Give the chapter title its own row before labelled links become crowded. */ .chapter-picker ~ .topbar-spacer { flex-basis: 100%; } .topbar .theme-toggle { flex-shrink: 0; } - .topbar-link span:not(.sr-only) { - /* Drop the labels on phones, keep just the icons. */ - display: none; - } } /* ---------- Shared "book" page chrome ---------- diff --git a/templates/base.html b/templates/base.html index 826eb2c..f0b18a1 100644 --- a/templates/base.html +++ b/templates/base.html @@ -116,6 +116,7 @@ Course {% endblock %}
+
{% block topbar_progress %}{% endblock %} Settings {% include "partials/theme_toggle.html" %} +