Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 7 additions & 2 deletions dashboard/e2e/app-map.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand Down
5 changes: 3 additions & 2 deletions dashboard/e2e/no-sideways-scroll.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"];
Expand Down
38 changes: 38 additions & 0 deletions dashboard/e2e/phone-nav-shots.spec.ts
Original file line number Diff line number Diff line change
@@ -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}`);
}
});
192 changes: 192 additions & 0 deletions dashboard/e2e/phone-nav.spec.ts
Original file line number Diff line number Diff line change
@@ -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<string[]> {
return scope.evaluateAll((roots, min) => {
const out: string[] = [];
for (const root of roots) {
for (const el of Array.from(root.querySelectorAll<HTMLElement>("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<number> {
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"]);
});
2 changes: 1 addition & 1 deletion dashboard/src/app/chat/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -801,7 +801,7 @@ function Chat() {
}

return (
<Page className="flex h-[calc(100dvh-5.25rem)] flex-col md:h-[calc(100dvh-7.25rem)]" testId="chat-page">
<Page className="flex h-[calc(100dvh-5.75rem-var(--bottom-bar)-env(safe-area-inset-top))] flex-col md:h-[calc(100dvh-7.25rem)]" testId="chat-page">
{/* 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 ? <PageHeader title={thread?.title ?? "Chat"} crumb={thread?.title ?? false} titleClassName="sr-only" /> : navSlot ? <OwnTitle /> : empty ? <OwnTitle /> : <PageHeader title="Chat" crumb={thread?.title} />}
{navSlot && createPortal(list({ inSheet: true }), navSlot)}
Expand Down
10 changes: 5 additions & 5 deletions dashboard/src/app/chat/thread-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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}`}
>
<ComposeIcon />
<span className="min-w-0 flex-1 truncate text-left">New chat</span>
Expand Down Expand Up @@ -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"
/>
</label>
{bulk && !selecting && (threads ?? []).some(selectable) && (
Expand Down Expand Up @@ -355,7 +355,7 @@ export function ThreadList({
<div className="mt-3 border-t border-zinc-800/80 pt-3">
<Link
href={KNOWLEDGE_HREF}
className={`flex min-w-0 items-center gap-2.5 rounded-lg px-2 py-2 text-sm text-zinc-400 hover:bg-zinc-800/60 hover:text-zinc-200 ${focusRing}`}
className={`flex min-w-0 items-center gap-2.5 rounded-lg px-2 py-2 max-md:min-h-12 text-sm text-zinc-400 hover:bg-zinc-800/60 hover:text-zinc-200 ${focusRing}`}
>
<BookIcon />
<span className="min-w-0 flex-1 truncate">Knowledge</span>
Expand Down Expand Up @@ -411,7 +411,7 @@ function ThreadRow({
<li className="min-w-0" data-testid="thread-row">
{canChange ? (
<label
className={`flex min-w-0 cursor-pointer items-center gap-2 rounded-lg px-2 py-1.5 text-sm ${checked ? "bg-zinc-800 text-zinc-100" : "text-zinc-300 hover:bg-zinc-800/50"}`}
className={`flex min-w-0 cursor-pointer items-center gap-2 rounded-lg px-2 py-1.5 max-md:min-h-12 text-sm ${checked ? "bg-zinc-800 text-zinc-100" : "text-zinc-300 hover:bg-zinc-800/50"}`}
>
<input
type="checkbox"
Expand Down Expand Up @@ -465,7 +465,7 @@ function ThreadRow({
}}
aria-current={current ? "page" : undefined}
title={t.title}
className={`flex min-w-0 items-center gap-2 rounded-lg px-2 py-1.5 text-sm ${canChange ? "pr-9" : ""} ${current ? "bg-zinc-800 text-zinc-100" : "text-zinc-400 hover:bg-zinc-800/50 hover:text-zinc-200"} ${focusRing}`}
className={`flex min-w-0 items-center gap-2 rounded-lg px-2 py-1.5 max-md:min-h-12 text-sm ${canChange ? "pr-9" : ""} ${current ? "bg-zinc-800 text-zinc-100" : "text-zinc-400 hover:bg-zinc-800/50 hover:text-zinc-200"} ${focusRing}`}
>
<span className="min-w-0 flex-1">
<span className="block truncate">{t.title}</span>
Expand Down
Loading
Loading