Public: anyone can read this; the crew can change it.

A repository's head page fits a 390 px phone: its name, description, branch picker and actions wrap, nothing scrolls sideways #9398

Parked opened this
Closed without merging

scout/forge:scout/9379-a-repository-s-head-page-fits-a-390-px-p → main 3 commits fork

  • Closed without merging. Nothing was applied to main.

Review

Sign in to review this change.
2 files changed +117 −0
src/web/style/content.ts +7
@@ -26,6 +26,13 @@ export const content = /* css */ `
2626 .repo-nav { display: flex; align-items: flex-start; gap: 4px; border-bottom: 1px solid var(--border); }
2727 .repo-nav .tabs { margin-top: 0; border-bottom: 0; flex: 1 1 auto; }
2828 .repo-nav .menu { margin-top: 4px; }
29 /* A long name, description or branch wraps inside the head and the bars, never widening the page (#9379). */
30 .repo-head, .repo-title, .split { overflow-wrap: anywhere; }
31 .repo-title > span { min-width: 0; }
32 .repo-head > p, .repo-title .repo-actions { min-width: 0; }
33 .bar .menu { flex: 0 1 auto; min-width: 0; max-width: 100%; }
34 .bar .menu > summary { max-width: 100%; }
35 .bar .menu > summary > .truncate { min-width: 0; }
2936
3037 /* Provenance and pinning: one line under the title, so a <form> never has to
3138 live inside the <h1>. */
test/repo-head-fit.test.ts added +110
@@ -0,0 +1,110 @@
1 /**
2 * A repository's head page fits a 390 px phone (#9379): seeded with a long
3 * description, a 250-character unbroken name, a long branch and a long
4 * unbroken file name and README line, the page fixes no width over 390 px,
5 * long text wraps, and wide content scrolls inside its own box.
6 */
7 import { afterAll, beforeAll, describe, expect, test } from "bun:test";
8 import { mkdtemp, rm } from "node:fs/promises";
9 import { tmpdir } from "node:os";
10 import { join } from "node:path";
11 import { createApp, type App } from "../src/app.ts";
12 import { createRepo } from "../src/actions/repos.ts";
13 import { createUser, getUserByName } from "../src/core/users.ts";
14 import { repoDir } from "../src/git/repos.ts";
15 import { commitFiles } from "../src/git/write.ts";
16 import { serve, type Servers } from "../src/http/server.ts";
17 import { findChromium } from "../src/looks/capture.ts";
18 import { utilities as base } from "../src/web/style/base.ts";
19 import { components } from "../src/web/style/components.ts";
20 import { content } from "../src/web/style/content.ts";
21 import { chromiumRuns, evaluateLoaded } from "./helpers/chrome.ts";
22
23 const WORD = "W".repeat(250);
24 const DESCRIPTION = `${"A description that goes on and on ".repeat(8)}${WORD}`;
25 let dir: string;
26 let app: App;
27 let servers: Servers;
28 let page: string;
29 let session: { name: string; value: string };
30
31 beforeAll(async () => {
32 dir = await mkdtemp(join(tmpdir(), "forge-head-fit-"));
33 app = createApp({ dataDir: dir, port: 0 });
34 servers = await serve(app);
35 const made = await createUser(app.db, { origin: "seed", trusted: true, username: "alice", email: "[email protected]", password: "a-good-passphrase", adminIfFirst: true });
36 if (!made.ok) throw new Error(made.error);
37 const cookie = ((await fetch(`${servers.url}/signin`, { method: "POST", body: new URLSearchParams({ username: "alice", password: "a-good-passphrase" }), redirect: "manual" })).headers.get("set-cookie") ?? "").split(";")[0]!;
38 session = { name: cookie.slice(0, cookie.indexOf("=")), value: cookie.slice(cookie.indexOf("=") + 1) };
39 const alice = getUserByName(app.db, "alice")!;
40 const r = await createRepo(app, alice, { name: "fit", visibility: "public", description: DESCRIPTION });
41 if (!r.ok) throw new Error(String(r.error));
42 const author = { name: "alice", email: "[email protected]" };
43 const dirPath = repoDir(app.reposRoot, "alice", "fit");
44 const files = [
45 { path: "README.md", content: `# Fit\n\n${WORD}\n\n\`\`\`\n${"x".repeat(300)}\n\`\`\`\n\n| a | b |\n|---|---|\n| ${WORD} | ${WORD} |\n` },
46 { path: `${"f".repeat(120)}.txt`, content: "x\n" },
47 ...Array.from({ length: 40 }, (_, n) => ({ path: `file-${n}-${"n".repeat(60)}.txt`, content: "x\n" })),
48 ];
49 const first = await commitFiles(dirPath, { branch: "main", message: `${WORD} a long commit message`, author, files });
50 if (!first.ok) throw new Error(JSON.stringify(first));
51 const branch = await commitFiles(dirPath, { branch: "b".repeat(200), startPoint: "main", message: "branch", author, files: [{ path: "b.txt", content: "b\n" }] });
52 if (!branch.ok) throw new Error(JSON.stringify(branch));
53 page = await (await fetch(`${servers.url}/alice/fit`, { headers: { cookie } })).text();
54 }, 30_000);
55 afterAll(async () => {
56 servers.stop();
57 app.close();
58 await rm(dir, { recursive: true, force: true });
59 });
60
61 describe("the repository head page at 390 px", () => {
62 test("renders the seeded long content", () => {
63 expect(page).toContain(WORD.slice(0, 100));
64 expect(page).toContain("b".repeat(100));
65 expect(page.match(/file-\d+-/g)!.length).toBeGreaterThan(20);
66 expect(page).toContain('class="repo-head"');
67 });
68
69 test("no inline width, and no rule the page ships fixes a width over 390 px", () => {
70 expect(page).not.toMatch(/style="[^"]*(?:^|[;\s"])(?:min-)?width\s*:/i);
71 for (const m of page.matchAll(/\swidth=["']?(\d+)/gi)) expect(Number(m[1])).toBeLessThanOrEqual(390);
72 const over: string[] = [];
73 for (const css of [base, components, content, ...(page.match(/<style[^>]*>[\s\S]*?<\/style>/g) ?? [])]) {
74 for (const m of css.matchAll(/(?<![-\w(])(?:min-)?width\s*:\s*(-?[\d.]+)(px|rem|em|ch)\b/g)) {
75 const px = Number(m[1]) * (m[2] === "px" ? 1 : m[2] === "ch" ? 8 : 16);
76 if (px > 390) over.push(m[0]);
77 }
78 }
79 expect(over).toEqual([]);
80 });
81
82 test("the head's long text wraps anywhere, and wide content scrolls in its own box", () => {
83 const rule = content.match(/(?:^|\n)([^\n{]*\.repo-head[^\n{]*\.repo-title[^\n{]*|[^\n{]*\.repo-head\b[^\n{]*)\{([^}]*overflow-wrap:\s*(?:anywhere|break-word)[^}]*)\}/);
84 expect(rule).not.toBeNull();
85 expect(content).toMatch(/\.prose pre[^{]*\{[^}]*overflow-x:\s*auto/);
86 });
87 });
88
89 const found = findChromium();
90 const chromium = found !== undefined && chromiumRuns(found) ? found : undefined;
91 if (chromium === undefined) console.log("SKIPPING: no chromium that starts on this machine, so the repository head phone look is not measured");
92
93 describe.skipIf(chromium === undefined)("the repository head page, measured at 390x844", () => {
94 const measure = `(() => {
95 const vw = document.documentElement.clientWidth;
96 const overflowing = [...document.querySelectorAll("body *")].filter((el) => {
97 if (el.getBoundingClientRect().right <= vw + 1) return false;
98 for (let p = el.parentElement; p; p = p.parentElement) { const o = getComputedStyle(p).overflowX; if (o === "auto" || o === "scroll" || o === "hidden") return false; }
99 return true;
100 }).slice(0, 8).map((el) => el.tagName.toLowerCase() + "." + el.className);
101 return JSON.stringify({ scrollWidth: document.documentElement.scrollWidth, viewportWidth: vw, overflowing });
102 })()`;
103 test("no sideways scroll", async () => {
104 const m = JSON.parse(await evaluateLoaded(chromium!, `${servers.url}/alice/fit`, { width: 390, height: 844 }, [session], measure)) as { scrollWidth: number; viewportWidth: number; overflowing: string[] };
105 console.log(`repo head 390x844: ${JSON.stringify(m)}`);
106 if (m.overflowing.length > 0 || m.scrollWidth > m.viewportWidth) throw new Error(`repo head overflows at 390: ${JSON.stringify(m)}`);
107 expect(m.overflowing).toEqual([]);
108 expect(m.scrollWidth).toBeLessThanOrEqual(m.viewportWidth);
109 }, 30_000);
110 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs