Public: anyone can read this; the crew can change it.
The /forges and /forges/new pages fit a 390 px phone: no sideways scroll, the form's fields and long forge names wrap #9397
mason/forge:mason/9372-the-forges-and-forges-new-pages-fit-a-39 → main 5 commits fork
4 files
changed +139
−4
src/web/pages/forges.ts +1 −1
| @@ -135,7 +135,7 @@ export async function forgesPage(ctx: Ctx): Promise<Response> { | ||
| 135 | 135 | const response = page({ |
| 136 | 136 | ctx, |
| 137 | 137 | title: "Forges you sent", |
| 138 | body: html`<div class="narrow-wide"> | |
| 138 | body: html`<div class="narrow-wide" data-forges-page> | |
| 139 | 139 | ${pageHead("Forges you sent", { |
| 140 | 140 | sub: "For whom each is, what it was given, and whether its person has claimed it.", |
| 141 | 141 | actions: action, |
src/web/pages/new-forge.ts +3 −3
| @@ -139,7 +139,7 @@ function formView( | ||
| 139 | 139 | ): Html { |
| 140 | 140 | const { full, quota, repos, crew } = reads; |
| 141 | 141 | if (full) |
| 142 | return html`<div class="narrow-wide"> | |
| 142 | return html`<div class="narrow-wide" data-new-forge-page> | |
| 143 | 143 | ${pageHead("New forge")} |
| 144 | 144 | ${card( |
| 145 | 145 | html`<p role="status">This forge cannot hold another child: ${full}.</p> |
| @@ -149,7 +149,7 @@ function formView( | ||
| 149 | 149 | )} |
| 150 | 150 | </div>`; |
| 151 | 151 | const anon = user === undefined; |
| 152 | return html`<div class="narrow-wide"> | |
| 152 | return html`<div class="narrow-wide" data-new-forge-page> | |
| 153 | 153 | ${pageHead("New forge", { |
| 154 | 154 | sub: anon |
| 155 | 155 | ? "Your own forge: pick a name, and the public apps to start from. Whoever opens the claim link becomes its admin." |
| @@ -388,7 +388,7 @@ function madeView(body: Record<string, unknown>): Html { | ||
| 388 | 388 | const link = body["claimUrl"]; |
| 389 | 389 | const note = body["keyNote"]; |
| 390 | 390 | const name = String(body["name"] ?? ""); |
| 391 | return html`<div class="narrow-wide"> | |
| 391 | return html`<div class="narrow-wide" data-new-forge-page> | |
| 392 | 392 | ${pageHead( |
| 393 | 393 | body["existed"] === true ? `${name} already exists` : `${name} is ready`, |
| 394 | 394 | )} |
src/web/style/content.ts +3
| @@ -152,6 +152,9 @@ a.origin-chip:hover { border-color: var(--border-strong); color: var(--fg); } | ||
| 152 | 152 | font-variant-numeric: tabular-nums; letter-spacing: 0.14em; |
| 153 | 153 | text-align: center; user-select: all; word-break: break-all; |
| 154 | 154 | } |
| 155 | [data-forges-page], [data-new-forge-page] { overflow-wrap: anywhere; } | |
| 156 | [data-new-forge-page] .field .input, [data-new-forge-page] textarea { max-width: 100%; } | |
| 157 | [data-forges-page] .card, [data-new-forge-page] .card { min-width: 0; } | |
| 155 | 158 | [data-apps], [data-apps-page], [data-bet-card], [data-milestone], [data-now] { overflow-wrap: anywhere; } |
| 156 | 159 | [data-bet-card] h2, [data-bet-card] ul, [data-bet-card] p { margin-block: 8px; } |
| 157 | 160 | [data-bet-card] ul { padding-inline-start: 16px; } |
test/forges-fit.test.ts added +132
| @@ -0,0 +1,132 @@ | ||
| 1 | /** | |
| 2 | * The /forges and /forges/new pages fit a 390 px phone (#9372): seeded with | |
| 3 | * long names, a 200-character unbroken "for whom" and many rows, neither page | |
| 4 | * fixes a width over 390 px, long text wraps, and the wide table scrolls in | |
| 5 | * 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 { createRepo } from "../src/actions/repos.ts"; | |
| 12 | import { createApp, type App } from "../src/app.ts"; | |
| 13 | import { createToken } from "../src/core/tokens.ts"; | |
| 14 | import { createUser, getUserByName } from "../src/core/users.ts"; | |
| 15 | import { commitFiles } from "../src/git/write.ts"; | |
| 16 | import { repoDir } from "../src/git/repos.ts"; | |
| 17 | import { serve, type Servers } from "../src/http/server.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 { findChromium } from "../src/looks/capture.ts"; | |
| 22 | import { useChildFetch } from "../src/spawn/clients.ts"; | |
| 23 | import { quietLogs } from "./helpers/globals.ts"; | |
| 24 | import { chromiumRuns, evaluateLoaded } from "./helpers/chrome.ts"; | |
| 25 | ||
| 26 | quietLogs(); | |
| 27 | ||
| 28 | const LONG_FOR = "F".repeat(200); | |
| 29 | const LONG_REPO = "r".repeat(90); | |
| 30 | let dir: string; | |
| 31 | let app: App; | |
| 32 | let servers: Servers; | |
| 33 | let session: { name: string; value: string }; | |
| 34 | const pages: Record<string, string> = {}; | |
| 35 | ||
| 36 | beforeAll(async () => { | |
| 37 | dir = await mkdtemp(join(tmpdir(), "forge-forges-fit-")); | |
| 38 | app = createApp({ dataDir: dir, url: "https://forge.test", port: 0 }); | |
| 39 | servers = await serve(app); | |
| 40 | const made = await createUser(app.db, { origin: "seed", trusted: true, username: "alice", email: "[email protected]", password: "a-good-passphrase", isAdmin: true }); | |
| 41 | if (!made.ok) throw new Error(made.error); | |
| 42 | const alice = getUserByName(app.db, "alice")!; | |
| 43 | const token = createToken(app.db, alice.id, "rw", "rw").token; | |
| 44 | for (const name of ["bakery", LONG_REPO]) { | |
| 45 | const r = await createRepo(app, alice, { name }); | |
| 46 | if (!r.ok) throw new Error(String(r.error)); | |
| 47 | const c = await commitFiles(repoDir(app.reposRoot, "alice", name), { branch: "main", message: "x", files: [{ path: "README.md", content: "# x\n" }], author: { name: "a", email: "[email protected]" } }); | |
| 48 | if (!c.ok) throw new Error("commit"); | |
| 49 | } | |
| 50 | useChildFetch(app, () => Promise.reject(new Error("unreachable"))); | |
| 51 | for (let n = 0; n < 12; n++) { | |
| 52 | const res = await fetch(`${servers.url}/api/v1/forges`, { | |
| 53 | method: "POST", | |
| 54 | headers: { authorization: `Bearer ${token}`, "content-type": "application/json" }, | |
| 55 | body: JSON.stringify({ name: n === 0 ? "n".repeat(39) : `forge-${n}`, for: n < 3 ? LONG_FOR : `Client ${n}`, apps: ["alice/bakery", `alice/${LONG_REPO}`], dryRun: false }), | |
| 56 | }); | |
| 57 | if (res.status !== 201) throw new Error(`spawn ${n}: ${res.status} ${await res.text()}`); | |
| 58 | } | |
| 59 | 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]!; | |
| 60 | session = { name: cookie.slice(0, cookie.indexOf("=")), value: cookie.slice(cookie.indexOf("=") + 1) }; | |
| 61 | const get = async (path: string) => (await fetch(`${servers.url}${path}`, { headers: { cookie } })).text(); | |
| 62 | pages["/forges"] = await get("/forges"); | |
| 63 | pages["/forges/new"] = await get("/forges/new"); | |
| 64 | }, 60_000); | |
| 65 | afterAll(async () => { | |
| 66 | servers.stop(); | |
| 67 | app.close(); | |
| 68 | await rm(dir, { recursive: true, force: true }); | |
| 69 | }); | |
| 70 | ||
| 71 | describe("the forges pages at 390 px", () => { | |
| 72 | test("both pages render the seeded long content", () => { | |
| 73 | expect(pages["/forges"]).toContain(LONG_FOR); | |
| 74 | expect(pages["/forges"]).toContain("n".repeat(39)); | |
| 75 | expect(pages["/forges"]!.match(/data-forge=/g)!.length).toBeGreaterThan(10); | |
| 76 | expect(pages["/forges/new"]).toContain(LONG_REPO); | |
| 77 | expect(pages["/forges/new"]).toContain('id="new-forge"'); | |
| 78 | }); | |
| 79 | ||
| 80 | test("no inline width, and no rule the page ships fixes a width over 390 px", () => { | |
| 81 | for (const page of Object.values(pages)) { | |
| 82 | expect(page).not.toMatch(/style="[^"]*(?:^|[;\s"])(?:min-)?width\s*:/i); | |
| 83 | for (const m of page.matchAll(/\swidth=["']?(\d+)/gi)) expect(Number(m[1])).toBeLessThanOrEqual(390); | |
| 84 | const over: string[] = []; | |
| 85 | for (const css of [base, components, content, ...(page.match(/<style[^>]*>[\s\S]*?<\/style>/g) ?? [])]) { | |
| 86 | for (const m of css.matchAll(/(?<![-\w(])(?:min-)?width\s*:\s*(-?[\d.]+)(px|rem|em|ch)\b/g)) { | |
| 87 | const px = Number(m[1]) * (m[2] === "px" ? 1 : m[2] === "ch" ? 8 : 16); | |
| 88 | if (px > 390) over.push(m[0]); | |
| 89 | } | |
| 90 | } | |
| 91 | expect(over).toEqual([]); | |
| 92 | } | |
| 93 | }); | |
| 94 | ||
| 95 | test("the list wraps its rows, and the side-by-side table scrolls inside its own box", () => { | |
| 96 | expect(pages["/forges"]).toContain('<ul class="list setting-list">'); | |
| 97 | expect(pages["/forges"]).toContain('class="table-scroll"'); | |
| 98 | expect(components).toMatch(/\.setting-list \.row-title[^{]*\{[^}]*overflow-wrap:\s*anywhere/); | |
| 99 | expect(components).toMatch(/\.table-scroll\s*\{[^}]*overflow-x:\s*auto/); | |
| 100 | }); | |
| 101 | ||
| 102 | test("long-text containers wrap anywhere", () => { | |
| 103 | for (const attr of ["data-forges-page", "data-new-forge-page"]) { | |
| 104 | const rule = content.match(new RegExp(`(?:^|\\n)([^\\n{]*\\[${attr}\\][^\\n{]*)\\{([^}]*)\\}`)); | |
| 105 | expect(rule).not.toBeNull(); | |
| 106 | expect(rule![2]).toMatch(/overflow-wrap:\s*(?:anywhere|break-word)/); | |
| 107 | } | |
| 108 | expect(pages["/forges"]).toContain("data-forges-page"); | |
| 109 | expect(pages["/forges/new"]).toContain("data-new-forge-page"); | |
| 110 | }); | |
| 111 | }); | |
| 112 | ||
| 113 | const found = findChromium(); | |
| 114 | const chromium = found !== undefined && chromiumRuns(found) ? found : undefined; | |
| 115 | if (chromium === undefined) console.log("SKIPPING: no chromium that starts on this machine, so the forges phone look is not measured"); | |
| 116 | ||
| 117 | describe.skipIf(chromium === undefined)("the forges pages, measured at 390x844", () => { | |
| 118 | const measure = `(() => { | |
| 119 | const vw = document.documentElement.clientWidth; | |
| 120 | const scroller = (el) => el.closest(".table-scroll") !== null; | |
| 121 | const overflowing = [...document.querySelectorAll("main *")].filter((el) => !scroller(el) && el.getBoundingClientRect().right > vw + 1).slice(0, 8).map((el) => el.tagName.toLowerCase() + "." + el.className); | |
| 122 | return JSON.stringify({ scrollWidth: document.documentElement.scrollWidth, viewportWidth: vw, overflowing }); | |
| 123 | })()`; | |
| 124 | for (const path of ["/forges", "/forges/new"]) { | |
| 125 | test(`${path}: no sideways scroll`, async () => { | |
| 126 | const m = JSON.parse(await evaluateLoaded(chromium!, `${servers.url}${path}`, { width: 390, height: 844 }, [session], measure)) as { scrollWidth: number; viewportWidth: number; overflowing: string[] }; | |
| 127 | console.log(`forges ${path} 390x844: ${JSON.stringify(m)}`); | |
| 128 | expect(m.overflowing).toEqual([]); | |
| 129 | expect(m.scrollWidth).toBeLessThanOrEqual(m.viewportWidth); | |
| 130 | }, 30_000); | |
| 131 | } | |
| 132 | }); |
new above
offline