Public: anyone can read this; the crew can change it.
The forge toolbar in a preview names the pull it previews and links back to it #15865
Check · Review · Land · Live done — Landed and live in production.
torque/forge:torque/15850-the-forge-toolbar-in-a-preview-names-the → main 0 commits fork
14 files
changed +123
−44
src/apps/proxy.ts +7 −4
| @@ -458,15 +458,18 @@ export function pillWhere( | ||
| 458 | 458 | } |
| 459 | 459 | const number = /^pull-(\d+)$/.exec(target.env)?.[1]; |
| 460 | 460 | if (number === undefined) return where; |
| 461 | where.pull = Number(number); | |
| 461 | // The number is read from the forge's own record: a preview host naming a pull the repository | |
| 462 | // does not have says nothing. | |
| 463 | const asked = Number(number); | |
| 464 | const pull = getIssue(db, target.app.repoId, asked); | |
| 465 | if (pull === undefined || pull.kind !== "pull") return where; | |
| 466 | where.pull = asked; | |
| 462 | 467 | // Whether the panel offers the comment box or the way to sign in for it. |
| 463 | 468 | if (user !== undefined) where.signedIn = true; |
| 464 | 469 | // What a waiting guest's preview runs on is said to whoever looks at it: it is about the page in |
| 465 | 470 | // front of them. |
| 466 | const row = getPull(db, target.app.repoId, where.pull); | |
| 471 | const row = getPull(db, target.app.repoId, asked); | |
| 467 | 472 | if (row !== undefined && guestWaits(db, row)) where.waits = true; |
| 468 | const pull = getIssue(db, target.app.repoId, where.pull); | |
| 469 | if (pull === undefined) return where; | |
| 470 | 473 | if (!reads || !mayView(db, repo, pull, user)) return where; |
| 471 | 474 | where.title = pull.title; |
| 472 | 475 | if (row !== undefined && row.headBranch !== "") where.branch = row.headBranch; |
src/apps/toolbar.ts +1 −1
| @@ -121,7 +121,7 @@ const toolbarSource = `(function () { | ||
| 121 | 121 | } |
| 122 | 122 | var cw = ${JSON.stringify(CHECK_WORDS)}; |
| 123 | 123 | var cv = d.check && Object.prototype.hasOwnProperty.call(cw, d.check) ? cw[d.check] : ""; |
| 124 | var pt = "Pull #" + d.pull + (cv ? ": " : ""); | |
| 124 | var pt = "Preview of #" + d.pull + (cv ? ": " : ""); | |
| 125 | 125 | // The word's own slot is as wide as the longest word: checking -> green never reflows the row. |
| 126 | 126 | function slot(a) { |
| 127 | 127 | if (!cv) return; |
test/apps-pill-check.test.ts +6 −6
| @@ -84,16 +84,16 @@ describe("the pill's check line", () => { | ||
| 84 | 84 | |
| 85 | 85 | test("the panel script draws the line for a pull, never for production or an unknown key", () => { |
| 86 | 86 | const pull = { app: "notes", env: "pull-3", pull: "3" }; |
| 87 | // The word sits in its own slot, so it is its own text beside "Pull #3: ". | |
| 87 | // The word sits in its own slot, so it is its own text beside "Preview of #3: ". | |
| 88 | 88 | const line = (set: Record<string, string>) => { |
| 89 | 89 | const t = drawn(set); |
| 90 | const i = t.indexOf("Pull #3: "); | |
| 90 | const i = t.indexOf("Preview of #3: "); | |
| 91 | 91 | return i < 0 ? null : `${t[i]}${t[i + 1]}`; |
| 92 | 92 | }; |
| 93 | expect(line({ ...pull, check: "failed" })).toBe(`Pull #3: ${CHECK_WORDS.failed}`); | |
| 94 | expect(line({ ...pull, check: "cancelled" })).toBe("Pull #3: cancelled"); | |
| 95 | expect(drawn({ ...pull, check: "bogus" }).filter((t) => t.startsWith("Pull"))).toEqual(["Pull #3"]); | |
| 96 | expect(drawn({ ...pull, check: "constructor" }).filter((t) => t.startsWith("Pull"))).toEqual(["Pull #3"]); | |
| 93 | expect(line({ ...pull, check: "failed" })).toBe(`Preview of #3: ${CHECK_WORDS.failed}`); | |
| 94 | expect(line({ ...pull, check: "cancelled" })).toBe("Preview of #3: cancelled"); | |
| 95 | expect(drawn({ ...pull, check: "bogus" }).filter((t) => t.startsWith("Preview"))).toEqual(["Preview of #3"]); | |
| 96 | expect(drawn({ ...pull, check: "constructor" }).filter((t) => t.startsWith("Preview"))).toEqual(["Preview of #3"]); | |
| 97 | 97 | expect(drawn(pull).some((t) => /^(Checks|No checks)/.test(t))).toBe(false); |
| 98 | 98 | // Production, even handed a check, names the app and says no check. |
| 99 | 99 | const prod = drawn({ app: "notes", env: "production", check: "passed" }); |
test/apps-pill-freshness.test.ts +2 −2
| @@ -269,14 +269,14 @@ describe("the pill's script draws the freshness line", () => { | ||
| 269 | 269 | ]; |
| 270 | 270 | for (const [extra, said] of cases) { |
| 271 | 271 | const lines = panelLines({ ...base, ...extra }); |
| 272 | expect(lines.slice(0, 4)).toEqual(["site", "Pull #7", "Environment: preview", said]); | |
| 272 | expect(lines.slice(0, 4)).toEqual(["site", "Preview of #7", "Environment: preview", said]); | |
| 273 | 273 | expect(lines.filter((l) => words.includes(l as never))).toEqual([said]); |
| 274 | 274 | } |
| 275 | 275 | }); |
| 276 | 276 | |
| 277 | 277 | test("the line follows the pull when there is no title", () => { |
| 278 | 278 | const lines = panelLines({ ...base, title: "", state: "merged" }); |
| 279 | expect(lines.slice(0, 4)).toEqual(["site", "Pull #7", "Environment: preview", FRESHNESS_WORDS.merged]); | |
| 279 | expect(lines.slice(0, 4)).toEqual(["site", "Preview of #7", "Environment: preview", FRESHNESS_WORDS.merged]); | |
| 280 | 280 | }); |
| 281 | 281 | |
| 282 | 282 | test("merged and closed win over deploying and behind; deploying wins over behind", () => { |
test/apps-toolbar.test.ts +3 −3
| @@ -476,19 +476,19 @@ describe("the pill's keyboard and touch behaviour", () => { | ||
| 476 | 476 | |
| 477 | 477 | |
| 478 | 478 | test("on a preview with a repo the pull line links to the pull; otherwise it is plain text", () => { |
| 479 | const a = tree({ app: "notes", repo: "alice/notes", pull: "12" }).lines.find((l) => l.textContent === "Pull #12")!; | |
| 479 | const a = tree({ app: "notes", repo: "alice/notes", pull: "12" }).lines.find((l) => l.textContent === "Preview of #12")!; | |
| 480 | 480 | expect(a.tag).toBe("a"); |
| 481 | 481 | expect(a.href).toBe("https://forge.test/alice/notes/pulls/12"); |
| 482 | 482 | expect(a.style.cssText).toContain("min-height:44px"); |
| 483 | 483 | const prod = tree({ app: "notes", repo: "alice/notes", env: "production", pull: "12" }); |
| 484 | expect(prod.lines.some((l) => l.textContent.startsWith("Pull #"))).toBe(false); | |
| 484 | expect(prod.lines.some((l) => l.textContent.startsWith("Preview of #"))).toBe(false); | |
| 485 | 485 | expect(prod.lines.some((l) => l.textContent === "production")).toBe(true); |
| 486 | 486 | // An unknown environment with no pull draws no environment line at all. |
| 487 | 487 | const unknown = tree({ app: "notes", repo: "alice/notes", env: "staging" }); |
| 488 | 488 | expect(unknown.lines.some((l) => l.textContent === "production" || l.textContent.startsWith("preview"))).toBe(false); |
| 489 | 489 | for (const bad of [{ pull: "12x" }, { pull: "../1" }, { pull: "1234567890" }, { repo: "" }]) { |
| 490 | 490 | const t = tree({ app: "notes", repo: "alice/notes", pull: "12", ...bad }); |
| 491 | const l = t.lines.find((x) => x.textContent.startsWith("Pull #"))!; | |
| 491 | const l = t.lines.find((x) => x.textContent.startsWith("Preview of #"))!; | |
| 492 | 492 | expect(l.tag === "a").toBe(false); |
| 493 | 493 | } |
| 494 | 494 | }); |
test/lost-journey.test.ts +6 −6
| @@ -234,7 +234,7 @@ describe("lost journey: where you are and three exits", () => { | ||
| 234 | 234 | // One link to the pull's page: the Pull link, not a second "Home" beside it. |
| 235 | 235 | expect(run.named("Home")).toBeUndefined(); |
| 236 | 236 | |
| 237 | const pullLink = run.built.find((e) => e.tag === "a" && String(e.textContent).startsWith(`Pull #${pull}`))!; | |
| 237 | const pullLink = run.built.find((e) => e.tag === "a" && String(e.textContent).startsWith(`Preview of #${pull}`))!; | |
| 238 | 238 | expect(focusable(pullLink)).toBe(true); |
| 239 | 239 | expect(pullLink.href).toBe(`${origin}/alice/public/pulls/${pull}`); |
| 240 | 240 | |
| @@ -266,7 +266,7 @@ describe("lost journey: where you are and three exits", () => { | ||
| 266 | 266 | const run = await boot(html.replace(/data-repo="[^"]*"/, `data-repo="${repo}"`), await crewOf(host, cookie), `http://${host}/`); |
| 267 | 267 | const hrefs = run.built.filter((e) => e.tag === "a").map((e) => String(e.href ?? "")); |
| 268 | 268 | expect(hrefs.some((h) => h.includes("/../") || /\/x$/.test(h) && !h.includes("/alice/"))).toBe(false); |
| 269 | expect(run.built.some((e) => e.tag === "a" && String(e.textContent).startsWith("Pull #"))).toBe(false); | |
| 269 | expect(run.built.some((e) => e.tag === "a" && String(e.textContent).startsWith("Preview of #"))).toBe(false); | |
| 270 | 270 | } |
| 271 | 271 | }); |
| 272 | 272 | |
| @@ -276,7 +276,7 @@ describe("lost journey: where you are and three exits", () => { | ||
| 276 | 276 | const html = await (await ask(host, "/", cookie)).text(); |
| 277 | 277 | const run = await boot(html, await crewOf(host, cookie), `http://${host}/`); |
| 278 | 278 | expect(run.named("production")).toBeDefined(); |
| 279 | expect(run.built.some((e) => String(e.textContent).startsWith("Pull #"))).toBe(false); | |
| 279 | expect(run.built.some((e) => String(e.textContent).startsWith("Preview of #"))).toBe(false); | |
| 280 | 280 | expect(run.named("Home")!.href).toBe(`${new URL(servers.url).origin}/alice/public`); |
| 281 | 281 | }); |
| 282 | 282 | |
| @@ -289,7 +289,7 @@ describe("lost journey: where you are and three exits", () => { | ||
| 289 | 289 | expect(tag[2]).toContain(` data-env="pull-${pull}"`); |
| 290 | 290 | expect(tag[2]).toContain(` data-pull="${pull}"`); |
| 291 | 291 | const run = await boot(html, await crewOf(host), `http://${host}/`); |
| 292 | expect(run.built.find((e) => e.tag === "a" && String(e.textContent).startsWith(`Pull #${pull}`))!.href).toBe(`${new URL(servers.url).origin}/alice/public/pulls/${pull}`); | |
| 292 | expect(run.built.find((e) => e.tag === "a" && String(e.textContent).startsWith(`Preview of #${pull}`))!.href).toBe(`${new URL(servers.url).origin}/alice/public/pulls/${pull}`); | |
| 293 | 293 | expect(run.named("Home")).toBeUndefined(); |
| 294 | 294 | expect(run.named("Tell the crew")).toBeUndefined(); |
| 295 | 295 | // Comment goes to the forge's own page, which asks the stranger to sign in there. |
| @@ -357,7 +357,7 @@ describe("lost journey: where you are and three exits", () => { | ||
| 357 | 357 | const session = await ownerSession(); |
| 358 | 358 | expect(session).toContain("="); |
| 359 | 359 | // The way back is the pull's page on a preview (the Pull link), else the app's (Home). |
| 360 | const back = preview ? run.built.find((e) => e.tag === "a" && String(e.textContent).startsWith(`Pull #${pull}`))! : run.named("Home")!; | |
| 360 | const back = preview ? run.built.find((e) => e.tag === "a" && String(e.textContent).startsWith(`Preview of #${pull}`))! : run.named("Home")!; | |
| 361 | 361 | expect(new URL(back.href as string).pathname).toBe(preview ? `/alice/public/pulls/${pull}` : "/alice/public"); |
| 362 | 362 | expect(Boolean(run.named("Home"))).toBe(!preview); |
| 363 | 363 | expect((await follow(back.href as string, session)).status).toBe(200); |
| @@ -370,7 +370,7 @@ describe("lost journey: where you are and three exits", () => { | ||
| 370 | 370 | |
| 371 | 371 | const strangerHtml = await (await ask(host, "/")).text(); |
| 372 | 372 | const stranger = await boot(strangerHtml, await crewOf(host), `http://${host}/page`); |
| 373 | const strangerBack = preview ? stranger.built.find((e) => e.tag === "a" && String(e.textContent).startsWith(`Pull #${pull}`))! : stranger.named("Home")!; | |
| 373 | const strangerBack = preview ? stranger.built.find((e) => e.tag === "a" && String(e.textContent).startsWith(`Preview of #${pull}`))! : stranger.named("Home")!; | |
| 374 | 374 | expect(new URL(strangerBack.href as string).pathname).toBe(preview ? `/alice/public/pulls/${pull}` : "/alice/public"); |
| 375 | 375 | expect((await follow(strangerBack.href as string)).status).toBe(200); |
| 376 | 376 | }); |
test/toolbar-back.test.ts +2 −2
| @@ -55,13 +55,13 @@ test("on production Home is the app's page on the forge, from the stored repo", | ||
| 55 | 55 | |
| 56 | 56 | test("on a pull preview the Pull link is the pull's page", () => { |
| 57 | 57 | const data = { repo: "trevato/lab", env: "preview", pull: "15657" }; |
| 58 | expect(homeFor(data, "Pull #")).toBe("https://forge.test/trevato/lab/pulls/15657"); | |
| 58 | expect(homeFor(data, "Preview of #")).toBe("https://forge.test/trevato/lab/pulls/15657"); | |
| 59 | 59 | }); |
| 60 | 60 | |
| 61 | 61 | test("a repo id with a dots-only segment never builds a link", () => { |
| 62 | 62 | for (const repo of ["../x", "x/..", "../..", "./x"]) { |
| 63 | 63 | expect(homeFor({ repo, env: "production" })).toBe("https://forge.test/elsewhere"); |
| 64 | expect(homeFor({ repo, env: "preview", pull: "7" }, "Pull #")).toBeUndefined(); | |
| 64 | expect(homeFor({ repo, env: "preview", pull: "7" }, "Preview of #")).toBeUndefined(); | |
| 65 | 65 | } |
| 66 | 66 | }); |
| 67 | 67 |
test/toolbar-check.test.ts +9 −9
| @@ -1,7 +1,7 @@ | ||
| 1 | 1 | /** |
| 2 | 2 | * The preview toolbar's pull line says green, red or checking from the pull's stored check run, and |
| 3 | * plain "Pull #N" when it has none. Already true on main (#14060); this proves it end to end: the | |
| 4 | * stored run row, then the word (#14858). | |
| 3 | * plain "Preview of #N" when it has none. Already true on main (#14060); this proves it end to end: | |
| 4 | * the stored run row, then the word (#14858). | |
| 5 | 5 | */ |
| 6 | 6 | import { Database } from "bun:sqlite"; |
| 7 | 7 | import { expect, test } from "bun:test"; |
| @@ -37,7 +37,7 @@ function row(check: PillCheck | undefined): { text: string; slot?: any } { | ||
| 37 | 37 | const win: any = { location: { origin: "https://app.test", pathname: "/" }, addEventListener() {}, matchMedia: () => ({ matches: false }) }; |
| 38 | 38 | new Function("window", "document", "location", "localStorage", "fetch", "URL", "setTimeout", "setInterval", "requestAnimationFrame", toolbarJs)( |
| 39 | 39 | win, doc, win.location, { getItem: () => null, setItem() {} }, () => new Promise(() => {}), URL, () => 0, () => 0, () => 0); |
| 40 | const link = made.find((e) => /^Pull #\d+/.test(e.textContent)); | |
| 40 | const link = made.find((e) => /^Preview of #\d+/.test(e.textContent)); | |
| 41 | 41 | return { text: link.textContent, slot: made.find((e) => e.tag === "span" && e.textContent === CHECK_WORDS[check as PillCheck]) }; |
| 42 | 42 | } |
| 43 | 43 | const word = (check: PillCheck | undefined) => row(check).text; |
| @@ -46,9 +46,9 @@ test("stored ok, failed and running runs read green, red and checking", () => { | ||
| 46 | 46 | const d = db(); |
| 47 | 47 | for (const [i, s] of ["ok", "failed", "running"].entries()) |
| 48 | 48 | d.run(`INSERT INTO run (kind, issue_id, commit_oid, state) VALUES ('check', ?, 'abc', ?)`, [`p${i}`, s]); |
| 49 | expect(word(pillCheck(d, "p0", "abc"))).toBe("Pull #12: green"); | |
| 50 | expect(word(pillCheck(d, "p1", "abc"))).toBe("Pull #12: red"); | |
| 51 | expect(word(pillCheck(d, "p2", "abc"))).toBe("Pull #12: checking"); | |
| 49 | expect(word(pillCheck(d, "p0", "abc"))).toBe("Preview of #12: green"); | |
| 50 | expect(word(pillCheck(d, "p1", "abc"))).toBe("Preview of #12: red"); | |
| 51 | expect(word(pillCheck(d, "p2", "abc"))).toBe("Preview of #12: checking"); | |
| 52 | 52 | }); |
| 53 | 53 | |
| 54 | 54 | test("the newest run of the head wins; another commit's run is not read", () => { |
| @@ -57,10 +57,10 @@ test("the newest run of the head wins; another commit's run is not read", () => | ||
| 57 | 57 | expect(pillCheck(d, "p", "abc")).toBe("passed"); |
| 58 | 58 | }); |
| 59 | 59 | |
| 60 | test("a pull with no check run says no check yet, and the pill draws plain Pull #N when none is sent", () => { | |
| 60 | test("a pull with no check run says no check yet, and the pill draws plain Preview of #N when none is sent", () => { | |
| 61 | 61 | expect(pillCheck(db(), "p", "abc")).toBe("none"); |
| 62 | expect(word("none")).toBe("Pull #12: no check yet"); | |
| 63 | expect(word(undefined)).toBe("Pull #12"); | |
| 62 | expect(word("none")).toBe("Preview of #12: no check yet"); | |
| 63 | expect(word(undefined)).toBe("Preview of #12"); | |
| 64 | 64 | }); |
| 65 | 65 | |
| 66 | 66 | test("the word sits in a slot as wide as the longest word, the same for every state", () => { |
test/toolbar-injection.test.ts +1 −1
| @@ -86,6 +86,6 @@ test("the pill overlays the page: fixed, out of flow, in a shadow root", () => { | ||
| 86 | 86 | }); |
| 87 | 87 | |
| 88 | 88 | test("on a preview the pill links to the pull's forge page in plain words", () => { |
| 89 | expect(toolbarJs).toContain('"Pull #"'); | |
| 89 | expect(toolbarJs).toContain('"Preview of #"'); | |
| 90 | 90 | expect(toolbarJs).toContain('"/pulls/"'); |
| 91 | 91 | }); |
test/toolbar-preview.test.ts added +76
| @@ -0,0 +1,76 @@ | ||
| 1 | /** | |
| 2 | * On a preview the toolbar reads "Preview of #N" and links to the pull; on production it reads as | |
| 3 | * before. The number comes from the forge's record of the pull, never from the host alone. | |
| 4 | */ | |
| 5 | import { afterAll, beforeAll, expect, test } from "bun:test"; | |
| 6 | import { mkdtemp, 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 { newApp } from "../src/actions/apps.ts"; | |
| 11 | import { createIssue } from "../src/core/issues.ts"; | |
| 12 | import { createUser } from "../src/core/users.ts"; | |
| 13 | import type { EnvName } from "../src/apps/data.ts"; | |
| 14 | import type { GrantWho } from "../src/apps/grants.ts"; | |
| 15 | import { getAppByRepo, type AppRecord } from "../src/core/apps.ts"; | |
| 16 | import { pillWhere, type AppTarget } from "../src/apps/proxy.ts"; | |
| 17 | import type { AppsRuntime } from "../src/apps/runtime.ts"; | |
| 18 | import { boot } from "./helpers/toolbar-boot.ts"; | |
| 19 | import { toolbarTag } from "../src/apps/toolbar.ts"; | |
| 20 | ||
| 21 | let dir: string; | |
| 22 | let app: App; | |
| 23 | let record: AppRecord; | |
| 24 | let number: number; | |
| 25 | let aliceId: string; | |
| 26 | const who = (): GrantWho => ({ id: aliceId, name: "alice", role: "admin" }); | |
| 27 | const at = (env: EnvName): AppTarget => ({ app: record, env }); | |
| 28 | const runtime = () => ({ app }) as unknown as AppsRuntime; | |
| 29 | ||
| 30 | beforeAll(async () => { | |
| 31 | dir = await mkdtemp(join(tmpdir(), "forge-toolbar-preview-")); | |
| 32 | app = createApp({ dataDir: dir, port: 0, host: "forge.test" }); | |
| 33 | const u = await createUser(app.db, { | |
| 34 | origin: "seed", trusted: true, username: "alice", email: "[email protected]", | |
| 35 | password: "a-good-passphrase", adminIfFirst: true, | |
| 36 | }); | |
| 37 | if (!u.ok) throw new Error(u.error); | |
| 38 | aliceId = u.value.id; | |
| 39 | const made = await newApp(app, u.value, { name: "open", description: "x", visibility: "public" }); | |
| 40 | if (!made.ok) throw new Error(String(made.error)); | |
| 41 | const repoId = made.value.repo.id; | |
| 42 | record = getAppByRepo(app.db, repoId)!; | |
| 43 | const p = createIssue(app.db, { repoId, authorId: u.value.id, title: "t", kind: "pull" }); | |
| 44 | if (!p.ok) throw new Error(p.error); | |
| 45 | app.db.run("INSERT INTO pull (issue_id, base_branch, head_branch, base_oid, head_oid) VALUES (?1, 'main', 'topic', ?2, ?2)", [p.value.id, "b".repeat(40)]); | |
| 46 | number = p.value.number; | |
| 47 | }, 120_000); | |
| 48 | ||
| 49 | afterAll(async () => { | |
| 50 | app.close(); | |
| 51 | await rm(dir, { recursive: true, force: true }); | |
| 52 | }); | |
| 53 | ||
| 54 | test("a preview of a recorded pull carries its number; the panel reads Preview of #N and links to it", () => { | |
| 55 | const w = pillWhere(runtime(), at(`pull-${number}`), who()); | |
| 56 | expect(w.pull).toBe(number); | |
| 57 | const tag = toolbarTag("https://forge.test", w); | |
| 58 | expect(tag).toContain(`data-pull="${number}"`); | |
| 59 | const texts = boot(null, 400, 800, { app: "open", repo: w.repo!, env: `pull-${number}`, pull: String(number) }).texts(); | |
| 60 | expect(texts).toContain(`Preview of #${number}`); | |
| 61 | }); | |
| 62 | ||
| 63 | test("a host naming a pull the record does not have shows nothing", () => { | |
| 64 | const w = pillWhere(runtime(), at("pull-9999"), who()); | |
| 65 | expect(w.pull).toBeUndefined(); | |
| 66 | const texts = boot(null, 400, 800, { app: "open", env: "pull-9999" }).texts(); | |
| 67 | expect(texts.some((t) => t.startsWith("Preview of"))).toBe(false); | |
| 68 | }); | |
| 69 | ||
| 70 | test("production reads as before", () => { | |
| 71 | const w = pillWhere(runtime(), at("production"), who()); | |
| 72 | expect(w.pull).toBeUndefined(); | |
| 73 | const texts = boot(null, 400, 800, { app: "open", env: "production" }).texts(); | |
| 74 | expect(texts).toContain("production"); | |
| 75 | expect(texts.some((t) => t.startsWith("Preview of"))).toBe(false); | |
| 76 | }); |
test/toolbar-pull-label.test.ts +2 −2
| @@ -31,12 +31,12 @@ function run(markup: string) { | ||
| 31 | 31 | const win: any = { location: { origin: "https://app.test", pathname: "/" }, addEventListener() {}, matchMedia: () => ({ matches: false }) }; |
| 32 | 32 | new Function("window", "document", "location", "localStorage", "fetch", "URL", "setTimeout", "setInterval", "requestAnimationFrame", toolbarJs)( |
| 33 | 33 | win, doc, win.location, { getItem: () => null, setItem() {} }, () => new Promise(() => {}), URL, () => 0, () => 0, () => 0); |
| 34 | return made.find((e) => e.tag === "a" && e.textContent.startsWith("Pull #")); | |
| 34 | return made.find((e) => e.tag === "a" && e.textContent.startsWith("Preview of #")); | |
| 35 | 35 | } |
| 36 | 36 | |
| 37 | 37 | test("the pull link carries the title as a one-line text child", () => { |
| 38 | 38 | const link = run(html("Add lists")); |
| 39 | expect(link.textContent).toBe("Pull #12"); | |
| 39 | expect(link.textContent).toBe("Preview of #12"); | |
| 40 | 40 | const t = link.children.find((c: any) => c.textContent === "Add lists"); |
| 41 | 41 | expect(t.tag).toBe("span"); |
| 42 | 42 | expect(t.style.cssText).toContain("white-space:nowrap"); |
test/toolbar-pull-state.test.ts +5 −5
| @@ -31,13 +31,13 @@ function line(markup: string): { textContent: string; href?: string } | undefine | ||
| 31 | 31 | const win: any = { location: { origin: "https://app.test", pathname: "/" }, addEventListener() {}, matchMedia: () => ({ matches: false }) }; |
| 32 | 32 | new Function("window", "document", "location", "localStorage", "fetch", "URL", "setTimeout", "setInterval", "requestAnimationFrame", toolbarJs)( |
| 33 | 33 | win, doc, win.location, { getItem: () => null, setItem() {} }, (u: string) => { calls.fetch.push(String(u)); return new Promise(() => {}); }, URL, () => 0, () => { calls.setInterval++; return 0; }, () => 0); |
| 34 | return made.find((e) => /^Pull #\d+/.test(e.textContent)); | |
| 34 | return made.find((e) => /^Preview of #\d+/.test(e.textContent)); | |
| 35 | 35 | } |
| 36 | 36 | |
| 37 | 37 | for (const [check, word] of [["running", "checking"], ["passed", "green"], ["failed", "red"]] as const) { |
| 38 | test(`${check} reads "Pull #12: ${word}" and links to the pull`, () => { | |
| 38 | test(`${check} reads "Preview of #12: ${word}" and links to the pull`, () => { | |
| 39 | 39 | const l = line(tag(check)); |
| 40 | expect(l!.textContent).toBe(`Pull #12: ${word}`); | |
| 40 | expect(l!.textContent).toBe(`Preview of #12: ${word}`); | |
| 41 | 41 | expect(l!.href).toBe("https://forge.test/alice/notes/pulls/12"); |
| 42 | 42 | }); |
| 43 | 43 | } |
| @@ -58,11 +58,11 @@ test("drawing the line neither polls nor fetches the pull's state", () => { | ||
| 58 | 58 | test("a hostile state is escaped in the tag and draws no state word", () => { |
| 59 | 59 | const out = tag(`"><img src=x>`); |
| 60 | 60 | expect(out).not.toContain(`"><img`); |
| 61 | expect(line(out)!.textContent).toBe("Pull #12"); | |
| 61 | expect(line(out)!.textContent).toBe("Preview of #12"); | |
| 62 | 62 | }); |
| 63 | 63 | |
| 64 | 64 | test("one link names the pull, and no separate checks row is drawn", () => { |
| 65 | 65 | const rows = (() => { const out = tag("passed"); return out; })(); |
| 66 | expect(line(rows)!.textContent).toBe("Pull #12: green"); | |
| 66 | expect(line(rows)!.textContent).toBe("Preview of #12: green"); | |
| 67 | 67 | expect(toolbarJs).not.toContain("Checks passed"); |
| 68 | 68 | }); |
test/toolbar-pull.test.ts +2 −2
| @@ -26,7 +26,7 @@ function lines(markup: string): { tag: string; textContent: string; href?: strin | ||
| 26 | 26 | const win: any = { location: { origin: "https://app.test", pathname: "/" }, addEventListener() {}, matchMedia: () => ({ matches: false }) }; |
| 27 | 27 | new Function("window", "document", "location", "localStorage", "fetch", "URL", "setTimeout", "setInterval", "requestAnimationFrame", toolbarJs)( |
| 28 | 28 | win, doc, win.location, { getItem: () => null, setItem() {} }, () => new Promise(() => {}), URL, () => 0, () => 0, () => 0); |
| 29 | return made.filter((e) => e.textContent.startsWith("Pull #")); | |
| 29 | return made.filter((e) => e.textContent.startsWith("Preview of #")); | |
| 30 | 30 | } |
| 31 | 31 | |
| 32 | 32 | test("a preview response carries the pull number and a link to the pull", () => { |
| @@ -34,7 +34,7 @@ test("a preview response carries the pull number and a link to the pull", () => | ||
| 34 | 34 | expect(out).toContain('data-pull="12"'); |
| 35 | 35 | const [link] = lines(out); |
| 36 | 36 | expect(link!.tag).toBe("a"); |
| 37 | expect(link!.textContent).toBe("Pull #12"); | |
| 37 | expect(link!.textContent).toBe("Preview of #12"); | |
| 38 | 38 | expect(link!.href).toBe("https://forge.test/alice/notes/pulls/12"); |
| 39 | 39 | }); |
| 40 | 40 |
test/toolbar-where.test.ts +1 −1
| @@ -157,7 +157,7 @@ const form = (made: any[]) => made.find((e) => e.tag === "form" && e.listeners.s | ||
| 157 | 157 | |
| 158 | 158 | test("the preview's panel names the pull with its title, linked, and has one comment form once opened", () => { |
| 159 | 159 | const { made, open } = panel(preview); |
| 160 | const link = made.find((e) => e.tag === "a" && e.textContent === "Pull #1"); | |
| 160 | const link = made.find((e) => e.tag === "a" && e.textContent === "Preview of #1"); | |
| 161 | 161 | expect(link.href).toBe("https://forge.test/alice/notes/pulls/1"); |
| 162 | 162 | // The form is not in the pill: a closed panel has fetched nothing for it. |
| 163 | 163 | expect(made.some((e) => e.tag === "textarea" && e.rows === 2)).toBe(false); |
new above
offline