| 1 | //go:build browser |
| 2 | |
| 3 | package thintest |
| 4 | |
| 5 | import ( |
| 6 | "fmt" |
| 7 | "strings" |
| 8 | "testing" |
| 9 | |
| 10 | "amadan.net/rastrillo/fiesta/check/rhythm" |
| 11 | ) |
| 12 | |
| 13 | // rhythmSkip are the regions the audit neither measures nor walks |
| 14 | // into: what a closed disclosure holds, which is not drawn (Fiesta |
| 15 | // 1.6.1's audit still reads its boxes, so a row's closed menu read as |
| 16 | // a Cancel button over the next group's heading); a roster report's |
| 17 | // eyebrow, its stage and the Needs you chip, which name the title under |
| 18 | // them and sit as close to it as a heading's own words; a team row's |
| 19 | // icon tile, drawn centred in a row taller than it, which is not the |
| 20 | // row's first line; model-written |
| 21 | // Markdown (a step's summary, a task's brief), spaced as the document |
| 22 | // it is; and the roster's day bar, a chart. |
| 23 | var rhythmSkip = []string{ |
| 24 | "details:not([open]) > :not(summary)", |
| 25 | "[equipo-roster-report-head] > :not(h3, [equipo-roster-why])", |
| 26 | "[equipo-team-mark]", |
| 27 | "[equipo-md]", |
| 28 | "[equipo-daybar]", |
| 29 | } |
| 30 | |
| 31 | // openDisclosures opens every closed disclosure in the page's flow, the |
| 32 | // ones whose contents take their place on the page (a machine's |
| 33 | // details, Change on a merge policy, a card's sub-chat), and leaves |
| 34 | // shut the menus whose contents float over it. |
| 35 | const openDisclosures = `(()=>{let n=0;for(const d of document.querySelectorAll('main details:not([open])')){d.open=true;const floats=[...d.children].some(c=>c.tagName!=='SUMMARY'&&['absolute','fixed'].includes(getComputedStyle(c).position));if(floats){d.open=false}else{n++}}return n})()` |
| 36 | |
| 37 | // audit runs Fiesta's rhythm audit over the page's main region, and |
| 38 | // over its feed when it has one: the audit reads a list as one block of |
| 39 | // text and does not walk into it, and the roster, a conversation's |
| 40 | // cards and messages, is a list. |
| 41 | func (p *innerPage) audit() []rhythm.Finding { |
| 42 | p.t.Helper() |
| 43 | found := eval[[]rhythm.Finding](p, rhythm.Expression("main", rhythm.Options{Skip: rhythmSkip})) |
| 44 | if eval[bool](p, `!!document.querySelector('main [equipo-feed]')`) { |
| 45 | found = append(found, eval[[]rhythm.Finding](p, rhythm.Expression("main [equipo-feed]", rhythm.Options{Skip: rhythmSkip}))...) |
| 46 | } |
| 47 | return found |
| 48 | } |
| 49 | |
| 50 | // brokenStacks is every stack in the page that an app's own rules have |
| 51 | // bent: one that is not a column, centres its blocks, or has another |
| 52 | // gap than the stack's, which its margins are measured against. A |
| 53 | // card's centred row turned a stack into a centred column, which the |
| 54 | // audit, reading only vertical gaps, cannot see. |
| 55 | func (p *innerPage) brokenStacks() string { |
| 56 | p.t.Helper() |
| 57 | return eval[string](p, `(()=>{const gap=getComputedStyle(document.documentElement).getPropertyValue('--rst-sp-2').trim();const px=parseFloat(gap)*parseFloat(getComputedStyle(document.documentElement).fontSize);return [...document.querySelectorAll('main [rst-stack]')].filter(e=>{const s=getComputedStyle(e);return e.getClientRects().length&&(s.display!=='flex'||s.flexDirection!=='column'||s.flexWrap!=='nowrap'||s.alignItems.includes('center')||Math.abs(parseFloat(s.rowGap)-px)>0.5)}).map(e=>{const s=getComputedStyle(e);return e.tagName.toLowerCase()+[...e.attributes].filter(a=>a.name!=='rst-stack').slice(0,2).map(a=>'['+a.name+']').join('')+' ('+s.display+' '+s.flexDirection+' '+s.flexWrap+', align '+s.alignItems+', gap '+s.rowGap+')'}).join('; ')})()`) |
| 58 | } |
| 59 | |
| 60 | // rhythmScreens are the screens the audit reads: the roster and the |
| 61 | // screens beside it, the work lists and pages, the team and the |
| 62 | // settings, and the forms under them. |
| 63 | // |
| 64 | // Left out, and why: /projects/accounts, an old page nothing links to, |
| 65 | // whose budget heading is followed straight by a subheading (the |
| 66 | // stack puts both 0.5rem apart, which the audit reads as a heading no |
| 67 | // closer to its content); the sign-in door, which is estilo's card and |
| 68 | // audited there; and the pages that need a fixture the gallery does not |
| 69 | // make: a question, a rendered change, a task's preview, plan and |
| 70 | // thread, a job, an invitation link, a device approval and the two |
| 71 | // template diffs. |
| 72 | func rhythmScreens(g *gallery) [][2]string { |
| 73 | return append(innerScreens(g), |
| 74 | [2]string{"roster", "/conversation"}, |
| 75 | [2]string{"jobs", "/jobs"}, |
| 76 | [2]string{"specialist", "/team/review"}, |
| 77 | [2]string{"people", "/people"}, |
| 78 | [2]string{"invite-new", "/invites/new"}, |
| 79 | [2]string{"teams", "/teams"}, |
| 80 | [2]string{"settings", "/conversation/settings"}, |
| 81 | [2]string{"autonomy", "/conversation/settings/autonomy"}, |
| 82 | [2]string{"thinking", "/conversation/settings/thinking"}, |
| 83 | [2]string{"housekeeping-settings", "/conversation/settings/housekeeping"}, |
| 84 | [2]string{"connections", "/conversation/settings/connections"}, |
| 85 | [2]string{"connections-add", "/conversation/settings/connections/add"}, |
| 86 | [2]string{"machines", "/conversation/settings/machines"}, |
| 87 | [2]string{"machines-add", "/conversation/settings/machines/add"}, |
| 88 | [2]string{"notebook", "/conversation/settings/notebook"}, |
| 89 | [2]string{"usage", "/usage"}, |
| 90 | [2]string{"housekeeping", "/housekeeping"}, |
| 91 | [2]string{"account", "/settings"}, |
| 92 | [2]string{"devices", "/settings/devices"}, |
| 93 | [2]string{"coordinator", "/settings/coordinator"}, |
| 94 | [2]string{"recovery", "/settings/recovery"}, |
| 95 | [2]string{"preferences", "/preferences"}, |
| 96 | [2]string{"onboarding", "/onboarding"}, |
| 97 | [2]string{"task-new", "/tasks/new"}, |
| 98 | [2]string{"merge", "/tasks/" + g.unchecked + "/merge"}, |
| 99 | [2]string{"project-new", "/projects/new"}, |
| 100 | [2]string{"playbooks", "/playbooks"}, |
| 101 | [2]string{"playbook-new", "/playbooks/new"}, |
| 102 | [2]string{"templates", "/templates"}, |
| 103 | [2]string{"specialist-new", "/specialists/new"}, |
| 104 | [2]string{"specialist-page", "/specialists/review"}, |
| 105 | [2]string{"task-move", "/tasks/" + g.unchecked + "/move"}, |
| 106 | ) |
| 107 | } |
| 108 | |
| 109 | // landed fails unless the browser is on path's own page, drawn: not |
| 110 | // redirected, not an error page, its fonts in. |
| 111 | func (p *innerPage) landed(name, path string) { |
| 112 | p.t.Helper() |
| 113 | p.wait(`document.fonts.status==='loaded'`, name+"'s fonts") |
| 114 | if got := eval[string](p, `location.pathname+location.search`); got != path { |
| 115 | p.t.Fatalf("%s: asked for %s, landed on %s", name, path, got) |
| 116 | } |
| 117 | if eval[bool](p, `!!document.querySelector('main [rst-error]')`) { |
| 118 | p.t.Fatalf("%s (%s) is an error page: %s", name, path, eval[string](p, `document.querySelector('main [rst-error]').textContent.replace(/\s+/g,' ').trim()`)) |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | // TestBrowserRhythm: every main screen, the roster first among them, |
| 123 | // read by Fiesta's rhythm audit at a desktop width and a phone's (Paul, |
| 124 | // 2026-11-22: no ad-hoc spacing), as it loads and again with its |
| 125 | // disclosures open. Every gap between two of a screen's blocks is a |
| 126 | // step of the spacing scale, no text rests on a control, every heading |
| 127 | // sits closer to its own content than to what comes before it, and |
| 128 | // every stack is the stack's own column. |
| 129 | func TestBrowserRhythm(t *testing.T) { |
| 130 | g := newGallery(t) |
| 131 | r := newRollupRig(t) |
| 132 | var failed []string |
| 133 | read := func(p *innerPage, what string) { |
| 134 | if found := p.audit(); len(found) > 0 { |
| 135 | failed = append(failed, fmt.Sprintf("%s: %s", what, rhythm.Report(found))) |
| 136 | } |
| 137 | if b := p.brokenStacks(); b != "" { |
| 138 | failed = append(failed, fmt.Sprintf("%s: these stacks are not the stack's column: %s", what, b)) |
| 139 | } |
| 140 | if eval[int](p, openDisclosures) > 0 { |
| 141 | if found := p.audit(); len(found) > 0 { |
| 142 | failed = append(failed, fmt.Sprintf("%s, disclosures open: %s", what, rhythm.Report(found))) |
| 143 | } |
| 144 | if b := p.brokenStacks(); b != "" { |
| 145 | failed = append(failed, fmt.Sprintf("%s, disclosures open: these stacks are not the stack's column: %s", what, b)) |
| 146 | } |
| 147 | } |
| 148 | } |
| 149 | for _, size := range []struct { |
| 150 | w, h int64 |
| 151 | touch bool |
| 152 | }{{1280, 900, false}, {390, 844, true}} { |
| 153 | p := openInner(t, g.a.inst.URL, g.a.inst.Cookie(), size.w, size.h, size.touch, "light", "reduce") |
| 154 | for _, s := range rhythmScreens(g) { |
| 155 | if s[0] == "index" && size.w > 800 { |
| 156 | continue |
| 157 | } |
| 158 | p.open(s[1]) |
| 159 | p.landed(s[0], s[1]) |
| 160 | read(p, fmt.Sprintf("%s (%s) at %dpx", s[0], s[1], size.w)) |
| 161 | } |
| 162 | p.stop() |
| 163 | // The roster with yesterday rolled up, its reports and its |
| 164 | // decision cards. |
| 165 | p = openInner(t, r.inst.URL, r.inst.Cookie(), size.w, size.h, size.touch, "light", "reduce") |
| 166 | p.open("/conversation") |
| 167 | p.landed("roster", "/conversation") |
| 168 | p.wait(`document.querySelector('[equipo-roster-report]')`, "the roster's report") |
| 169 | read(p, fmt.Sprintf("roster with reports at %dpx", size.w)) |
| 170 | p.stop() |
| 171 | } |
| 172 | if len(failed) > 0 { |
| 173 | t.Fatal(strings.Join(failed, "\n\n")) |
| 174 | } |
| 175 | } |
| 176 | |