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

A visual test pins Talk's layout at 360, 1280 and 2560 px #16531

Merged opened this

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

Merged

scout/forge:scout/15817-a-visual-test-pins-talk-s-layout-at-360 → main 0 commits fork

  • Merged. scout/15817-a-visual-test-pins-talk-s-layout-at-360 was merged into main as 37a5cba.

Review

Sign in to review this change.
1 file changed +104 −0
test/talk.looks.test.ts added +104
@@ -0,0 +1,104 @@
1 /**
2 * Talk's layout is pinned at 360, 1280 and 2560 px (#15817, the last part of #15734), in a real
3 * Chromium, in the looks lane. One seeded conversation: a long code block, a long link and a
4 * message with an attachment. At each width the page does not scroll sideways, the composer is
5 * inside the viewport and the thread is no wider than its cap (`.talk`, 46 rem = 736 px).
6 * Skipped, and says so, where no Chromium starts. The finer cases (tablet, empty first visit)
7 * stay in talk-layout.test.ts.
8 */
9 import { afterAll, beforeAll, expect, test } from "bun:test";
10 import { mkdtemp, rm } from "node:fs/promises";
11 import { tmpdir } from "node:os";
12 import { join } from "node:path";
13 import { createApp, type App } from "../src/app.ts";
14 import { appendTurn, openConversation } from "../src/core/conversations.ts";
15 import { attach, storeFile } from "../src/core/conversation_files.ts";
16 import { createSession } from "../src/core/sessions.ts";
17 import { createUser } from "../src/core/users.ts";
18 import { serve, type Servers } from "../src/http/server.ts";
19 import { findChromium } from "../src/looks/capture.ts";
20 import { chromiumRuns, evaluateLoaded } from "./helpers/chrome.ts";
21 import { quietLogs } from "./helpers/globals.ts";
22 import { promote } from "./helpers/members.ts";
23
24 quietLogs();
25
26 const found = findChromium();
27 const chromium = found !== undefined && chromiumRuns(found) ? found : undefined;
28 if (chromium === undefined) console.log("SKIPPING: no chromium that starts on this machine, so Talk's layout is not pinned at 360, 1280 and 2560 px");
29
30 /** The thread's cap: `max-width: 46rem` on `.talk`. */
31 const THREAD_CAP = 736;
32
33 interface Seen {
34 scrollWidth: number;
35 vw: number;
36 vh: number;
37 thread: { left: number; right: number; width: number } | null;
38 composer: { top: number; bottom: number; left: number; right: number } | null;
39 code: boolean;
40 link: boolean;
41 attachment: { right: number } | null;
42 }
43
44 const EXPRESSION = `(() => {
45 const r = (sel) => { const el = document.querySelector(sel); return el ? el.getBoundingClientRect() : null; };
46 const thread = r(".talk-log"), composer = r(".talk-compose"), file = r(".talk-files a");
47 return JSON.stringify({
48 scrollWidth: document.documentElement.scrollWidth,
49 vw: document.documentElement.clientWidth,
50 vh: window.innerHeight,
51 thread: thread && { left: thread.left, right: thread.right, width: thread.width },
52 composer: composer && { top: composer.top, bottom: composer.bottom, left: composer.left, right: composer.right },
53 code: !!document.querySelector(".talk-body pre"),
54 link: !!document.querySelector(".talk-body a"),
55 attachment: file && { right: file.right },
56 });
57 })()`;
58
59 let dir: string;
60 let app: App;
61 let servers: Servers;
62 let token: string;
63
64 beforeAll(async () => {
65 dir = await mkdtemp(join(tmpdir(), "forge-talk-looks-"));
66 app = createApp({ dataDir: dir, port: 0 });
67 servers = await serve(app);
68 const made = await createUser(app.db, { origin: "seed", trusted: true, username: "alice", email: "[email protected]", password: "a-good-passphrase", adminIfFirst: true });
69 if (!made.ok) throw new Error(made.error);
70 promote(app.db, made.value);
71 const chat = openConversation(app.db, made.value.id);
72 const asked = appendTurn(app.db, made.value.id, chat.id, { role: "person", text: "look at this file" });
73 if (!asked.ok) throw new Error(asked.error);
74 const stored = storeFile(app.db, dir, made.value.id, `${"notes-".repeat(12)}.txt`, new TextEncoder().encode("some notes\n"));
75 if (!stored.ok) throw new Error(stored.error);
76 attach(app.db, [stored.value], asked.value.id);
77 const long = "a".repeat(180);
78 const said = appendTurn(app.db, made.value.id, chat.id, { role: "agent", text: `See [https://example.com/${long}](https://example.com/${long}) for more.\n\n\`\`\`\n${"x".repeat(300)}\n\`\`\`\n` });
79 if (!said.ok) throw new Error(said.error);
80 token = createSession(app.db, made.value.id).token;
81 }, 30_000);
82 afterAll(async () => {
83 servers.stop();
84 app.close();
85 await rm(dir, { recursive: true, force: true });
86 });
87
88 for (const [width, height] of [[360, 740], [1280, 800], [2560, 1300]] as const) {
89 test.skipIf(chromium === undefined)(`/talk at ${width} px: no sideways scroll, the composer in view, the thread within its cap`, async () => {
90 const raw = await evaluateLoaded(chromium!, `${servers.url}/talk`, { width, height }, [{ name: "forge_session", value: token }], EXPRESSION);
91 const s = JSON.parse(raw) as Seen;
92 const note = `measured: ${raw}`;
93 // The seeded content is on the page, or the test would pass on an empty one.
94 expect([note, s.code, s.link, s.attachment !== null]).toEqual([note, true, true, true]);
95 expect([note, s.vw]).toEqual([note, width]);
96 expect([note, s.scrollWidth <= width]).toEqual([note, true]);
97 expect([note, s.attachment!.right <= width]).toEqual([note, true]);
98 expect(s.composer).not.toBeNull();
99 const inView = s.composer!.top >= 0 && s.composer!.bottom <= s.vh + 1 && s.composer!.left >= 0 && s.composer!.right <= width + 1;
100 expect([note, inView]).toEqual([note, true]);
101 expect(s.thread).not.toBeNull();
102 expect([note, s.thread!.width <= Math.min(width, THREAD_CAP) + 1]).toEqual([note, true]);
103 }, 30_000);
104 }

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs