Public: anyone can read this; the crew can change it.
A new account's home offers three things it can do, each one click away, and an empty page says what goes there and how #18496
Merged 4h 33m ago, live in production
scout/forge:scout/18492-a-new-account-s-home-offers-three-things → main 0 commits fork 2 threads · 2 unresolved
15 files
changed +187
−64
- docs/design/attention-budget.json
- docs/features/first-week.md
- src/core/first_week.ts
- src/web/pages/app_releases.ts
- src/web/pages/apps.ts
- src/web/pages/boards-view.ts
- src/web/pages/branches.ts
- src/web/pages/displays.ts
- src/web/pages/repo.ts
- src/web/studio/feed.ts
- src/web/studio/home.ts
- test/empty-bare.test.ts
- test/empty-states.test.ts
- test/first-week.test.ts
- test/helpers/empty-blocks.ts
docs/design/attention-budget.json +7 −7
| @@ -218,16 +218,16 @@ | ||
| 218 | 218 | }, |
| 219 | 219 | "boards": { |
| 220 | 220 | "390": { |
| 221 | "words": 345, | |
| 222 | "blocks": 99, | |
| 223 | "colours": 2 | |
| 221 | "words": 349, | |
| 222 | "blocks": 100, | |
| 223 | "colours": 3 | |
| 224 | 224 | }, |
| 225 | 225 | "1280": { |
| 226 | "words": 345, | |
| 227 | "blocks": 99, | |
| 228 | "colours": 2 | |
| 226 | "words": 349, | |
| 227 | "blocks": 100, | |
| 228 | "colours": 3 | |
| 229 | 229 | }, |
| 230 | "note": "Raised by 6 words and 3 blocks for the slots above the pipeline, at their least: a line each for checks and the crew (\"Checks 0 of 1 slots busy\", nothing more while nothing waits) and the Change capacity button that replaced the header's Capacity link; no legend (#16830). Plus 3 words and 1 block for the live line, \"live \u00b7 Pause\", the one mechanism that replaced the page's old refresh (#3715)." | |
| 230 | "note": "Raised by 6 words and 3 blocks for the slots above the pipeline, at their least: a line each for checks and the crew (\"Checks 0 of 1 slots busy\", nothing more while nothing waits) and the Change capacity button that replaced the header's Capacity link; no legend (#16830). Plus 3 words and 1 block for the live line, \"live \u00b7 Pause\", the one mechanism that replaced the page's old refresh (#3715). Plus 4 words, 1 block and 1 colour for the empty list's one link, the control every empty state carries (#18492)." | |
| 231 | 231 | }, |
| 232 | 232 | "forges": { |
| 233 | 233 | "390": { |
docs/features/first-week.md +2
| @@ -9,3 +9,5 @@ On a forge whose first account is under seven days old, its admin sees one line | ||
| 9 | 9 | Each step is read from records that already exist, nothing is stored: an app is any repository the admin owns; telling is an issue they wrote that is not an app's direction issue; inviting is an invite link they made. A spawned forge keeps its own, longer first-login card instead. |
| 10 | 10 | |
| 11 | 11 | Code: `src/core/first_week.ts` (the steps), `src/web/first_week.ts` (the line). Test: `test/first-week.test.ts`. |
| 12 | ||
| 13 | Any other new account sees the same line for its own first seven days, with "See what others made" (`/explore`) in place of Invite: Name an app, Tell the crew something, See what others made. Looking leaves no record, so that step is never struck; the line goes once the app and the telling are done. Every list page's empty state names what goes there and carries its one control (`test/empty-states.test.ts`, `test/empty-bare.test.ts`). |
src/core/first_week.ts +14 −10
| @@ -1,9 +1,9 @@ | ||
| 1 | 1 | /** |
| 2 | * The first week's three steps for the person who set a forge up: name an app, tell the crew | |
| 3 | * something, invite someone. Each is read from records that already exist (a repository they own, | |
| 4 | * an issue they wrote, an invite they made); nothing is stored. Only a person who is a site admin | |
| 5 | * sees them, and only while the forge's first account is under seven days old. Once all three are | |
| 6 | * done there are none. | |
| 2 | * The first week's three steps: name an app, tell the crew something, then invite someone (the | |
| 3 | * forge's admin) or see what others made (any other new account). Each is read from records that | |
| 4 | * already exist (a repository they own, an issue they wrote, an invite they made); nothing is | |
| 5 | * stored. They show while the account (for the admin, the forge's first) is under seven days old. | |
| 6 | * Once all three are done there are none. | |
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | 9 | import type { Database } from "bun:sqlite"; |
| @@ -11,7 +11,7 @@ import type { User } from "./users.ts"; | ||
| 11 | 11 | |
| 12 | 12 | export const FIRST_WEEK_MS = 7 * 24 * 60 * 60 * 1000; |
| 13 | 13 | |
| 14 | export type FirstWeekKey = "app" | "tell" | "invite"; | |
| 14 | export type FirstWeekKey = "app" | "tell" | "invite" | "explore"; | |
| 15 | 15 | |
| 16 | 16 | export interface FirstWeekStep { |
| 17 | 17 | readonly key: FirstWeekKey; |
| @@ -25,8 +25,9 @@ export interface FirstWeekStep { | ||
| 25 | 25 | * done. |
| 26 | 26 | */ |
| 27 | 27 | export function firstWeekSteps(db: Database, user: User | undefined, now: number = Date.now()): readonly FirstWeekStep[] | null { |
| 28 | if (user === undefined || user.kind !== "user" || !user.isAdmin) return null; | |
| 29 | const born = db.query<{ at: string | null }, []>("SELECT MIN(created_at) AS at FROM user").get()?.at; | |
| 28 | if (user === undefined || user.kind !== "user") return null; | |
| 29 | // The forge's admin counts from the forge's first account; anyone else from their own. | |
| 30 | const born = user.isAdmin ? db.query<{ at: string | null }, []>("SELECT MIN(created_at) AS at FROM user").get()?.at : user.createdAt; | |
| 30 | 31 | const since = born ? Date.parse(born) : Number.NaN; |
| 31 | 32 | if (!Number.isFinite(since) || now - since >= FIRST_WEEK_MS) return null; |
| 32 | 33 | const has = (sql: string): boolean => db.query<{ n: number }, [string]>(sql).get(user.id) !== null; |
| @@ -41,9 +42,12 @@ export function firstWeekSteps(db: Database, user: User | undefined, now: number | ||
| 41 | 42 | AND id NOT IN (SELECT direction_issue_id FROM repo WHERE direction_issue_id IS NOT NULL) LIMIT 1`, |
| 42 | 43 | ), |
| 43 | 44 | }, |
| 44 | { key: "invite", text: "Invite someone", href: "/admin/limits", done: has("SELECT 1 AS n FROM invite WHERE created_by = ?1 LIMIT 1") }, | |
| 45 | user.isAdmin | |
| 46 | ? { key: "invite", text: "Invite someone", href: "/admin/limits", done: has("SELECT 1 AS n FROM invite WHERE created_by = ?1 LIMIT 1") } | |
| 47 | : // Looking is not a record, so this step is never struck; the line goes when the other two are done. | |
| 48 | { key: "explore", text: "See what others made", href: "/explore", done: false }, | |
| 45 | 49 | ]; |
| 46 | return steps.every((s) => s.done) ? null : steps; | |
| 50 | return steps.filter((s) => s.key !== "explore").every((s) => s.done) ? null : steps; | |
| 47 | 51 | } |
| 48 | 52 | |
| 49 | 53 | /** The crew's first run for a person, in two states a page can say in plain words. */ |
src/web/pages/app_releases.ts +2 −2
| @@ -10,7 +10,7 @@ import { releaseFacts } from "../../release/app_words.ts"; | ||
| 10 | 10 | import { loadRepo, notFoundPage, pageHead, repoBase } from "../chrome.ts"; |
| 11 | 11 | import { html } from "../html.ts"; |
| 12 | 12 | import { page } from "../layout.ts"; |
| 13 | import { row, sha, time } from "../ui.ts"; | |
| 13 | import { btn, row, sha, time } from "../ui.ts"; | |
| 14 | 14 | import { emptyList } from "../empty_words.ts"; |
| 15 | 15 | |
| 16 | 16 | export function appReleasesPage(ctx: Ctx): Response { |
| @@ -24,7 +24,7 @@ export function appReleasesPage(ctx: Ctx): Response { | ||
| 24 | 24 | body: html`<div class="narrow-wide"> |
| 25 | 25 | ${pageHead("Releases", { sub: `Each version ${repo.ownerName}/${repo.name} first served in production.` })} |
| 26 | 26 | ${releases.length === 0 |
| 27 | ? emptyList("appReleases", { noAction: true }) | |
| 27 | ? emptyList("appReleases", { action: btn("Tell the crew", { href: `/${repo.ownerName}/${repo.name}/issues/new`, variant: "link" }) }) | |
| 28 | 28 | : html`<ul class="list" aria-label="Releases">${releases.map((r) => |
| 29 | 29 | row({ |
| 30 | 30 | title: html`${r.version} · ${r.subject}`, |
src/web/pages/apps.ts +1 −1
| @@ -241,7 +241,7 @@ export async function appsList(ctx: Ctx): Promise<Response> { | ||
| 241 | 241 | </p>` |
| 242 | 242 | : null} |
| 243 | 243 | ${shown.length === 0 && !live |
| 244 | ? emptyList("apps", { noAction: true }) | |
| 244 | ? emptyList("apps", { action: ctx.auth.user ? btn("New app", { href: "/apps/new", variant: "link" }) : btn("Sign in to make one", { href: withReturn("/signin", returnTo(ctx)), variant: "link" }) }) | |
| 245 | 245 | : shown.length === 0 |
| 246 | 246 | ? html`<section class="stack"> |
| 247 | 247 | <p><strong>${live ? "Nothing is live" : "Nothing runs here yet"}</strong></p> |
src/web/pages/boards-view.ts +1 −1
| @@ -144,7 +144,7 @@ export async function boardsList(ctx: Ctx): Promise<Response> { | ||
| 144 | 144 | const boards = html`<section class="bd-block" id="boards-all" aria-labelledby="boards-all-h"> |
| 145 | 145 | <header class="bd-head"><h2 id="boards-all-h">Your boards</h2><p class="bd-sub">A board is a page of charts over the forge's own numbers, saved as a file in forge/boards.</p></header> |
| 146 | 146 | ${listed.value.length === 0 |
| 147 | ? emptyList("board", { noAction: true }) | |
| 147 | ? emptyList("board") | |
| 148 | 148 | : html`<ul class="bd-boards"> |
| 149 | 149 | ${listed.value.map( |
| 150 | 150 | ({ slug, board }) => html`<li class="tile"><a href="/boards/${slug}" class="tile-link" data-nav tabindex="-1"> |
src/web/pages/branches.ts +1 −1
| @@ -380,7 +380,7 @@ export async function renderBranches( | ||
| 380 | 380 | ? html`<p class="small"><a href="${scope.base}/builds">Builds</a></p>` |
| 381 | 381 | : null} |
| 382 | 382 | ${rows.length === 0 |
| 383 | ? emptyList("branches", { noAction: true }) | |
| 383 | ? emptyList("branches", scope.kind === "local" ? { action: btn("Tell the crew", { href: `${scope.base}/issues/new`, variant: "link" }) } : { noAction: true }) | |
| 384 | 384 | : html`<h2 class="mt"> |
| 385 | 385 | ${rows.length} branch${rows.length === 1 ? "" : "es"} |
| 386 | 386 | ${when( |
src/web/pages/displays.ts +2 −1
| @@ -13,6 +13,7 @@ import { pageHead, repoBase, signInFirst } from "../chrome.ts"; | ||
| 13 | 13 | import { html } from "../html.ts"; |
| 14 | 14 | import { page } from "../layout.ts"; |
| 15 | 15 | import { emptyList } from "../empty_words.ts"; |
| 16 | import { btn } from "../ui.ts"; | |
| 16 | 17 | import { signedInPage } from "../../http/page_may.ts"; |
| 17 | 18 | |
| 18 | 19 | const LAYOUT_WORD = { shelf: "Shelf", grid: "Grid", graph: "Graph" } as const; |
| @@ -34,7 +35,7 @@ export async function displaysPage(ctx: Ctx): Promise<Response> { | ||
| 34 | 35 | ${rows.length === 0 && !complete |
| 35 | 36 | ? null |
| 36 | 37 | : rows.length === 0 |
| 37 | ? emptyList("displays", { noAction: true }) | |
| 38 | ? emptyList("displays", { action: btn("Pick an app", { href: "/apps", variant: "link" }) }) | |
| 38 | 39 | : html`<div class="table-scroll" role="region" tabindex="0" aria-label="Displays"> |
| 39 | 40 | <table class="table" data-dense data-by="displays"> |
| 40 | 41 | <thead> |
src/web/pages/repo.ts +1 −1
| @@ -233,7 +233,7 @@ export async function forksPage(ctx: Ctx): Promise<Response> { | ||
| 233 | 233 | </div> |
| 234 | 234 | <p class="muted small" data-fork-flows-link><a href="/forks/flows">Fork flows</a></p> |
| 235 | 235 | ${lineage.size === 1 |
| 236 | ? emptyList("forks", { noAction: true, bind: BIND.rest }) | |
| 236 | ? emptyList("forks", { action: btn("Fork it", { href: repoBase(repo), variant: "link" }), bind: BIND.rest }) | |
| 237 | 237 | : html`${forkRanking(ranked, new Map(tree.map((n) => [n.repo.id, n])), BIND.rest, forkModes, (fork, parent) => keptBehind(ctx.app, fork, parent), forkFollowed)} |
| 238 | 238 | <h3 class="mt">The family, by who follows whom</h3> |
| 239 | 239 | ${lineageCard(lineage, repo.id, ctx.auth.user?.id)}`}`; |
src/web/studio/feed.ts +1 −1
| @@ -581,7 +581,7 @@ function drawRegion(user: User, ctx: Ctx, read: ReturnType<typeof readRegion>): | ||
| 581 | 581 | ${chipsBar(user, ctx, items)} |
| 582 | 582 | ${thoughts.map((t) => thoughtCard(t, user.username, placed.get(t.id)))} |
| 583 | 583 | ${items.length === 0 && thoughts.length === 0 |
| 584 | ? html`<div class="feed-empty" data-feed-empty>${empty({ title: EMPTY_FEED })}</div>` | |
| 584 | ? html`<div class="feed-empty" data-feed-empty>${empty({ title: EMPTY_FEED, action: btn("See what others made", { href: "/explore", variant: "link" }) })}</div>` | |
| 585 | 585 | : posts} |
| 586 | 586 | ${quiet === 0 |
| 587 | 587 | ? "" |
src/web/studio/home.ts +2 −2
| @@ -145,7 +145,7 @@ function yourApps(ctx: Ctx, user: User, apps = writableAppsOf(ctx, user)): Html | ||
| 145 | 145 | const archived = archivedAppCount(ctx); |
| 146 | 146 | const foundry = foundryHref(ctx.app, ctx.auth.user); |
| 147 | 147 | const list = html`${rows.length === 0 |
| 148 | ? emptyList("appList", { noAction: true }) | |
| 148 | ? emptyList("appList", { action: btn("New app", { href: "/apps/new", variant: "link" }) }) | |
| 149 | 149 | : html`<ul class="list"> |
| 150 | 150 | ${rows} |
| 151 | 151 | </ul>`} |
| @@ -822,7 +822,7 @@ export function studioDoor(ctx: Ctx): Response { | ||
| 822 | 822 | title: front.total > 0 ? "Nothing on this shelf yet" : "Nothing public is up yet", |
| 823 | 823 | ...(front.total > 0 |
| 824 | 824 | ? { action: btn(`See all ${front.total} public ${front.total === 1 ? "app" : "apps"}`, { href: "/explore?q=kind%3Aapp", variant: "link" }) } |
| 825 | : { note: "Apps made public here show up on this shelf once they run." }), | |
| 825 | : { note: "Apps made public here show up on this shelf once they run.", action: btn("Look around in Explore", { href: "/explore", variant: "link" }) }), | |
| 826 | 826 | })} |
| 827 | 827 | </div>`} |
| 828 | 828 | </section> |
test/empty-bare.test.ts added +111
| @@ -0,0 +1,111 @@ | ||
| 1 | /** | |
| 2 | * #18492: a new account that is not the admin has a home with three first steps, and every list | |
| 3 | * page it can open says what goes there with its one control: a page whose empty state is bare is | |
| 4 | * named. | |
| 5 | */ | |
| 6 | import { afterAll, beforeAll, 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 { 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 { goPagesFor } from "../src/web/go_pages.ts"; | |
| 15 | import { html } from "../src/web/html.ts"; | |
| 16 | import { empty } from "../src/web/ui.ts"; | |
| 17 | import { serve, type Servers } from "../src/http/server.ts"; | |
| 18 | import { emptyBlocks } from "./helpers/empty-blocks.ts"; | |
| 19 | import { quietLogs } from "./helpers/globals.ts"; | |
| 20 | ||
| 21 | quietLogs(); | |
| 22 | ||
| 23 | let dir: string; | |
| 24 | let app: App; | |
| 25 | let servers: Servers; | |
| 26 | let cookie: string; | |
| 27 | ||
| 28 | beforeAll(async () => { | |
| 29 | dir = await mkdtemp(join(tmpdir(), "forge-empty-bare-")); | |
| 30 | app = createApp({ dataDir: dir, port: 0 }); | |
| 31 | servers = await serve(app); | |
| 32 | const root = await createUser(app.db, { origin: "seed", trusted: true, username: "root", allowReserved: true, email: "[email protected]", password: "a-good-passphrase", adminIfFirst: true }); | |
| 33 | const kim = await createUser(app.db, { origin: "seed", trusted: true, username: "kim", email: "[email protected]", password: "a-good-passphrase" }); | |
| 34 | if (!root.ok || !kim.ok) throw new Error("user"); | |
| 35 | const made = await createRepo(app, root.value, { name: "fresh", visibility: "public" }); | |
| 36 | if (!made.ok) throw new Error("repo"); | |
| 37 | cookie = `forge_session=${createSession(app.db, kim.value.id).token}`; | |
| 38 | }); | |
| 39 | afterAll(async () => { | |
| 40 | servers.stop(); | |
| 41 | app.close(); | |
| 42 | await rm(dir, { recursive: true, force: true }); | |
| 43 | }); | |
| 44 | ||
| 45 | test("a new account's home offers three links, each to a page that does it", async () => { | |
| 46 | const page = await (await fetch(`${servers.url}/`, { headers: { cookie } })).text(); | |
| 47 | const nav = page.match(/<nav id="first-week"[\s\S]*?<\/nav>/)?.[0] ?? ""; | |
| 48 | const hrefs = [...nav.matchAll(/href="([^"]+)" data-step="(\w+)"/g)].map((m) => `${m[2]}|${m[1]}`); | |
| 49 | expect(hrefs).toEqual(["app|/new", "tell|#tell-box", "explore|/explore"]); | |
| 50 | for (const path of ["/new", "/explore"]) expect((await fetch(servers.url + path, { headers: { cookie } })).status).toBe(200); | |
| 51 | expect(page).toContain('id="tell-box"'); | |
| 52 | }); | |
| 53 | ||
| 54 | /** The words and the one control of every `.empty` block, parsed by div depth (`emptyBlocks`). */ | |
| 55 | function blocks(page: string): { text: string; control: boolean }[] { | |
| 56 | return emptyBlocks(page).map((b) => ({ | |
| 57 | text: b.replace(/<[^>]*>/g, " ").replace(/\s+/g, " ").trim(), | |
| 58 | control: /<a\s|<form\s|<button\s/.test(b), | |
| 59 | })); | |
| 60 | } | |
| 61 | ||
| 62 | // The list pages come from the nav's own table (`GO_PAGES`), for each kind of viewer, plus the | |
| 63 | // lists a repository carries, which the nav does not name. | |
| 64 | const REPO_LISTS = ["issues", "pulls", "runs", "branches", "labels", "releases", "forks"].map((l) => `/root/fresh/${l}`); | |
| 65 | const pagesFor = (signedIn: boolean): string[] => [ | |
| 66 | ...new Set( | |
| 67 | [...goPagesFor({ signedIn, admin: false }).map((p) => p.href), ...REPO_LISTS] | |
| 68 | .filter((h) => !h.includes("?")) | |
| 69 | .filter((h) => h !== "/"), | |
| 70 | ), | |
| 71 | ]; | |
| 72 | ||
| 73 | test("the nav lists pages for the new account and for a guest, so the walk below is not empty", () => { | |
| 74 | expect(pagesFor(true).length).toBeGreaterThan(pagesFor(false).length); | |
| 75 | expect(pagesFor(false)).toContain("/apps"); | |
| 76 | expect(pagesFor(true)).toContain("/notes"); | |
| 77 | }); | |
| 78 | ||
| 79 | for (const [who, signedIn] of [["a new non-admin account", true], ["a guest", false]] as const) { | |
| 80 | test(`no list page ${who} opens has an empty state that says nothing or offers nothing`, async () => { | |
| 81 | const bare: string[] = []; | |
| 82 | let seen = 0; | |
| 83 | for (const path of pagesFor(signedIn)) { | |
| 84 | const res = await fetch(servers.url + path, { headers: signedIn ? { cookie } : {} }); | |
| 85 | if (res.status !== 200) continue; | |
| 86 | for (const b of blocks(await res.text())) { | |
| 87 | seen++; | |
| 88 | if (b.text.length < 12) bare.push(`${path}: names nothing`); | |
| 89 | if (!b.control) bare.push(`${path}: "${b.text}" has no control`); | |
| 90 | } | |
| 91 | } | |
| 92 | expect(bare).toEqual([]); | |
| 93 | expect(seen).toBeGreaterThan(0); | |
| 94 | }); | |
| 95 | } | |
| 96 | ||
| 97 | test("/apps and /boards say what goes there and carry the one control themselves", async () => { | |
| 98 | const apps = blocks(await (await fetch(`${servers.url}/apps`, { headers: { cookie } })).text()); | |
| 99 | expect(apps.length).toBe(1); | |
| 100 | expect(apps[0]!.control).toBe(true); | |
| 101 | expect(apps[0]!.text).toContain("Nothing runs here yet"); | |
| 102 | expect(apps[0]!.text).toContain("New app"); | |
| 103 | const guest = blocks(await (await fetch(`${servers.url}/apps`)).text()); | |
| 104 | expect(guest[0]!.text).toContain("Sign in to make one"); | |
| 105 | }); | |
| 106 | ||
| 107 | test("a block's control is found even when the helper nests elements before it", () => { | |
| 108 | const page = String(empty({ icon: "lock", title: "Nothing here yet at all", action: html`<a href="/x">Go</a>` })); | |
| 109 | expect(blocks(page)).toEqual([{ text: "Nothing here yet at all Go", control: true }]); | |
| 110 | expect(blocks(String(empty({ title: "Nothing here yet at all" })))[0]!.control).toBe(false); | |
| 111 | }); |
test/empty-states.test.ts +3 −35
| @@ -13,6 +13,7 @@ import type { EmptyWords } from "../src/core/empty_words.ts"; | ||
| 13 | 13 | import { createUser } from "../src/core/users.ts"; |
| 14 | 14 | import { RATCHET_FIX } from "../src/design/ratchets.ts"; |
| 15 | 15 | import { serve, type Servers } from "../src/http/server.ts"; |
| 16 | import { emptyBlocks } from "./helpers/empty-blocks.ts"; | |
| 16 | 17 | import { html } from "../src/web/html.ts"; |
| 17 | 18 | import { EMPTY_WORDS, emptyLine, emptyList, emptySection, type EmptyKind } from "../src/web/empty_words.ts"; |
| 18 | 19 | |
| @@ -37,33 +38,8 @@ afterAll(async () => { | ||
| 37 | 38 | await rm(dir, { recursive: true, force: true }); |
| 38 | 39 | }); |
| 39 | 40 | |
| 40 | // /apps and /boards are not here: their page already carries the one door ("New app", "Make a | |
| 41 | // board"). | |
| 42 | 41 | const LISTS = ["/root/fresh/issues", "/root/fresh/pulls", "/root/fresh/runs", "/settings/people", "/notes"]; |
| 43 | 42 | |
| 44 | /** Every `.empty` block in a page, whole: matched by div depth, so a nested | |
| 45 | * div in the part never cuts it short. */ | |
| 46 | function emptyBlocks(page: string): string[] { | |
| 47 | const out: string[] = []; | |
| 48 | let at = page.indexOf('<div class="empty"'); | |
| 49 | while (at !== -1) { | |
| 50 | const tag = /<(\/?)div\b/g; | |
| 51 | tag.lastIndex = at; | |
| 52 | let depth = 0; | |
| 53 | let end = page.length; | |
| 54 | for (let m = tag.exec(page); m; m = tag.exec(page)) { | |
| 55 | depth += m[1] ? -1 : 1; | |
| 56 | if (depth === 0) { | |
| 57 | end = page.indexOf(">", m.index) + 1; | |
| 58 | break; | |
| 59 | } | |
| 60 | } | |
| 61 | out.push(page.slice(at, end)); | |
| 62 | at = page.indexOf('<div class="empty"', end); | |
| 63 | } | |
| 64 | return out; | |
| 65 | } | |
| 66 | ||
| 67 | 43 | const links = (block: string): string[] => [...block.matchAll(/<a\s[^>]*href="([^"]+)"[^>]*>([^<]*)</g)].map((m) => `${m[1]}|${m[2]!.trim()}`); |
| 68 | 44 | |
| 69 | 45 | for (const path of LISTS) { |
| @@ -113,16 +89,14 @@ test("the six lists take their empty sentence from one table, each with a single | ||
| 113 | 89 | const blocks = emptyBlocks(await (await fetch(servers.url + path, { headers: { cookie } })).text()); |
| 114 | 90 | const mine = blocks.filter((b) => b.includes(w.sentence)); |
| 115 | 91 | expect(mine.length).toBe(1); |
| 116 | // apps and board: the page already offers the door, so the empty state does not say it twice. | |
| 117 | const once = kind === "apps" || kind === "board"; | |
| 118 | 92 | // waves: the one step is a tell button (a form), not a link. |
| 119 | 93 | if (kind === "waves") { |
| 120 | 94 | expect(mine[0]).toContain(w.label!); |
| 121 | 95 | expect(mine[0]).toContain('action="/root/fresh/tell"'); |
| 122 | 96 | continue; |
| 123 | 97 | } |
| 124 | expect(links(mine[0]!).length).toBe(once ? 0 : 1); | |
| 125 | if (!once) expect(links(mine[0]!)[0]!.endsWith(`|${w.label}`)).toBe(true); | |
| 98 | expect(links(mine[0]!).length).toBe(1); | |
| 99 | expect(links(mine[0]!)[0]!.endsWith(`|${w.label}`)).toBe(true); | |
| 126 | 100 | expect(mine[0]).not.toContain('data-variant="primary"'); |
| 127 | 101 | expect((mine[0]!.match(/<p\b/g) ?? []).length).toBe(1); |
| 128 | 102 | } |
| @@ -165,14 +139,8 @@ test("emptyLine is one muted line: sentence and reason, no picture, no link", () | ||
| 165 | 139 | // has exactly one link or form in it, or is named in ALLOWED with the reason it has none. A failing |
| 166 | 140 | // page is named in the failure, so the fix points at the page. |
| 167 | 141 | const ALLOWED: Readonly<Record<string, string>> = { |
| 168 | "/boards": "the page's own 'Make a board' disclosure under the empty state is the one door", | |
| 169 | "/apps": "the page's own 'New app' button is the one door", | |
| 170 | "/displays": "a display is a file in a repository, so the next step is a git push, not a page", | |
| 171 | 142 | "/settings/subscriptions": "the add-token form sits on the same page, directly below", |
| 172 | "/root/fresh/branches": "the create-branch form sits on the same page, directly above", | |
| 173 | 143 | "/root/fresh/commits": "history comes from a git push; there is no page to send anyone to", |
| 174 | "/root/fresh/releases": "a release is recorded by the forge when production serves a version", | |
| 175 | "/root/fresh/forks": "the Fork button in the repository's header is the one door", | |
| 176 | 144 | }; |
| 177 | 145 | const EMPTY_PAGES = [ |
| 178 | 146 | "/apps", "/boards", "/audit", "/displays", "/explore", "/settings/subscriptions", |
test/first-week.test.ts +16 −2
| @@ -70,10 +70,24 @@ describe("first week", () => { | ||
| 70 | 70 | expect(firstWeekBlock(app.db, alice)).toBeNull(); |
| 71 | 71 | }); |
| 72 | 72 | |
| 73 | test("nothing for a forge a week old, a guest or a non-admin", async () => { | |
| 73 | test("a new account that is not the admin sees three links, the third to explore, and it is never struck", async () => { | |
| 74 | 74 | const bob = await createUser(app.db, { origin: "seed", trusted: true, username: "bob", email: "[email protected]", password: "a-good-passphrase" }); |
| 75 | 75 | if (!bob.ok) throw new Error("user"); |
| 76 | expect(firstWeekSteps(app.db, bob.value)).toBeNull(); | |
| 76 | const steps = firstWeekSteps(app.db, bob.value) ?? []; | |
| 77 | expect(steps.map((s) => [s.key, s.href, s.done])).toEqual([["app", "/new", false], ["tell", "#tell-box", false], ["explore", "/explore", false]]); | |
| 78 | expect(firstWeekSteps(app.db, bob.value, Date.now() + FIRST_WEEK_MS + 1000)).toBeNull(); | |
| 79 | // Lend bob alice's app and her ask for a moment: both steps read as done, and the line goes. | |
| 80 | app.db.run("UPDATE repo SET owner_id = ?1", [bob.value.id]); | |
| 81 | app.db.run("UPDATE issue SET author_id = ?1", [bob.value.id]); | |
| 82 | try { | |
| 83 | expect(firstWeekSteps(app.db, bob.value)).toBeNull(); | |
| 84 | } finally { | |
| 85 | app.db.run("UPDATE repo SET owner_id = ?1", [alice.id]); | |
| 86 | app.db.run("UPDATE issue SET author_id = ?1", [alice.id]); | |
| 87 | } | |
| 88 | }); | |
| 89 | ||
| 90 | test("nothing for a forge a week old or a guest", () => { | |
| 77 | 91 | expect(firstWeekSteps(app.db, undefined)).toBeNull(); |
| 78 | 92 | app.db.run("DELETE FROM invite"); |
| 79 | 93 | expect(firstWeekSteps(app.db, alice)).not.toBeNull(); |
test/helpers/empty-blocks.ts added +23
| @@ -0,0 +1,23 @@ | ||
| 1 | /** | |
| 2 | * Every `.empty` block in a page, whole: matched by div depth, so a nested div never cuts it short. | |
| 3 | */ | |
| 4 | export function emptyBlocks(page: string): string[] { | |
| 5 | const out: string[] = []; | |
| 6 | let at = page.indexOf('<div class="empty"'); | |
| 7 | while (at !== -1) { | |
| 8 | const tag = /<(\/?)div\b/g; | |
| 9 | tag.lastIndex = at; | |
| 10 | let depth = 0; | |
| 11 | let end = page.length; | |
| 12 | for (let m = tag.exec(page); m; m = tag.exec(page)) { | |
| 13 | depth += m[1] ? -1 : 1; | |
| 14 | if (depth === 0) { | |
| 15 | end = page.indexOf(">", m.index) + 1; | |
| 16 | break; | |
| 17 | } | |
| 18 | } | |
| 19 | out.push(page.slice(at, end)); | |
| 20 | at = page.indexOf('<div class="empty"', end); | |
| 21 | } | |
| 22 | return out; | |
| 23 | } |
new above
offline
The lazy match ends at the first
</div>. Theempty()helper nests elements, so the control can be cut off. Match the whole block, or add adata-hook.