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
80 changes: 80 additions & 0 deletions dashboard/e2e/tabs-no-scroll.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import { expect, test, type Page } from "@playwright/test";
import { mockWideApi } from "./wide-data";
import { SAMPLE_QUERY } from "./wide-data/addresses";

// A row of tabs (components/tabs.tsx) scrolls only when its tabs don't fit.
// On a desktop screen every row here fits, so its scroll box must not scroll
// either way: a box that is even 1px bigger inside than out draws a scrollbar
// under the tabs. On a phone a row may scroll inside itself, but the page
// never scrolls sideways.
//
// Every page that draws the shared tab row is listed; the spec fails if a
// listed page stops drawing one, so the list can't quietly go stale.

const PAGES = [
"/runs/detail", // Overview, Changes, Activity, Details
"/analytics",
"/tests",
"/admin",
"/settings/agents",
"/settings/deliveries",
"/skills/agent",
"/reviewer", // the section's pages (Reviewer, Tests, Releases)
"/logs", // the section's pages (Logs, Alerts)
"/settings/instructions", // the Instructions pages
];

const DESKTOP = [1280, 1600];
const PHONE = 375;

async function open(page: Page, path: string, width: number) {
await page.setViewportSize({ width, height: 900 });
await page.goto(path + (SAMPLE_QUERY[path] ?? ""));
await page.waitForLoadState("networkidle", { timeout: 15_000 }).catch(() => {});
await expect(page.getByTestId("topbar")).toBeVisible();
await page.waitForTimeout(300);
}

/** Each visible tab row's scroll box: its inside and outside sizes. */
function rows(page: Page) {
return page.evaluate(() =>
Array.from(document.querySelectorAll<HTMLElement>("[data-testid=tab-row] > [data-scroll-fade]"))
.filter((el) => el.getClientRects().length > 0)
.map((el) => ({
label: el.closest("nav")?.getAttribute("aria-label") ?? "",
scrollWidth: el.scrollWidth,
clientWidth: el.clientWidth,
scrollHeight: el.scrollHeight,
clientHeight: el.clientHeight,
})),
);
}

test.describe.configure({ mode: "parallel" });

for (const path of PAGES) {
test(`tab row does not scroll when it fits: ${path}`, async ({ page }) => {
await mockWideApi(page);
const problems: string[] = [];
for (const width of DESKTOP) {
await open(page, path, width);
const found = await rows(page);
if (!found.length) problems.push(`${path} at ${width}px draws no tab row`);
for (const r of found) {
if (r.scrollWidth > r.clientWidth) problems.push(`${path} at ${width}px: "${r.label}" is ${r.scrollWidth - r.clientWidth}px wider inside than out`);
if (r.scrollHeight > r.clientHeight) problems.push(`${path} at ${width}px: "${r.label}" is ${r.scrollHeight - r.clientHeight}px taller inside than out`);
}
}
await open(page, path, PHONE);
const { scrollWidth, clientWidth } = await page.evaluate(() => ({
scrollWidth: document.documentElement.scrollWidth,
clientWidth: document.documentElement.clientWidth,
}));
if (scrollWidth > clientWidth) problems.push(`${path} at ${PHONE}px is ${scrollWidth - clientWidth}px wider than the screen`);
// On a phone the row may scroll sideways, but never up and down.
for (const r of await rows(page)) {
if (r.scrollHeight > r.clientHeight) problems.push(`${path} at ${PHONE}px: "${r.label}" is ${r.scrollHeight - r.clientHeight}px taller inside than out`);
}
expect(problems.join("\n"), `${path}: a tab row scrolls though its tabs fit, or the page scrolls sideways`).toBe("");
});
}
16 changes: 10 additions & 6 deletions dashboard/src/components/tabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,20 @@ export function Tabs({
const asSelect = items.length > selectAbove;
const current = items.find((t) => t.value === value);

// The base line is the row's own bottom border, and each tab's underline
// pulls down 1px to sit on it. Both stay inside the row's box: a negative
// margin on the row itself would make the scroll box 1px taller inside than
// out, so it scrolled (and showed a scrollbar) even when every tab fit.
const row = (
<ul className="-mb-px flex gap-x-1">
<ul className="flex min-w-max gap-x-1 border-b border-zinc-800">
{items.map((t) => {
const on = t.value === value;
return (
<li key={t.value} className="shrink-0">
<li key={t.value} className="flex shrink-0">
<Link
href={t.href}
aria-current={on ? "page" : undefined}
className={`inline-flex min-h-10 items-center gap-2 whitespace-nowrap rounded-t border-b-2 px-3 text-sm ${
className={`-mb-px inline-flex min-h-10 items-center gap-2 whitespace-nowrap rounded-t border-b-2 px-3 text-sm ${
on ? "border-zinc-100 font-medium text-zinc-100" : "border-transparent text-zinc-400 hover:text-zinc-100"
} ${focusRing}`}
>
Expand All @@ -66,9 +70,9 @@ export function Tabs({
);

return (
<nav aria-label={label} className={`border-b border-zinc-800 ${className}`}>
<nav aria-label={label} className={className}>
{asSelect && (
<div className="pb-3 sm:hidden">
<div className="border-b border-zinc-800 pb-3 sm:hidden">
<Select
aria-label={label}
value={current?.value ?? ""}
Expand All @@ -81,7 +85,7 @@ export function Tabs({
/>
</div>
)}
<ScrollFade axis="x" className={asSelect ? "hidden sm:block" : ""}>
<ScrollFade axis="x" testId="tab-row" className={asSelect ? "hidden sm:block" : ""}>
{row}
</ScrollFade>
</nav>
Expand Down
Loading