Public: anyone can read this; the crew can change it.

The forge toolbar in a preview shows its pull number and links back to the pull in one tap #13415

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

scout/forge:scout/13395-the-forge-toolbar-in-a-preview-shows-its → main 2 commits fork 1 thread · 1 unresolved

  • Merged. scout/13395-the-forge-toolbar-in-a-preview-shows-its was merged into main as 5551306.

Review

Sign in to review this change.
1 file changed +53 −0
test/toolbar-pull.test.ts added +53
@@ -0,0 +1,53 @@
1 /** A preview's toolbar names its pull and links to it; production's carries no pull (#13395). */
2 import { expect, test } from "bun:test";
3 import { toolbarJs, withToolbar } from "../src/apps/toolbar.ts";
4
5 const page = new TextEncoder().encode("<html><body><p>hi</p></body></html>");
6 const html = (where: Parameters<typeof withToolbar>[2]) =>
7 new TextDecoder().decode(withToolbar(page, "https://forge.test", where));
8
9 /** Run the client on the data attributes of the tag in `markup`; returns the panel's lines. */
10 function lines(markup: string): { tag: string; textContent: string; href?: string; style: any }[] {
11 const data: Record<string, string> = {};
12 const attrs = /<script ([^>]*)>/.exec(markup)![1]!;
13 for (const m of attrs.matchAll(/data-([a-z]+)="([^"]*)"/g)) data[m[1]!] = m[2]!.replace(/&amp;/g, "&");
14 const made: any[] = [];
15 const el = (tag: string): any => ({
16 tag, style: {}, dataset: {}, children: [], hidden: false, textContent: "",
17 appendChild(c: any) { this.children.push(c); return c; },
18 setAttribute() {}, addEventListener() {}, classList: { add() {}, remove() {} },
19 attachShadow() { return el("shadow"); },
20 });
21 const doc: any = {
22 referrer: "", currentScript: { src: "/__forge/t.js", dataset: data },
23 createElement: (t: string) => { const e = el(t); made.push(e); return e; },
24 addEventListener() {}, body: el("body"), documentElement: el("html"),
25 };
26 const win: any = { location: { origin: "https://app.test", pathname: "/" }, addEventListener() {}, matchMedia: () => ({ matches: false }) };
27 new Function("window", "document", "location", "localStorage", "fetch", "URL", "setTimeout", "setInterval", "requestAnimationFrame", toolbarJs)(
28 win, doc, win.location, { getItem: () => null, setItem() {} }, () => new Promise(() => {}), URL, () => 0, () => 0, () => 0);
29 return made.filter((e) => e.textContent.startsWith("Pull #"));
30 }
31
32 test("a preview response carries the pull number and a link to the pull", () => {
33 const out = html({ app: "notes", repo: "alice/notes", env: "pull-12", pull: 12 });
34 expect(out).toContain('data-pull="12"');
35 const [link] = lines(out);
36 expect(link!.tag).toBe("a");
37 expect(link!.textContent).toBe("Pull #12");
38 expect(link!.href).toBe("https://forge.test/alice/notes/pulls/12");
39 });
40
41 test("a production response carries no pull and draws no pull line", () => {
42 const out = html({ app: "notes", repo: "alice/notes", env: "production" });
43 expect(out).not.toContain("data-pull=");
44 expect(lines(out)).toEqual([]);
45 });
46
47 test("the pull link row keeps a fixed 44px height and the tag adds no script or style", () => {
outdated

Overclaims: the name says no fixed height change, but only the script count and absence of <style> are checked. Assert the pull link carries min-height:44px (via the captured element style/cssText) and rename the test to match.

48 const out = html({ app: "notes", repo: "alice/notes", env: "pull-12", pull: 12 });
49 const [link] = lines(out);
50 expect(link!.style.cssText).toContain("min-height:44px");
51 expect(out.match(/<script/g)?.length).toBe(1);
52 expect(out).not.toContain("<style");
53 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs