diff --git a/.github/screenshots/phone-navigation/after-menu-375.png b/.github/screenshots/phone-navigation/after-menu-375.png new file mode 100644 index 00000000..4f9660d9 Binary files /dev/null and b/.github/screenshots/phone-navigation/after-menu-375.png differ diff --git a/.github/screenshots/phone-navigation/after-runs-375.png b/.github/screenshots/phone-navigation/after-runs-375.png new file mode 100644 index 00000000..443ad496 Binary files /dev/null and b/.github/screenshots/phone-navigation/after-runs-375.png differ diff --git a/.github/screenshots/phone-navigation/after-security-320.png b/.github/screenshots/phone-navigation/after-security-320.png new file mode 100644 index 00000000..ed1c31eb Binary files /dev/null and b/.github/screenshots/phone-navigation/after-security-320.png differ diff --git a/.github/screenshots/phone-navigation/before-menu-375.png b/.github/screenshots/phone-navigation/before-menu-375.png new file mode 100644 index 00000000..aad67ca7 Binary files /dev/null and b/.github/screenshots/phone-navigation/before-menu-375.png differ diff --git a/.github/screenshots/phone-navigation/before-runs-375.png b/.github/screenshots/phone-navigation/before-runs-375.png new file mode 100644 index 00000000..ed71b7c0 Binary files /dev/null and b/.github/screenshots/phone-navigation/before-runs-375.png differ diff --git a/dashboard/e2e/app-map.spec.ts b/dashboard/e2e/app-map.spec.ts index a16f4959..1f6372fc 100644 --- a/dashboard/e2e/app-map.spec.ts +++ b/dashboard/e2e/app-map.spec.ts @@ -690,8 +690,13 @@ test.describe("App map reading", () => { expect(got.reduce((a, [, n]) => a + n, 0)).toBe(map.screens.length); // Opened, each group lists its own screens. const web = v.locator("#ch-start details[data-app='web']"); - await web.evaluate((d) => { (d as HTMLDetailsElement).open = true; }); - for (const name of ["Home", "Slips", "Slip list", "Hero"]) await expect(web.getByText(name, { exact: true }).first()).toBeVisible(); + // The viewer draws the list once more shortly after it first shows it, + // which replaces the group closed: open it until it stays open. + await expect(async () => { + await web.evaluate((d) => { (d as HTMLDetailsElement).open = true; }); + await page.waitForTimeout(400); + for (const name of ["Home", "Slips", "Slip list", "Hero"]) await expect(web.getByText(name, { exact: true }).first()).toBeVisible({ timeout: 500 }); + }).toPass({ timeout: 15_000 }); await expect(web.getByText("Offer", { exact: true })).toHaveCount(0); fs.mkdirSync(SHOTS_DIR, { recursive: true }); await page.screenshot({ path: path.join(SHOTS_DIR, "app-map-screens-by-card.png"), fullPage: true }); diff --git a/dashboard/e2e/no-sideways-scroll.spec.ts b/dashboard/e2e/no-sideways-scroll.spec.ts index f5a8af60..008ee8bb 100644 --- a/dashboard/e2e/no-sideways-scroll.spec.ts +++ b/dashboard/e2e/no-sideways-scroll.spec.ts @@ -3,7 +3,8 @@ import { ROUTES } from "../src/lib/routes"; import { mockWideApi } from "./wide-data"; import { SAMPLE_QUERY } from "./wide-data/addresses"; -// No page scrolls sideways on a phone. Every page in the route map +// No page scrolls sideways on a phone, down to 320px (WCAG 1.4.10 Reflow). +// Every page in the route map // (lib/routes.ts) is opened at phone widths with records full of long, // unbroken strings (wide-data/long.ts): shas, URLs, branch names, file paths, // tables and code. A page fails if the document is wider than the screen, and @@ -14,7 +15,7 @@ import { SAMPLE_QUERY } from "./wide-data/addresses"; // any data it loads needs an answer in wide-data/: the spec fails and names // what is missing. -const WIDTHS = [375, 390]; +const WIDTHS = [320, 375, 390]; /** Every page in the route map, and the not-found page. */ const PAGES = [...Object.keys(ROUTES), "/no-such-page"]; diff --git a/dashboard/e2e/phone-nav-shots.spec.ts b/dashboard/e2e/phone-nav-shots.spec.ts new file mode 100644 index 00000000..15a1f278 --- /dev/null +++ b/dashboard/e2e/phone-nav-shots.spec.ts @@ -0,0 +1,38 @@ +import { expect, test, type Page } from "@playwright/test"; +import fs from "node:fs"; +import path from "node:path"; +import { mockWideApi } from "./wide-data"; +import { SAMPLE_QUERY } from "./wide-data/addresses"; + +// Screenshots of the dashboard on a phone, for a pull request: the bottom bar +// on the main pages, and the Menu sheet, at 375 and 320 wide. Written only +// when E2E_SHOTS_DIR is set; the checks themselves are in phone-nav.spec.ts. + +const DIR = process.env.E2E_SHOTS_DIR; + +async function shot(page: Page, name: string) { + fs.mkdirSync(DIR!, { recursive: true }); + await page.addStyleTag({ content: "nextjs-portal{display:none!important}" }); + await page.waitForTimeout(300); + await page.screenshot({ path: path.join(DIR!, `${name}.png`) }); +} + +test("phone screenshots: the bottom bar and the Menu sheet", async ({ page }) => { + test.skip(!DIR, "E2E_SHOTS_DIR is not set"); + test.setTimeout(300_000); + await mockWideApi(page); + for (const width of [375, 320]) { + await page.setViewportSize({ width, height: 760 }); + for (const route of ["/", "/reviewer", "/security", "/settings/team", "/runs/detail"]) { + await page.goto(route + (SAMPLE_QUERY[route] ?? "")); + await page.waitForLoadState("networkidle", { timeout: 15_000 }).catch(() => {}); + await expect(page.getByTestId("phone-bar")).toBeVisible(); + const slug = route === "/" ? "runs" : route.slice(1).replace(/\//g, "-"); + await shot(page, `phone-${slug}-${width}`); + } + await page.goto("/"); + await page.getByRole("button", { name: /^Menu/ }).click(); + await expect(page.getByRole("dialog", { name: "Menu" })).toBeVisible(); + await shot(page, `phone-menu-${width}`); + } +}); diff --git a/dashboard/e2e/phone-nav.spec.ts b/dashboard/e2e/phone-nav.spec.ts new file mode 100644 index 00000000..091f4387 --- /dev/null +++ b/dashboard/e2e/phone-nav.spec.ts @@ -0,0 +1,192 @@ +import { expect, test, type Locator, type Page } from "@playwright/test"; +import { NAV_SECTIONS, PHONE_BAR_KEYS, phoneBar, type NavSection } from "../src/lib/nav"; +import { mockWideApi } from "./wide-data"; + +// The dashboard on a phone. Every page a menu item opens is drawn at 375px +// (and 320px, WCAG's reflow width) with the wide data (records full of long, +// unbroken strings), and fails when: +// - the page scrolls sideways, +// - a navigation target (the bottom bar, the top bar, a page's tabs, every +// row of the Menu sheet) is smaller than 44 by 44px, +// - a field is drawn under 16px, so Safari on iOS would zoom into it. +// The failure names each offender with its size. + +const MIN = 44; + +/** Every page reachable from the main menu, once. */ +const ROUTES = [...new Set(NAV_SECTIONS.flatMap((s) => s.pages.map((p) => p.href)))]; + +async function hideDevOverlay(page: Page) { + await page.addInitScript(() => { + document.addEventListener("DOMContentLoaded", () => { + const s = document.createElement("style"); + s.textContent = "nextjs-portal{display:none!important}"; + document.head.appendChild(s); + }); + }); +} + +/** Visible links and buttons inside `scope` smaller than 44px either way, as "WxH name". */ +async function smallTargets(scope: Locator): Promise { + return scope.evaluateAll((roots, min) => { + const out: string[] = []; + for (const root of roots) { + for (const el of Array.from(root.querySelectorAll("a[href], button, [role=button], select, input:not([type=hidden])"))) { + const r = el.getBoundingClientRect(); + const cs = getComputedStyle(el); + if (r.width === 0 || r.height === 0 || cs.visibility === "hidden") continue; + if (r.width < min - 0.5 || r.height < min - 0.5) { + const name = (el.getAttribute("aria-label") || el.innerText || el.tagName).trim().replace(/\s+/g, " ").slice(0, 40); + out.push(`${Math.round(r.width)}x${Math.round(r.height)} "${name}"`); + } + } + } + return out; + }, MIN); +} + +async function sidewaysBy(page: Page): Promise { + return page.evaluate(() => document.documentElement.scrollWidth - document.documentElement.clientWidth); +} + +test.describe.configure({ mode: "parallel" }); + +for (const route of ROUTES) { + test(`phone: ${route} reflows, and its navigation is thumb-sized`, async ({ page }) => { + await mockWideApi(page); + await hideDevOverlay(page); + const problems: string[] = []; + + for (const width of [320, 375]) { + await page.setViewportSize({ width, height: 740 }); + await page.goto(route); + await page.waitForLoadState("networkidle", { timeout: 15_000 }).catch(() => {}); + await expect(page.getByTestId("phone-bar")).toBeVisible(); + await page.waitForTimeout(250); + const over = await sidewaysBy(page); + if (over > 0) problems.push(`${route} at ${width}px scrolls sideways by ${over}px`); + } + + // At 375px: the bar, the top bar and the page's tabs. + for (const [name, scope] of [ + ["bottom bar", page.getByTestId("phone-bar")], + ["top bar", page.getByTestId("topbar")], + ["page tabs", page.getByTestId("section-tabs").or(page.getByTestId("settings-page-tabs"))], + ] as const) { + for (const s of await smallTargets(scope)) problems.push(`${name}: ${s}`); + } + // One destination in the bar is current, or Menu is (its page is in the sheet). + const current = page.getByTestId("phone-bar").locator('[aria-current="page"], [aria-current="true"]'); + await expect(current, `${route}: the bottom bar marks where you are`).toHaveCount(1); + + // Fields are at least 16px, so iOS does not zoom on focus. + const smallFields = await page.locator("input:not([type=checkbox]):not([type=radio]):not([type=hidden]), select, textarea").evaluateAll((els) => + els + .filter((el) => (el as HTMLElement).offsetParent !== null && parseFloat(getComputedStyle(el).fontSize) < 16) + .map((el) => `${el.tagName.toLowerCase()}[${el.getAttribute("aria-label") || el.getAttribute("placeholder") || el.id}] ${getComputedStyle(el).fontSize}`), + ); + for (const f of smallFields) problems.push(`field under 16px: ${f}`); + + // The Menu sheet: every row, the team switcher, help and sign out. + await page.getByRole("button", { name: "Menu" }).click(); + const sheet = page.getByRole("dialog", { name: "Menu" }); + await expect(sheet).toBeVisible(); + for (const s of await smallTargets(sheet)) problems.push(`Menu sheet: ${s}`); + const box = await sheet.boundingBox(); + if (!box || box.width < 375 - 0.5) problems.push(`Menu sheet is ${box?.width ?? 0}px wide, not the whole screen`); + + expect(problems.join("\n"), `${route} on a phone`).toBe(""); + }); +} + +test("phone: the bottom bar holds Runs, Review, Chat and Security, then Menu; the current page is marked", async ({ page }) => { + await mockWideApi(page); + await hideDevOverlay(page); + await page.setViewportSize({ width: 375, height: 740 }); + await page.goto("/reviewer/stale"); + const bar = page.getByRole("navigation", { name: "Main" }); + await expect(bar.getByRole("link")).toHaveText(["Runs", "Review", "Chat", /Security/]); + await expect(bar.getByRole("link", { name: "Review" })).toHaveAttribute("aria-current", "page"); + // Security's count is said, not only drawn. + await expect(bar.getByRole("link", { name: /^Security/ })).toHaveAccessibleName(/2 urgent security findings/); + // A page only in the sheet marks Menu. + await page.goto("/analytics"); + await expect(page.getByRole("button", { name: /^Menu/ })).toHaveAttribute("aria-current", "true"); + await expect(bar.locator('[aria-current="page"]')).toHaveCount(0); + // The bar sits at the bottom of the screen. + const box = await page.getByTestId("phone-bar").boundingBox(); + expect(Math.round((box?.y ?? 0) + (box?.height ?? 0))).toBe(740); + // Wider screens keep the sidebar and no bar. + await page.setViewportSize({ width: 1280, height: 800 }); + await expect(page.getByTestId("phone-bar")).toBeHidden(); + await expect(page.getByTestId("main-nav")).toBeVisible(); +}); + +test("phone: the Menu sheet works from the keyboard and gives focus back", async ({ page }) => { + await mockWideApi(page); + await hideDevOverlay(page); + await page.setViewportSize({ width: 375, height: 740 }); + await page.goto("/"); + const menu = page.getByRole("button", { name: /^Menu/ }); + await menu.focus(); + await expect(menu).toHaveAttribute("aria-expanded", "false"); + await page.keyboard.press("Enter"); + const sheet = page.getByRole("dialog", { name: "Menu" }); + await expect(sheet).toBeVisible(); + await expect(menu).toHaveAttribute("aria-expanded", "true"); + // Focus is inside the sheet and stays there. + await expect.poll(() => sheet.evaluate((el) => el.contains(document.activeElement))).toBe(true); + for (let i = 0; i < 40; i++) await page.keyboard.press("Tab"); + await expect.poll(() => sheet.evaluate((el) => el.contains(document.activeElement))).toBe(true); + // The current destination is marked in the sheet too. + await expect(sheet.getByTestId("main-nav").getByRole("link", { name: "Runs", exact: true })).toHaveAttribute("aria-current", "page"); + await page.keyboard.press("Escape"); + await expect(sheet).toBeHidden(); + await expect(menu).toBeFocused(); + // A row goes where it says and closes the sheet. + await menu.click(); + await sheet.getByRole("link", { name: "Plans", exact: true }).click(); + await expect(page).toHaveURL(/\/plans\/?$/); + await expect(sheet).toBeHidden(); + // Close is a large button with its name. + await menu.click(); + await sheet.getByRole("button", { name: "Close" }).click(); + await expect(sheet).toBeHidden(); +}); + +test("phone: the team switcher in the Menu sheet lists every team in rows a thumb can hit", async ({ page }) => { + await mockWideApi(page); + await hideDevOverlay(page); + await page.route("**/api/teams", (r) => + r.fulfill({ + contentType: "application/json", + body: JSON.stringify({ + teams: [ + { team_id: "t_1", org: "example-org", status: "active", current: true }, + { team_id: "t_2", org: "sample-team", status: "active", current: false }, + ], + }), + }), + ); + await page.setViewportSize({ width: 375, height: 740 }); + await page.goto("/"); + await page.getByRole("button", { name: /^Menu/ }).click(); + const sheet = page.getByRole("dialog", { name: "Menu" }); + await sheet.getByRole("button", { name: /Switch team/ }).click(); + const rows = sheet.getByRole("button", { name: /(example-org|sample-team)$/ }); + await expect(rows).toHaveCount(2); + for (const row of await rows.all()) expect((await row.boundingBox())?.height ?? 0).toBeGreaterThanOrEqual(MIN); + await expect(sheet.getByRole("button", { name: /example-org$/ })).toHaveAttribute("aria-current", "true"); +}); + +test("phone: the bar keeps a place for Pull requests", () => { + // The kept place is in the bar's order, second, after Runs. + expect(PHONE_BAR_KEYS[1]).toBe("pull-requests"); + const sec = (key: string, label: string): NavSection => ({ key, label, icon: "reviews", pages: [{ href: `/${key}`, label }] }); + const visible = [...NAV_SECTIONS, sec("pull-requests", "Pull requests")].map((section) => ({ section, href: section.pages[0].href })); + // Once a Pull requests destination exists it is in the bar and Security moves into the Menu sheet. + expect(phoneBar(visible).map((x) => x.section.key)).toEqual(["runs", "pull-requests", "reviews", "chat"]); + // Today: Runs, Code review, Chat and Security. + const today = NAV_SECTIONS.map((section) => ({ section, href: section.pages[0].href })); + expect(phoneBar(today).map((x) => x.section.key)).toEqual(["runs", "reviews", "chat", "security"]); +}); diff --git a/dashboard/src/app/chat/page.tsx b/dashboard/src/app/chat/page.tsx index df350c02..6f9eba42 100644 --- a/dashboard/src/app/chat/page.tsx +++ b/dashboard/src/app/chat/page.tsx @@ -801,7 +801,7 @@ function Chat() { } return ( - + {/* The empty page draws its own heading; an open chat's name is a hidden one (and the top bar's last crumb). */} {navSlot && !empty ? : navSlot ? : empty ? : } {navSlot && createPortal(list({ inSheet: true }), navSlot)} diff --git a/dashboard/src/app/chat/thread-list.tsx b/dashboard/src/app/chat/thread-list.tsx index d352e2c3..88cfbb89 100644 --- a/dashboard/src/app/chat/thread-list.tsx +++ b/dashboard/src/app/chat/thread-list.tsx @@ -217,7 +217,7 @@ export function ThreadList({ type="button" onClick={onNew} data-testid="new-chat" - className={`inline-flex h-9 min-w-0 flex-1 items-center gap-2 rounded-lg border border-zinc-800 px-3 text-sm text-zinc-200 hover:bg-zinc-800/70 ${focusRing}`} + className={`inline-flex h-9 max-md:h-11 min-w-0 flex-1 items-center gap-2 rounded-lg border border-zinc-800 px-3 text-sm text-zinc-200 hover:bg-zinc-800/70 ${focusRing}`} > New chat @@ -252,7 +252,7 @@ export function ThreadList({ aria-label="Search chats" placeholder="Search chats" data-testid="thread-search" - className="h-8 w-full rounded-lg border border-transparent bg-zinc-900 pl-8 pr-2 text-sm text-zinc-200 placeholder-zinc-500 focus:border-zinc-600 focus:outline-none" + className="h-8 max-md:h-11 w-full rounded-lg border border-transparent bg-zinc-900 pl-8 pr-2 text-sm text-zinc-200 placeholder-zinc-500 focus:border-zinc-600 focus:outline-none" /> {bulk && !selecting && (threads ?? []).some(selectable) && ( @@ -355,7 +355,7 @@ export function ThreadList({
Knowledge @@ -411,7 +411,7 @@ function ThreadRow({
  • {canChange ? (