Public: anyone can read this; the crew can change it.
A component gallery at /design/components, where the parts the cold-read audit blames are judged #16644
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/5912-a-component-gallery-at-design-components → main 0 commits fork 4 threads · 4 unresolved
11 files
changed +288
−1
- docs/design/areas/gallery.md
- docs/design/audit.md
- docs/features/design-gallery.md
- src/http/server.ts
- src/tui/screens/design_gallery.ts
- src/web/pages/design-components.ts
- src/web/studio/design.ts
- test/design-components.test.ts
- test/design-gallery-door.test.ts
- test/design-theme.test.ts
- test/palette-roster.test.ts
docs/design/areas/gallery.md added +10
| @@ -0,0 +1,10 @@ | ||
| 1 | # Component gallery | |
| 2 | ||
| 3 | `/design/gallery` (`designComponentsPage` in `src/web/pages/design-components.ts`) draws every component §5 names once, at the window's own width (a media query reads the window, so judge the phone layout with a 390 px window), so a part the cold-read audit blames is judged in one place. `galleryCss` there holds every rule below. | |
| 4 | ||
| 5 | - `.gallery-index` — the row of links to each component's section. | |
| 6 | - `.gallery-part` — one component: its name, then its frame. | |
| 7 | - `.gallery-frame` — the sample, ended by a hairline. | |
| 8 | - `.gallery-line` — a wrapping row of samples side by side. | |
| 9 | - `.gallery-col` — a stack of samples, one under the other. | |
| 10 | - `.gallery-static` — lets a dialog or palette sit in the page, not over it. |
docs/design/audit.md +1
| @@ -82,6 +82,7 @@ Machine routes are not pages and have no entry: `/audit.csv`, | ||
| 82 | 82 | - `/releases` — `pages/releases.ts` · the forge's kept releases and rollback · `/settings/backups` (both are "go back") · none seen. |
| 83 | 83 | - `/design` — `studio/design.ts` · the forge's theme: colour and scale fields, four side-by-side samples, publish and revert for an admin, history; a non-admin reads it · `/design/components` · none seen. |
| 84 | 84 | - `/design/components` — `studio/design.ts` · the forge's components drawn with the live theme, searchable, signed in · `/design` · none seen. |
| 85 | - `/design/gallery` — `pages/design-components.ts` · every component §5 names, once at the window's width, public and static, so a part the cold-read audit blames is judged in one place · `/design/components` (the live-theme explorer, signed in) · none seen. | |
| 85 | 86 | - `/changelog` — `pages/changelog.ts` · the last 30 releases with their dates and pulls, public · `/releases` (the signed-in kept releases) · none seen. |
| 86 | 87 | - `/displays` — `pages/displays.ts` · every display the viewer may read, each with its layout, repository and showcased demos; a stranger signs in first · none yet (read only; a repository's display is its own page) · none seen. |
| 87 | 88 | - `/api` — `pages/api.ts` · the forge's OpenAPI operations by area, with search and Try it, public · the footer, the OpenAPI document, the terminal's API screen · none seen. An app's own spec is its `/:owner/:name/api` tab. |
docs/features/design-gallery.md added +13
| @@ -0,0 +1,13 @@ | ||
| 1 | --- | |
| 2 | topic: Getting around: keys, the palette and search | |
| 3 | row: The component gallery: every part the design names, on one page | |
| 4 | --- | |
| 5 | # The component gallery | |
| 6 | ||
| 7 | Open `/design/gallery` in the web UI, signed in or not. It draws every component that `docs/DESIGN.md` §5 names, once each, so a part the cold-read audit blames can be judged in one place. A section's link in the index at the top jumps to it. | |
| 8 | ||
| 9 | The frames are as wide as your window, because a media query reads the window. To judge the phone layout, make the window 390 px wide. | |
| 10 | ||
| 11 | The page is static: it reads nothing from your request or the database. The live-theme explorer at `/design/components` (signed in) draws the same parts with the forge's current theme. | |
| 12 | ||
| 13 | In the terminal, open the palette and choose "Component gallery". It says how many components the gallery holds and where; the page itself is web-only, since it is about how things look. |
src/http/server.ts +2
| @@ -47,6 +47,7 @@ import { prerenderComments } from "../web/prerender.ts"; | ||
| 47 | 47 | import { heapCensusSubmit, systemPage, systemStream } from "../web/pages/system.ts"; |
| 48 | 48 | import { bottleneckPage } from "../web/pages/bottleneck.ts"; |
| 49 | 49 | import { contributePage } from "../web/pages/contribute.ts"; |
| 50 | import { designComponentsPage } from "../web/pages/design-components.ts"; | |
| 50 | 51 | import { pipelinePage } from "../web/pages/pipeline.ts"; |
| 51 | 52 | import { adminDataPage, appDataCsv, appDataPage, dataPage } from "../web/pages/data.ts"; |
| 52 | 53 | import { fleetAct, fleetReceipt, fleetUndo } from "../web/pages/fleet-ops.ts"; |
| @@ -1311,6 +1312,7 @@ export function buildRouter(): Router<Handler> { | ||
| 1311 | 1312 | router.add("GET", "/boards/:slug", boardShow); |
| 1312 | 1313 | router.add("GET", "/boards/:slug/live", boardLive); |
| 1313 | 1314 | router.add("POST", "/boards/:slug/:op", boardPost); |
| 1315 | router.add("GET", "/design/gallery", designComponentsPage); | |
| 1314 | 1316 | router.add("GET", "/admin/data", adminDataPage); |
| 1315 | 1317 | router.add("GET", "/admin/limits", limitsPage); |
| 1316 | 1318 | router.add("GET", "/admin/flows", allFlowsPage); |
src/tui/screens/design_gallery.ts added +16
| @@ -0,0 +1,16 @@ | ||
| 1 | /** The component gallery's palette entry: where it is and how many parts it holds. */ | |
| 2 | ||
| 3 | import type { PaletteEntry } from "./entries.ts"; | |
| 4 | import { samples } from "../../web/pages/design-components.ts"; | |
| 5 | ||
| 6 | /** The one sentence the toast says. */ | |
| 7 | export const galleryLine = (): string => `${samples.length} components, drawn once each at /design/gallery`; | |
| 8 | ||
| 9 | export const entry: PaletteEntry = { | |
| 10 | rank: 900, | |
| 11 | id: "design-gallery", | |
| 12 | title: "Component gallery", | |
| 13 | hint: "every component the design names", | |
| 14 | offered: () => true, | |
| 15 | run: (_session, ctx) => ctx.toast(galleryLine(), "default"), | |
| 16 | }; |
src/web/pages/design-components.ts added +137
| @@ -0,0 +1,137 @@ | ||
| 1 | /** | |
| 2 | * The component gallery (`/design/gallery`): every component docs/DESIGN.md | |
| 3 | * §5 names, drawn by the function that draws it on the real pages (or, where the | |
| 4 | * part belongs to one page, the markup that page gives its class), once, at the | |
| 5 | * window's own width: a media query reads the window, so to judge the phone | |
| 6 | * layout, make the window 390 px wide. When the cold-read audit blames a heading, a button or a | |
| 7 | * list, this is where it is judged. Nothing here reads the database or the | |
| 8 | * request: it is the same page for everyone, and every sample is static text. | |
| 9 | */ | |
| 10 | ||
| 11 | import { notePhase, takeSessionTime } from "../../core/route_timing.ts"; | |
| 12 | import { THEMES } from "../../design/themes.ts"; | |
| 13 | import type { Ctx } from "../../http/context.ts"; | |
| 14 | import { Html, html, raw } from "../html.ts"; | |
| 15 | import { pageHead } from "../chrome.ts"; | |
| 16 | import { page } from "../layout.ts"; | |
| 17 | import { | |
| 18 | labelCss, avatar, badge, btn, card, counts, crumbs, disclosure, dot, empty, field, iconBtn, kbd, labelChip, | |
| 19 | listCard, menu, meter, nameMark, pager, pill, row, seg, sha, stat, stateBadge, tabs, tlComment, | |
| 20 | tlEvent, userTag, verdictBadge, runStateBadge, envStateBadge, | |
| 21 | } from "../ui.ts"; | |
| 22 | ||
| 23 | const r = (markup: string): Html => raw(markup); | |
| 24 | ||
| 25 | const sampleRows = [ | |
| 26 | row({ href: "#", title: "Make the feed answer in under 50 ms", meta: html`#41 · opened by <b>scout</b>`, state: "open" }), | |
| 27 | row({ href: "#", title: "Escape every output", meta: html`#38 · merged`, state: "merged" }), | |
| 28 | ]; | |
| 29 | ||
| 30 | /** One entry per row of the §5 table, keyed by the name in bold there. */ | |
| 31 | export const samples: readonly (readonly [name: string, sample: Html])[] = [ | |
| 32 | ["page head", pageHead("A page title", { sub: "One plain sentence on what the page is for." })], | |
| 33 | ["button", html`<div class="gallery-line">${btn("Primary", { variant: "primary" })}${btn("Secondary", { variant: "secondary" })}${btn("Outline", { variant: "outline" })}${btn("Ghost", { variant: "ghost" })}${btn("Danger", { variant: "danger" })}${btn("Small", { size: "sm" })}${btn("Disabled", { disabled: true })}</div>`], | |
| 34 | ["icon button", iconBtn("check", "Mark done")], | |
| 35 | ["input / textarea / select", html`<div class="gallery-col"><input class="input" aria-label="Text" value="An input" /><textarea class="input" aria-label="Notes" rows="2">A textarea</textarea><select class="input" aria-label="Choice"><option>A select</option></select></div>`], | |
| 36 | ["form field", field({ label: "Name", name: "gallery-name", value: "scout", hint: "Lowercase, no spaces." })], | |
| 37 | ["checkbox", r(`<label class="check"><input type="checkbox" checked /> Notify me</label>`)], | |
| 38 | ["badge", html`<div class="gallery-line">${badge("default")}${badge("accent", { tone: "attn" })}${badge("danger", { tone: "danger" })}${badge("outline", { variant: "outline" })}${stateBadge("open")}</div>`], | |
| 39 | ["stat", html`<div class="stats">${stat({ label: "Ships", value: 12, note: "this week" })}${stat({ label: "Forks", value: 3 })}</div>`], | |
| 40 | ["label chip", labelChip({ name: "bug", color: "d73a4a" })], | |
| 41 | ["author", html`<div class="gallery-line">${userTag("scout")}</div>`], | |
| 42 | ["name mark", html`${nameMark("crew")}${nameMark("owner")}`], | |
| 43 | ["avatar", html`<div class="gallery-line">${avatar("scout")}${avatar("scout", "lg")}</div>`], | |
| 44 | ["count", counts([{ icon: "comment", value: 4, label: "comments" }])], | |
| 45 | ["stat pill", html`${pill(7)} ${pill(2, "accent")} ${pill(9, "danger")}`], | |
| 46 | ["status dot", html`${dot("success")} ${dot("attn")} ${dot("danger")}`], | |
| 47 | ["sha", sha("0123456789abcdef0123456789abcdef01234567")], | |
| 48 | ["progress bar", r(`<progress max="10" value="6" aria-label="6 of 10 done"></progress>`)], | |
| 49 | ["meter", meter(64, "Budget used")], | |
| 50 | ["kbd", kbd(["g", "i"])], | |
| 51 | ["card", card(html`<p>Body text inside a card.</p><p class="muted">A second line, so the card holds more than one sentence.</p>`, { head: html`<h3>Card head</h3>`, foot: html`<span>foot</span>` })], | |
| 52 | ["list row", listCard(sampleRows)], | |
| 53 | ["edit row", r(`<form class="edit-row" onsubmit="return false"><input class="input" aria-label="Title" value="Rename me" /><button class="btn" type="button">Save</button></form>`)], | |
| 54 | ["colour field", html`<label class="color-field"><input type="color" value="${THEMES.light.tokens.accent}" aria-label="Colour" /> <span>accent</span></label>`], | |
| 55 | ["table", r(`<table class="table"><thead><tr><th>Name</th><th>State</th></tr></thead><tbody><tr><td>feed</td><td>live</td></tr><tr><td>map</td><td>live</td></tr></tbody></table>`)], | |
| 56 | ["tabs", tabs([{ label: "Issues", href: "#", count: 4, current: true }, { label: "Pulls", href: "#", current: false }], "Gallery tabs")], | |
| 57 | ["segmented control", seg([{ label: "Open", href: "#", current: true }, { label: "Closed", href: "#", current: false }])], | |
| 58 | ["menu", menu({ trigger: "Actions", items: [{ label: "Rename", href: "#" }, { label: "Archive", href: "#" }] })], | |
| 59 | ["disclosure", disclosure("More detail", html`<p>Hidden until opened.</p>`)], | |
| 60 | ["dialog", r(`<div class="dialog gallery-static" role="dialog" aria-label="Sample dialog"><div class="dialog-head"><h2>Delete this?</h2></div><div class="dialog-foot"><button class="btn" type="button">Cancel</button></div><p>Delete this?</p></div>`)], | |
| 61 | ["tooltip", r(`<span class="btn" data-tip="A tip, on hover and focus" tabindex="0">Hover me</span>`)], | |
| 62 | ["toast / flash", r(`<div class="toast" role="status">Saved.</div>`)], | |
| 63 | ["command palette", r(`<div class="dialog palette gallery-static"><input class="input" aria-label="Search" placeholder="Type a command" /><div class="palette-list" role="listbox" aria-label="Results"></div></div>`)], | |
| 64 | ["breadcrumb", crumbs([{ label: "forge", href: "#" }, { label: "design", href: "#" }, { label: "components" }])], | |
| 65 | ["pagination", pager({ prev: "#", next: "#", note: "Page 2" })], | |
| 66 | ["timeline item", html`${tlEvent({ icon: "check", body: html`<span>scout closed this</span>` })}${tlComment(card(html`<p>A comment.</p><p class="muted">Posted just now.</p>`))}`], | |
| 67 | ["empty state", empty({ icon: "lock", title: "Nothing here yet", note: "It will show up when it happens." })], | |
| 68 | ["diff file", r(`<div class="diff-file"><div class="diff-file-head">src/a.ts</div><pre class="code">+ added\n- removed</pre></div>`)], | |
| 69 | ["code block", r(`<pre class="code">const x = 1;</pre>`)], | |
| 70 | ["prose", r(`<div class="prose"><h3>A heading</h3><p>A paragraph with <a href="#">a link</a> and <code>code</code>.</p></div>`)], | |
| 71 | ["settings shell", r(`<div class="settings"><nav class="settings-nav"><a href="#">Profile</a></nav><div class="settings-main"><p>Main column</p></div></div>`)], | |
| 72 | ["repo header", r(`<header class="repo-head"><h2>trevato/forge</h2></header>`)], | |
| 73 | ["where strip", r(`<div class="where"><span class="where-place">production</span></div>`)], | |
| 74 | ["live-browse banner", r(`<p class="live-note">Reading the live app, not a commit.</p>`)], | |
| 75 | ["where-it-lives block", r(`<div class="where-block"><p>Lives at forge.example</p></div>`)], | |
| 76 | ["mirror stages", r(`<div class="list stages" aria-live="polite"><div class="row"><div class="row-main"><span class="row-title">Fetch</span></div></div></div>`)], | |
| 77 | ["origin chip", r(`<span class="repo-origin"><span class="origin-chip">from github</span></span>`)], | |
| 78 | ["origin state badge", badge("mirrored")], | |
| 79 | ["imported author", r(`<span class="byline origin-by"><span class="byline-name">octocat</span></span>`)], | |
| 80 | ["pin toggle", r(`<div class="repo-where"><form class="where-pin" onsubmit="return false"><button class="btn" type="button">Pin</button></form></div>`)], | |
| 81 | ["device code", r(`<code class="device-code">ABCD-1234</code>`)], | |
| 82 | ["sticky action", r(`<div class="sticky-action"><button class="btn" data-variant="primary" type="button">Save</button></div>`)], | |
| 83 | ["count group", r(`<div class="counts"><span class="count">3 issues</span><span class="count">1 pull</span></div>`)], | |
| 84 | ["file explorer", r(`<div class="code-layout"><div class="explorer-panel"><div class="explorer"><a class="ex-dir" href="#">src</a><a class="ex-file" href="#">main.ts</a></div></div></div>`)], | |
| 85 | ["fuzzy finder", r(`<div class="dialog palette finder gallery-static"><input class="input" aria-label="Find a file" placeholder="Find a file" /><div class="palette-list" role="listbox" aria-label="Files"></div></div>`)], | |
| 86 | ["file editor", r(`<form class="editor-form" onsubmit="return false"><div class="editor-head">main.ts</div><div class="editor-wrap"><textarea class="editor" aria-label="File" rows="3">const x = 1;</textarea></div></form>`)], | |
| 87 | ["branch row", r(`<div class="branch-row"><span>main</span><span class="branch-div"><span class="ahead">2</span><span class="behind">0</span></span></div>`)], | |
| 88 | ["code hit", r(`<div class="code-hit"><span class="code-line">const <mark>feed</mark> = 1;</span></div>`)], | |
| 89 | ["verdict badge", html`${verdictBadge("approved")} ${verdictBadge("changes_requested")}`], | |
| 90 | ["reviews chip", r(`<span class="reviews-chip">2 reviews</span>`)], | |
| 91 | ["review card", r(`<div class="card review-card"><div class="review-verdicts">approved by atlas</div></div>`)], | |
| 92 | ["review thread", card(html`<p class="dc-review">Rename this.</p><p class="muted">Open · on src/a.ts</p>`)], | |
| 93 | ["propose card", r(`<fieldset class="editor-target propose"><legend>Propose</legend><span class="propose-line">to a new branch</span></fieldset>`)], | |
| 94 | ["run state badge", html`${runStateBadge("ok")} ${runStateBadge("failed")} ${runStateBadge("running")}`], | |
| 95 | ["env state badge", html`${envStateBadge("running")} ${envStateBadge("deploying")} ${envStateBadge("failed")}`], | |
| 96 | ["app strip", r(`<div class="app-strip"><span>lab</span><span>production</span></div>`)], | |
| 97 | ["environment card", r(`<div class="card env-card"><div class="env-facts">serving · 3 min ago</div><div class="env-error">last build failed</div></div>`)], | |
| 98 | ["checks line", r(`<p class="checks-line"><span class="ok">12 passed</span> <span class="bad">1 failed</span> <span class="now">1 running</span></p>`)], | |
| 99 | ["run log", r(`<pre class="run-log">bun test v1\n 12 pass\n</pre>`)], | |
| 100 | ["assignee card", r(`<div class="card"><form class="edit-row" onsubmit="return false"><select class="input" aria-label="Assignee"><option>scout</option></select></form></div>`)], | |
| 101 | ["inbox", listCard(sampleRows)], | |
| 102 | ["look", r(`<div class="looks"><figure class="look"><figcaption>Home at 390</figcaption></figure></div>`)], | |
| 103 | ["board", r(`<div class="board"><div class="board-grid"><div class="board-region">A region</div></div></div>`)], | |
| 104 | ["stacked bar chart", r(`<div class="plots"><div class="plot"><span class="plot-name">Spend</span></div><div class="plot-legend">by day</div></div>`)], | |
| 105 | ["chart", r(`<div class="chart-box"><svg class="chart" viewBox="0 0 100 20" role="img" aria-label="A rising line"><polyline fill="none" stroke="currentColor" points="0,18 40,12 100,2"/></svg></div>`)], | |
| 106 | ]; | |
| 107 | ||
| 108 | const slug = (name: string) => name.replace(/[^a-z0-9]+/gi, "-").replace(/^-|-$/g, "").toLowerCase(); | |
| 109 | ||
| 110 | const galleryCss = /* css */ ` | |
| 111 | .gallery-index{display:flex;flex-wrap:wrap;gap:4px 12px;margin:0 0 16px} | |
| 112 | .gallery-part{margin:0 0 24px;min-width:0} | |
| 113 | .gallery-part h2{font-size:15px;margin:0 0 8px} | |
| 114 | .gallery-frame{min-width:0;max-width:100%;padding:0 0 12px;border-bottom:1px solid var(--border);overflow-x:auto} | |
| 115 | .gallery-line{display:flex;flex-wrap:wrap;gap:8px;align-items:center} | |
| 116 | .gallery-col{display:grid;gap:8px} | |
| 117 | .gallery-static{position:static;display:block;transform:none;margin:0} | |
| 118 | `; | |
| 119 | ||
| 120 | export function galleryBody(): Html { | |
| 121 | return html`${pageHead("Component gallery", { sub: `The ${samples.length} components docs/DESIGN.md §5 names, each drawn once, so a part the cold-read audit blames can be judged.` })} | |
| 122 | <nav class="gallery-index" aria-label="Components">${samples.map(([name]) => html`<a href="#c-${slug(name)}">${name}</a>`)}</nav> | |
| 123 | ${samples.map( | |
| 124 | ([name, sample]) => html`<section class="gallery-part" id="c-${slug(name)}" data-component="${name}"> | |
| 125 | <h2>${name}</h2> | |
| 126 | <div class="gallery-frame">${sample}</div> | |
| 127 | </section>`, | |
| 128 | )}`; | |
| 129 | } | |
| 130 | ||
| 131 | export function designComponentsPage(ctx: Ctx): Response { | |
| 132 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); | |
| 133 | const rendering = performance.now(); | |
| 134 | const res = page({ ctx, title: "Component gallery", wide: true, styleCss: galleryCss + labelCss([{ name: "bug", color: "d73a4a" }]), body: galleryBody() }); | |
| 135 | notePhase(ctx.request, "render", performance.now() - rendering); | |
| 136 | return res; | |
| 137 | } |
src/web/studio/design.ts +1 −1
| @@ -578,7 +578,7 @@ export function componentsPage(ctx: Ctx): Response { | ||
| 578 | 578 | const cell = (e: Entry, mode: "light" | "dark"): Html => |
| 579 | 579 | html`<div class="cx-cell cx-${mode}"><p class="small">${mode}</p>${e.render()}</div>`; |
| 580 | 580 | const body = html`${homeTabs("design")}${pageHead("Components", { sub: "The forge's own components against the theme" })} |
| 581 | <p class="small"><a href="/design">Theme editor</a>${parsed.ok ? "" : html` · <span role="alert">${parsed.error}</span>`}</p> | |
| 581 | <p class="small"><a href="/design">Theme editor</a> · <a href="/design/gallery">Component gallery</a>${parsed.ok ? "" : html` · <span role="alert">${parsed.error}</span>`}</p> | |
| 582 | 582 | <form method="get" action="/design/components" role="search"> |
| 583 | 583 | ${field({ label: "Filter", name: "q", value: q, type: "search", maxlength: 80 })} |
| 584 | 584 | ${btn("Filter", { variant: "secondary" })} |
test/design-components.test.ts added +65
| @@ -0,0 +1,65 @@ | ||
| 1 | /** | |
| 2 | * /design/gallery (#5912): every component DESIGN.md §5 names is on the page, once. | |
| 3 | */ | |
| 4 | ||
| 5 | import { afterAll, beforeAll, describe, expect, test } from "bun:test"; | |
| 6 | import { mkdtemp, readFile, rm } from "node:fs/promises"; | |
| 7 | import { tmpdir } from "node:os"; | |
| 8 | import { join } from "node:path"; | |
| 9 | import { createApp, type App } from "../src/app.ts"; | |
| 10 | import { serve, type Servers } from "../src/http/server.ts"; | |
| 11 | import { samples } from "../src/web/pages/design-components.ts"; | |
| 12 | ||
| 13 | /** The bold name opening each row of the §5 vocabulary table. */ | |
| 14 | async function namedComponents(): Promise<string[]> { | |
| 15 | const doc = await readFile(join(import.meta.dir, "../docs/design/sections/5-components.md"), "utf8"); | |
| 16 | const start = doc.indexOf("## 5. The component vocabulary"); | |
| 17 | const end = doc.indexOf("Two things are deliberately", start); | |
| 18 | return [...doc.slice(start, end).matchAll(/^\| \*\*([^*]+)\*\*/gm)].map((m) => m[1]!.trim()); | |
| 19 | } | |
| 20 | ||
| 21 | describe("component gallery", () => { | |
| 22 | let dataDir: string; | |
| 23 | let app: App; | |
| 24 | let servers: Servers; | |
| 25 | beforeAll(async () => { | |
| 26 | dataDir = await mkdtemp(join(tmpdir(), "forge-gallery-")); | |
| 27 | app = createApp({ dataDir, port: 0, forgeRepo: "acme/forge" }); | |
| 28 | servers = await serve(app); | |
| 29 | }); | |
| 30 | afterAll(async () => { | |
| 31 | servers.stop(); | |
| 32 | app.close(); | |
| 33 | await rm(dataDir, { recursive: true, force: true }); | |
| 34 | }); | |
| 35 | ||
| 36 | test("answers 200 and lists every component §5 names", async () => { | |
| 37 | const names = await namedComponents(); | |
| 38 | expect(names.length).toBeGreaterThan(60); | |
| 39 | const res = await fetch(`${servers.url}/design/gallery`); | |
| 40 | expect(res.status).toBe(200); | |
| 41 | expect(res.headers.get("x-content-type-options")).toBe("nosniff"); | |
| 42 | const body = await res.text(); | |
| 43 | for (const name of names) { | |
| 44 | const section = body.split(`data-component="${name.replace(/&/g, "&")}"`)[1]; | |
| 45 | expect(section, `${name} is missing from the gallery`).toBeDefined(); | |
| 46 | expect(section!.slice(0, 20000)).toContain("gallery-frame"); | |
| 47 | } | |
| 48 | }); | |
| 49 | ||
| 50 | test("shows nothing §5 does not name", async () => { | |
| 51 | const names = new Set(await namedComponents()); | |
| 52 | for (const [name] of samples) expect(names.has(name), `${name} is not in §5`).toBe(true); | |
| 53 | }); | |
| 54 | ||
| 55 | test("the rendered page keeps one hairline frame per sample, with no box or fixed width", async () => { | |
| 56 | const body = await (await fetch(`${servers.url}/design/gallery`)).text(); | |
| 57 | const parts = body.split('class="gallery-part"').slice(1); | |
| 58 | expect(parts.length).toBe(samples.length); | |
| 59 | for (const part of parts) expect(part.split('class="gallery-frame"').length - 1).toBe(1); | |
| 60 | expect(body).toContain(".gallery-frame{min-width:0;max-width:100%;padding:0 0 12px;border-bottom:1px solid var(--border)"); | |
| 61 | expect(body).not.toMatch(/gallery[^{]*\{[^}]*(dashed|opacity)/); | |
| 62 | expect(body).not.toMatch(/data-w=/); | |
| 63 | expect(body).toMatch(/type="color" value="#[0-9a-f]{6}"/i); | |
| 64 | }); | |
| 65 | }); |
test/design-gallery-door.test.ts added +37
| @@ -0,0 +1,37 @@ | ||
| 1 | /** The gallery's terminal door (#5912): offered to everyone, says how many parts and where. */ | |
| 2 | import { afterAll, beforeAll, expect, test } from "bun:test"; | |
| 3 | import { mkdtemp, rm } from "node:fs/promises"; | |
| 4 | import { tmpdir } from "node:os"; | |
| 5 | import { join } from "node:path"; | |
| 6 | import { createApp, type App } from "../src/app.ts"; | |
| 7 | import { createForgeApp } from "../src/tui/forge.ts"; | |
| 8 | import { entry, galleryLine } from "../src/tui/screens/design_gallery.ts"; | |
| 9 | import { headlessTerminal } from "../src/tui/term/terminal.ts"; | |
| 10 | import { samples } from "../src/web/pages/design-components.ts"; | |
| 11 | import { quietLogs } from "./helpers/globals.ts"; | |
| 12 | ||
| 13 | quietLogs(); | |
| 14 | ||
| 15 | let dataDir: string; | |
| 16 | let app: App; | |
| 17 | ||
| 18 | beforeAll(async () => { | |
| 19 | dataDir = await mkdtemp(join(tmpdir(), "forge-gallery-door-")); | |
| 20 | app = createApp({ dataDir, port: 0 }); | |
| 21 | }); | |
| 22 | ||
| 23 | afterAll(async () => { | |
| 24 | app.close(); | |
| 25 | await rm(dataDir, { recursive: true, force: true }); | |
| 26 | }); | |
| 27 | ||
| 28 | test("the palette entry is offered to a signed-out session and names the count and the page", () => { | |
| 29 | const { app: tui, session } = createForgeApp(app, { sshUsername: "guest", remoteAddress: "127.0.0.1", fingerprint: "SHA256:t" }, { terminal: headlessTerminal(120, 30), exitHooks: false }); | |
| 30 | expect(entry.offered(session)).toBe(true); | |
| 31 | expect(galleryLine()).toContain(String(samples.length)); | |
| 32 | expect(galleryLine()).toContain("/design/gallery"); | |
| 33 | let said = ""; | |
| 34 | const ctx = Object.assign(Object.create(tui.ctx), { toast: (m: string) => (said = m) }); | |
| 35 | entry.run(session, ctx); | |
| 36 | expect(said).toBe(galleryLine()); | |
| 37 | }); |
test/design-theme.test.ts +2
| @@ -195,6 +195,8 @@ describe("design tab over http", () => { | ||
| 195 | 195 | expect(text).toContain("cx-dark"); |
| 196 | 196 | expect(text).toContain("Badge"); |
| 197 | 197 | expect(text).not.toContain("Empty state"); |
| 198 | expect(text).toContain(`<a href="/design/gallery">Component gallery</a>`); | |
| 199 | expect(text).not.toContain("390 and 1440"); | |
| 198 | 200 | }); |
| 199 | 201 | |
| 200 | 202 | test("a publish is pushed to an open page within 2 s", async () => { |
test/palette-roster.test.ts +4
| @@ -230,6 +230,7 @@ test("a site-admin person is offered the whole roster", () => { | ||
| 230 | 230 | ["experiments", "Experiments", "what each cloud machine costs and answers"], |
| 231 | 231 | ["bets", "Bets", "back, stop and finish a repository\'s bets"], |
| 232 | 232 | ["origins", "Connected accounts", "the hosts your mirrors come from"], |
| 233 | ["design-gallery", "Component gallery", "every component the design names"], | |
| 233 | 234 | ["domains", "Failure domains", "failure domains and their last drill"], |
| 234 | 235 | ["feed", "Feed", "what happened, ranked; r replies on a post about an issue or pull, l likes, h who liked, p its permalink, o a run's log"], |
| 235 | 236 | ["feature-review", "Menu entries to review", "absorbed apps whose declared name or page changed: accept them"], |
| @@ -343,6 +344,7 @@ test("a site-admin agent is offered the roster without the person-only entries", | ||
| 343 | 344 | ["cloud", "Cloud accounts", "provider tokens, what they are used for, today's calls"], |
| 344 | 345 | ["pinned", "Pinned forges", "deploy, update and roll back a forge on your cloud"], |
| 345 | 346 | ["experiments", "Experiments", "what each cloud machine costs and answers"], |
| 347 | ["design-gallery", "Component gallery", "every component the design names"], | |
| 346 | 348 | ["feed", "Feed", "what happened, ranked; r replies on a post about an issue or pull, l likes, h who liked, p its permalink, o a run's log"], |
| 347 | 349 | ["feature-feed", "Feature feeds", "the feed items about an absorbed app, as Settings › Features shows them"], |
| 348 | 350 | ["front", "Front page", "the apps a first visitor sees, ranked; an admin pins or hides"], |
| @@ -460,6 +462,7 @@ test("a member person is offered the signed-in roster without the admin entries" | ||
| 460 | 462 | ["bulk", "Bulk actions", "your last bulk actions; u undoes one inside its day"], |
| 461 | 463 | ["bets", "Bets", "back, stop and finish a repository\'s bets"], |
| 462 | 464 | ["origins", "Connected accounts", "the hosts your mirrors come from"], |
| 465 | ["design-gallery", "Component gallery", "every component the design names"], | |
| 463 | 466 | ["feed", "Feed", "what happened, ranked; r replies on a post about an issue or pull, l likes, h who liked, p its permalink, o a run's log"], |
| 464 | 467 | ["feature-feed", "Feature feeds", "the feed items about an absorbed app, as Settings › Features shows them"], |
| 465 | 468 | ["front", "Front page", "the apps a first visitor sees, ranked; an admin pins or hides"], |
| @@ -521,6 +524,7 @@ test("signed out, the palette offers sign-in and the public entries", () => { | ||
| 521 | 524 | ["health-voice", "Health — spoken", "how the forge is, in two plain sentences"], |
| 522 | 525 | ["audit", "Who can do what", "each app's doors from its contract.json: yes, own or no"], |
| 523 | 526 | ["apps-crew", "What the crew is doing", "one plain sentence per app: who is on what"], |
| 527 | ["design-gallery", "Component gallery", "every component the design names"], | |
| 524 | 528 | ["front", "Front page", "the apps a first visitor sees, ranked; an admin pins or hides"], |
| 525 | 529 | ["origin-ahead", "New commits upstream", "mirrors whose origin has moved on: take them"], |
| 526 | 530 | ["security", "Security", "what the forge enforces for everyone, and how to report a problem"], |
new above
offline
Hand-rolled dialog with an inline style. Use the named dialog component, or a gallery class that sets position, so the sample is what the real page draws. The same applies to lines 63 and 85.