Public: anyone can read this; the crew can change it.
An issue's page fits a 390 px phone: its title, body and conversation wrap instead of scrolling sideways #9368
mason/forge:mason/9345-an-issue-s-page-fits-a-390-px-phone-its → main 7 commits fork 1 thread · 1 unresolved
3 files
changed +121
−0
docs/design/areas/tell.md +4
| @@ -16,3 +16,7 @@ A muted line on a client's app row, `Finished <time>: <title>`, for the app's | ||
| 16 | 16 | newest merged pull. It sits with `client-app-about`, `client-app-agents` and |
| 17 | 17 | `client-app-doing`; it uses `muted` and adds no colour or size. The |
| 18 | 18 | terminal says the same words. |
| 19 | ||
| 20 | ## An issue's page on a 390 px phone (#9345) | |
| 21 | ||
| 22 | The page does not scroll sideways: the title (`.page-head h1`) wraps with `overflow-wrap: anywhere`, the body and every comment sit in `.prose` (also `anywhere`), `.mono` wraps, and `.split` is one `minmax(0, 1fr)` column below 960 px (all from #9327). The page already fit, so `tellPage` is unchanged; `test/issue-phone-fit.test.ts` pins it with a 300-character unbroken word in the title, body and twelve comments. No new class. `/preview-admin/sample/issues/1` joins the preview's owner looks at desk and phone. Those looks are taken as the owner (`looks/service.ts`), so `GET …/pulls/:n/looks` lists them only to a writer (`looks/readable.ts`). | |
src/spawn/preview-looks.ts +4
| @@ -60,6 +60,9 @@ export const PREVIEW_ISSUES_PAGE = `${PREVIEW_REPO_HOME}/issues`; | ||
| 60 | 60 | /** The pulls list, whose long titles must wrap at a 390 px phone (#9346). */ |
| 61 | 61 | export const PREVIEW_PULLS_PAGE = `${PREVIEW_REPO_HOME}/pulls`; |
| 62 | 62 | |
| 63 | /** An issue's page, whose title, body and conversation must wrap at a 390 px phone (#9345). */ | |
| 64 | export const PREVIEW_ISSUE_PAGE = `${PREVIEW_REPO_HOME}/issues/1`; | |
| 65 | ||
| 63 | 66 | /** The owner's resilience page, whose protections and test paths must wrap at a 390 px phone (#9328). */ |
| 64 | 67 | export const PREVIEW_RESILIENCE_PAGE = "/resilience"; |
| 65 | 68 | |
| @@ -108,6 +111,7 @@ export const PREVIEW_OWNER_LOOKS: readonly OwnerLook[] = [ | ||
| 108 | 111 | PREVIEW_MILESTONES_PAGE, |
| 109 | 112 | PREVIEW_WAVES_PAGE, |
| 110 | 113 | PREVIEW_PULLS_PAGE, |
| 114 | PREVIEW_ISSUE_PAGE, | |
| 111 | 115 | PREVIEW_CHANGELOG_PAGE, |
| 112 | 116 | PREVIEW_NEXT_PAGE, |
| 113 | 117 | PREVIEW_COMMITS_PAGE, |
test/issue-phone-fit.test.ts added +113
| @@ -0,0 +1,113 @@ | ||
| 1 | /** | |
| 2 | * An issue's page fits a 390 px phone (#9345): the preview seed's issue, given a | |
| 3 | * long title, a 300-character unbroken word in its body and a comment holding a 300-character | |
| 4 | * unbroken word, ships no fixed width over 390 px, wraps its long text, and | |
| 5 | * (where a Chromium starts) does not scroll sideways. | |
| 6 | */ | |
| 7 | import { afterAll, beforeAll, describe, expect, test } from "bun:test"; | |
| 8 | import { createHmac } from "node:crypto"; | |
| 9 | import { mkdtemp, rm } from "node:fs/promises"; | |
| 10 | import { tmpdir } from "node:os"; | |
| 11 | import { join } from "node:path"; | |
| 12 | import { createApp, type App } from "../src/app.ts"; | |
| 13 | import { serve, type Servers } from "../src/http/server.ts"; | |
| 14 | import { addComment } from "../src/core/issues.ts"; | |
| 15 | import { createSession } from "../src/core/sessions.ts"; | |
| 16 | import { findChromium } from "../src/looks/capture.ts"; | |
| 17 | import { PREVIEW_ISSUE_PAGE, PREVIEW_OWNER_LOOKS } from "../src/spawn/preview-looks.ts"; | |
| 18 | import { previewAdmin, seedPreview } from "../src/spawn/preview-seed.ts"; | |
| 19 | import { base as elements, utilities as base } from "../src/web/style/base.ts"; | |
| 20 | import { components } from "../src/web/style/components.ts"; | |
| 21 | import { content } from "../src/web/style/content.ts"; | |
| 22 | import { chromiumRuns, evaluateLoaded } from "./helpers/chrome.ts"; | |
| 23 | ||
| 24 | const KEY = "issue-phone-fit-key"; | |
| 25 | const WORD = "w".repeat(300); | |
| 26 | const TITLE = `Make every long and winding issue title wrap ${"t".repeat(120)} and many words after it`; | |
| 27 | let dir: string; | |
| 28 | let app: App; | |
| 29 | let servers: Servers; | |
| 30 | let page: string; | |
| 31 | ||
| 32 | beforeAll(async () => { | |
| 33 | dir = await mkdtemp(join(tmpdir(), "forge-issue-fit-")); | |
| 34 | app = createApp({ dataDir: dir, port: 0, previewIdentityKey: KEY }); | |
| 35 | const seeded = await seedPreview(app, { FORGE_APP_ENV: "preview" }); | |
| 36 | if (!seeded.ok) throw new Error(seeded.error); | |
| 37 | const admin = previewAdmin(app)!; | |
| 38 | const number = Number(PREVIEW_ISSUE_PAGE.split("/").pop()); | |
| 39 | const issue = app.db.query("SELECT id FROM issue WHERE number = ?1 AND id NOT IN (SELECT issue_id FROM pull)").get(number) as { id: string }; | |
| 40 | app.db.query("UPDATE issue SET title = ?1, body = ?2 WHERE id = ?3").run(TITLE, `Body ${WORD} https://example.com/${WORD}`, issue.id); | |
| 41 | for (let i = 0; i < 12; i++) addComment(app.db, { issueId: issue.id, authorId: admin.id, body: `Row ${String(i)} ${WORD} https://example.com/${WORD}` }); | |
| 42 | servers = await serve(app); | |
| 43 | const said = `u1|trevato|admin|${Date.now() + 60_000}`; | |
| 44 | const headers = { "x-forge-identity": said, "x-forge-signature": createHmac("sha256", KEY).update(said).digest("base64url") }; | |
| 45 | page = await (await fetch(`${servers.url}${PREVIEW_ISSUE_PAGE}`, { headers })).text(); | |
| 46 | }, 30_000); | |
| 47 | afterAll(async () => { | |
| 48 | servers.stop(); | |
| 49 | app.close(); | |
| 50 | await rm(dir, { recursive: true, force: true }); | |
| 51 | }); | |
| 52 | ||
| 53 | /** Every `width`/`min-width` in `css` that fixes more than 390 px, as written. */ | |
| 54 | const widthsOver390 = (css: string): string[] => | |
| 55 | [...css.matchAll(/(?<![-\w(])(?:min-)?width\s*:\s*(-?[\d.]+)(px|rem|em|ch)\b/g)] | |
| 56 | .filter((m) => Number(m[1]) * (m[2] === "px" ? 1 : m[2] === "ch" ? 8 : 16) > 390) | |
| 57 | .map((m) => m[0]); | |
| 58 | ||
| 59 | describe("an issue's page at 390 px", () => { | |
| 60 | test("the seeded long content is on the page", () => { | |
| 61 | expect(page).toContain(TITLE); | |
| 62 | expect(page).toContain(WORD); | |
| 63 | expect(page.match(new RegExp(WORD, "g"))!.length).toBeGreaterThan(12); | |
| 64 | }); | |
| 65 | ||
| 66 | test("no inline width and no rule the page ships fixes a width over 390 px", () => { | |
| 67 | for (const m of page.matchAll(/\swidth=["']?(\d+)/gi)) expect(Number(m[1])).toBeLessThanOrEqual(390); | |
| 68 | expect(page).not.toMatch(/style="[^"]*(?:^|[;\s])min-width\s*:/i); | |
| 69 | const sheets = [base, components, content, ...(page.match(/<style[^>]*>[\s\S]*?<\/style>/g) ?? [])]; | |
| 70 | const inline = [...page.matchAll(/style="([^"]*)"/g)].map((m) => m[1]!); | |
| 71 | expect([...inline, ...sheets].flatMap(widthsOver390)).toEqual([]); | |
| 72 | }); | |
| 73 | ||
| 74 | test("the long-text containers wrap anywhere", () => { | |
| 75 | expect(components).toMatch(/\.page-head h1[^{]*\{[^}]*overflow-wrap:\s*(anywhere|break-word)/); | |
| 76 | expect(elements).toMatch(/\.mono[^{]*\{[^}]*overflow-wrap:\s*(anywhere|break-word)/); | |
| 77 | expect(content).toMatch(/\.prose\s*\{[^}]*overflow-wrap:\s*(anywhere|break-word)/); | |
| 78 | }); | |
| 79 | }); | |
| 80 | ||
| 81 | const found = findChromium(); | |
| 82 | const chromium = found !== undefined && chromiumRuns(found) ? found : undefined; | |
| 83 | if (chromium === undefined) console.log("SKIPPING: no chromium that starts here, so the issue's phone look is not measured"); | |
| 84 | ||
| 85 | describe.skipIf(chromium === undefined)("an issue's page, measured", () => { | |
| 86 | const measure = `(() => { | |
| 87 | const vw = document.documentElement.clientWidth; | |
| 88 | const clipped = (el) => { for (let p = el.parentElement; p && p !== document.body; p = p.parentElement) { const o = getComputedStyle(p).overflowX; if (o !== "visible") return true; } return false; }; | |
| 89 | const overflowing = [...document.querySelectorAll(".page-head, .page-head *, .split, .split *")].filter((el) => el.getBoundingClientRect().right > vw + 1 && !clipped(el) && getComputedStyle(el).clipPath === "none" && getComputedStyle(el).position !== "fixed").slice(0, 8).map((el) => el.tagName.toLowerCase() + "." + String(el.className)); | |
| 90 | return JSON.stringify({ scrollWidth: document.documentElement.scrollWidth, viewportWidth: vw, overflowing }); | |
| 91 | })()`; | |
| 92 | // The layout's own chrome (tabs, off-canvas menus) is web-phone.test.ts's to hold; the page's content is measured here. | |
| 93 | const look = async (width: number, height: number) => { | |
| 94 | const cookies = [{ name: "forge_session", value: createSession(app.db, previewAdmin(app)!.id).token }]; | |
| 95 | const m = JSON.parse(await evaluateLoaded(chromium!, `${servers.url}${PREVIEW_ISSUE_PAGE}`, { width, height }, cookies, measure)) as { scrollWidth: number; viewportWidth: number; overflowing: string[] }; | |
| 96 | console.log(`issue look ${width}x${height}: ${JSON.stringify(m)}`); | |
| 97 | return m; | |
| 98 | }; | |
| 99 | test("phone, 390x844: no sideways scroll", async () => { | |
| 100 | const m = await look(390, 844); | |
| 101 | expect(m.overflowing).toEqual([]); | |
| 102 | expect(m.scrollWidth).toBeLessThanOrEqual(m.viewportWidth); | |
| 103 | }, 30_000); | |
| 104 | test("desk, 1280x800: no sideways scroll", async () => { | |
| 105 | const m = await look(1280, 800); | |
| 106 | expect(m.scrollWidth).toBeLessThanOrEqual(m.viewportWidth); | |
| 107 | }, 30_000); | |
| 108 | }); | |
| 109 | ||
| 110 | test("a forge preview takes the issue's page at desk and phone", () => { | |
| 111 | expect(PREVIEW_ISSUE_PAGE).toBe("/preview-admin/sample/issues/1"); | |
| 112 | expect(PREVIEW_OWNER_LOOKS).toContainEqual({ page: PREVIEW_ISSUE_PAGE, kind: "phone" }); | |
| 113 | }); |
new above
offline
Fine as written. The pull description, not this doc, is where the phone-look link and the one-line verdict still have to go (box 3).