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

Migrated from github.com/Trevato/SO-ARM100

workbenchthis machine

A stylesheet test proves the chat Report button is at least 44x44 px and its line keeps that room before and after 'Reported' - test only #425

Merged opened this

Check · Review · Land done · Live — Landed; nothing deploys from this branch, so this is the end of its path.

Merged

smith/arm:smith/419-a-stylesheet-test-proves-the-chat-report → main 1 commit fork

  • Merged. smith/419-a-stylesheet-test-proves-the-chat-report was merged into main as f01be40.

Review

Sign in to review this change.
1 file changed +54 −0
Software/so101/src/report-layout.test.ts added +54
@@ -0,0 +1,54 @@
1 import { describe, expect, test } from "bun:test";
2 import { readdirSync, readFileSync } from "node:fs";
3
4 // Read, not rendered: the chat Report button keeps a 44 px target, and its line keeps 44 px of height before and after "Reported".
5
6 const read = (p: string) => readFileSync(new URL(p, import.meta.url), "utf8");
7 const css = [read("./viewer.html").match(/<style\b[^>]*>[\s\S]*?<\/style>/gi)!.join("\n"), ...readdirSync(new URL("./ui/", import.meta.url)).filter((f) => f.endsWith(".css")).map((f) => read(`./ui/${f}`))].join("\n").replace(/\/\*[\s\S]*?\*\//g, "");
8
9 /** Every rule whose selector list names a selector mentioning `needle`, flattened out of @media blocks. */
10 function rulesFor(needle: string): Array<{ selector: string; body: string }> {
11 const out: Array<{ selector: string; body: string }> = [];
12 const walk = (src: string) => {
13 let i = 0;
14 while (i < src.length) {
15 const open = src.indexOf("{", i);
16 if (open < 0) break;
17 let depth = 1;
18 let j = open + 1;
19 for (; j < src.length && depth; j++) depth += src[j] === "{" ? 1 : src[j] === "}" ? -1 : 0;
20 const head = src.slice(i, open).trim();
21 if (head.startsWith("@")) walk(src.slice(open + 1, j - 1));
22 else for (const s of head.split(",")) if (s.includes(needle)) out.push({ selector: s.trim(), body: src.slice(open + 1, j - 1) });
23 i = j;
24 }
25 };
26 walk(css);
27 return out;
28 }
29
30 const px = (rules: Array<{ body: string }>, prop: string) => Math.max(0, ...rules.flatMap((r) => [...r.body.matchAll(new RegExp(`(?:^|[;\\s])${prop}\\s*:\\s*(\\d+(?:\\.\\d+)?)px`, "g"))].map((m) => Number(m[1]))));
31 const plain = (sel: string) => rulesFor(sel).filter((r) => r.selector === `#chat ${sel}`);
32
33 describe("chat Report button layout", () => {
34 test("#chat .report is at least 44 x 44 px", () => {
35 const rules = plain(".report");
36 expect(rules.length).toBeGreaterThan(0);
37 expect(px(rules, "min-width")).toBeGreaterThanOrEqual(44);
38 expect(px(rules, "min-height")).toBeGreaterThanOrEqual(44);
39 });
40
41 test("#chat .rep reserves at least 44 px of height", () => {
42 const rules = plain(".rep");
43 expect(rules.length).toBeGreaterThan(0);
44 expect(px(rules, "min-height")).toBeGreaterThanOrEqual(44);
45 });
46
47 test("no rule sizes the button by :disabled or by its text, and nothing shrinks it", () => {
48 const all = rulesFor(".report");
49 for (const r of all) expect(r.selector).not.toMatch(/:disabled|:enabled|\[disabled|:empty|\[aria-label|\[name|:lang|:has\(/);
50 const box = /(^|[;\s])(width|height|min-width|min-height|max-width|max-height|padding[\w-]*|margin[\w-]*|font-size|line-height|display|flex[\w-]*|border[\w-]*|content)\s*:/;
51 for (const r of all.filter((r) => /:disabled|\[disabled|::?(before|after)/.test(r.selector))) expect(r.body).not.toMatch(box);
52 for (const r of all) expect(r.body).not.toMatch(/(^|[;\s])(max-width|max-height|width|height)\s*:\s*(\d{1,2}(\.\d+)?|[0-3]\d|4[0-3])px/);
53 });
54 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs