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

A repository's files page fits a 390 px phone: long paths and file names wrap, a file's code scrolls inside its box, never the page #9391

Parked opened this
Closed without merging

scout/forge:scout/9376-a-repository-s-files-page-fits-a-390-px → main 3 commits fork

  • Closed without merging. Nothing was applied to main.

Review

Sign in to review this change.
3 files changed +126 −1
src/web/pages/explorer.ts +1 −1
@@ -319,7 +319,7 @@ export const SPLIT = { min: 200, start: 300, minMain: 480 } as const;
319319 * without one the columns keep the stylesheet's width and nothing is lost.
320320 */
321321 export function codeLayout(explorer: Html, content: Html): Html {
322 return html`<div class="code-layout">
322 return html`<div class="code-layout" data-tree>
323323 ${explorer}
324324 <div
325325 role="separator"
src/web/style/content.ts +7
@@ -605,6 +605,13 @@ form.inline { display: inline; margin-left: auto; }
605605 has exactly one thing to set and the stylesheet keeps the fallback. */
606606 .code-layout { display: grid; gap: 12px; margin-top: 12px; align-items: start; }
607607 .code-layout > #code-main { min-width: 0; }
608 /* The files page on a phone: a long name breaks anywhere, a row wraps rather
609 than ellipsizes, the path above wraps; code keeps scrolling in .code. */
610 [data-tree] { overflow-wrap: anywhere; }
611 [data-tree] .row-title { white-space: normal; overflow: visible; text-overflow: clip; }
612 [data-tree] .row { align-items: flex-start; }
613 [data-tree] .crumbs { flex-wrap: wrap; overflow: visible; }
614 [data-tree] .crumbs a { white-space: normal; overflow: visible; text-overflow: clip; }
608615 .code-layout > #code-main[aria-busy="true"] { opacity: .55; transition: opacity 120ms var(--ease); }
609616 /* The divider is nothing until a script can drag it, and nothing on one
610617 column either. */
test/tree-fit.test.ts added +118
@@ -0,0 +1,118 @@
1 /**
2 * The files page fits a 390 px phone (#9376): a directory listing and a file
3 * view, seeded with a 250-character unbroken name, a long path and many rows,
4 * fix no width over 390 px, wrap long names, and scroll code inside its box.
5 */
6 import { afterAll, beforeAll, describe, expect, test } from "bun:test";
7 import { mkdtemp, rm } from "node:fs/promises";
8 import { tmpdir } from "node:os";
9 import { join } from "node:path";
10 import { commitToBranch, createRepo } from "../src/actions/repos.ts";
11 import { createApp, type App } from "../src/app.ts";
12 import { createSession } from "../src/core/sessions.ts";
13 import { createUser } from "../src/core/users.ts";
14 import { serve, type Servers } from "../src/http/server.ts";
15 import { findChromium } from "../src/looks/capture.ts";
16 import { utilities as base } from "../src/web/style/base.ts";
17 import { components } from "../src/web/style/components.ts";
18 import { content } from "../src/web/style/content.ts";
19 import { chromiumRuns, evaluateLoaded } from "./helpers/chrome.ts";
20
21 const WORD = "N".repeat(250);
22 const DIR = "D".repeat(120);
23 let dir: string;
24 let app: App;
25 let servers: Servers;
26 let listing: string;
27 let file: string;
28 let session: { name: string; value: string };
29 const listPath = `/alice/fit/tree/main/${DIR}`;
30 const filePath = `/alice/fit/blob/main/${DIR}/${WORD}.ts`;
31
32 const must = <T>(r: { ok: true; value: T } | { ok: false; error: unknown }): T => {
33 if (!r.ok) throw new Error(JSON.stringify(r.error));
34 return r.value;
35 };
36
37 beforeAll(async () => {
38 dir = await mkdtemp(join(tmpdir(), "forge-tree-fit-"));
39 app = createApp({ dataDir: dir, port: 0 });
40 servers = await serve(app);
41 const u = must(await createUser(app.db, { origin: "seed", trusted: true, username: "alice", email: "[email protected]", password: "a-good-passphrase", adminIfFirst: true }));
42 const repo = must(await createRepo(app, u, { name: "fit", visibility: "public" }));
43 const files = Array.from({ length: 25 }, (_, i) => ({ path: `${DIR}/file-${i}.txt`, content: "x\n" }));
44 files.push({ path: `${DIR}/${WORD}.ts`, content: `const long = "${"c".repeat(400)}";\n`.repeat(30) });
45 must(await commitToBranch(app, u, repo, { message: "seed", files }));
46 const token = createSession(app.db, u.id).token;
47 session = { name: "forge_session", value: token };
48 const cookie = `forge_session=${token}; forge_mode=dev`;
49 const get = async (p: string) => (await fetch(`${servers.url}${p}`, { headers: { cookie } })).text();
50 listing = await get(listPath);
51 file = await get(filePath);
52 }, 60_000);
53 afterAll(async () => {
54 servers.stop();
55 app.close();
56 await rm(dir, { recursive: true, force: true });
57 });
58
59 describe("the files page at 390 px", () => {
60 test("both views render the seeded long content", () => {
61 expect(listing).toContain(WORD);
62 expect(listing.match(/class="row[ "]/g)!.length).toBeGreaterThan(20);
63 expect(file).toContain(WORD);
64 expect(file).toContain('class="code');
65 expect(listing).toContain("data-tree");
66 expect(file).toContain("data-tree");
67 });
68
69 for (const [name, get] of [["listing", () => listing], ["file", () => file]] as const) {
70 test(`the ${name} ships no width over 390 px`, () => {
71 const page = get();
72 expect(page).not.toMatch(/style="[^"]*(?:^|[;\s])(?:min-|max-)?width\s*:/i);
73 for (const m of page.matchAll(/\swidth=["']?(\d+)/gi)) expect(Number(m[1])).toBeLessThanOrEqual(390);
74 const over: string[] = [];
75 for (const css of [base, components, content, ...(page.match(/<style[^>]*>[\s\S]*?<\/style>/g) ?? [])]) {
76 for (const m of css.matchAll(/(?<![-\w(])(?:min-)?width\s*:\s*(-?[\d.]+)(px|rem|em|ch)\b/g)) {
77 if (Number(m[1]) * (m[2] === "px" ? 1 : m[2] === "ch" ? 8 : 16) > 390) over.push(m[0]);
78 }
79 }
80 expect(over).toEqual([]);
81 });
82 }
83
84 test("long names wrap anywhere; code scrolls inside its own box", () => {
85 expect(content).toMatch(/\[data-tree\]\s*\{[^}]*overflow-wrap:\s*(anywhere|break-word)/);
86 expect(content).toMatch(/\[data-tree\] \.row-title[^{]*\{[^}]*white-space:\s*normal/);
87 expect(content).toMatch(/\[data-tree\] \.crumbs[^{]*\{[^}]*flex-wrap:\s*wrap/);
88 expect(content).toMatch(/\.code \{[^}]*overflow-x:\s*auto/);
89 expect(content).toMatch(/\.code-layout > #code-main \{[^}]*min-width:\s*0/);
90 });
91 });
92
93 const found = findChromium();
94 const chromium = found !== undefined && chromiumRuns(found) ? found : undefined;
95 if (chromium === undefined) console.log("SKIPPING: no chromium that starts on this machine, so the files phone look is not measured");
96
97 describe.skipIf(chromium === undefined)("the files page, measured at 390x844", () => {
98 const measure = `(() => {
99 const vw = document.documentElement.clientWidth;
100 const scope = [...document.querySelectorAll("[data-tree], [data-tree] *")].filter((el) => !el.closest(".code, .explorer-panel"));
101 const overflowing = scope.filter((el) => el.getBoundingClientRect().right > vw + 1).slice(0, 8).map((el) => el.tagName.toLowerCase() + "." + el.className);
102 const code = document.querySelector(".code");
103 return JSON.stringify({ scrollWidth: document.documentElement.scrollWidth, viewportWidth: vw, overflowing, code: code === null ? null : { scrolls: code.scrollWidth > code.clientWidth, box: Math.round(code.getBoundingClientRect().right) } });
104 })()`;
105 type Measured = { scrollWidth: number; viewportWidth: number; overflowing: string[]; code: { scrolls: boolean; box: number } | null };
106 for (const which of ["listing", "file"] as const) {
107 test(`${which}: no sideways scroll`, async () => {
108 const m = JSON.parse(await evaluateLoaded(chromium!, `${servers.url}${which === "listing" ? listPath : filePath}`, { width: 390, height: 844 }, [session], measure)) as Measured;
109 console.log(`tree ${which} 390x844: ${JSON.stringify(m)}`);
110 expect(m.overflowing).toEqual([]);
111 expect(m.scrollWidth).toBeLessThanOrEqual(m.viewportWidth);
112 if (which === "file") {
113 expect(m.code?.scrolls).toBe(true);
114 expect(m.code!.box).toBeLessThanOrEqual(m.viewportWidth);
115 }
116 }, 30_000);
117 }
118 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs