//go:build browser package thintest import ( "fmt" "strings" "testing" "amadan.net/rastrillo/fiesta/check/rhythm" ) // rhythmSkip are the regions the audit neither measures nor walks // into: what a closed disclosure holds, which is not drawn (Fiesta // 1.6.1's audit still reads its boxes, so a row's closed menu read as // a Cancel button over the next group's heading); a roster report's // eyebrow, its stage and the Needs you chip, which name the title under // them and sit as close to it as a heading's own words; a team row's // icon tile, drawn centred in a row taller than it, which is not the // row's first line; model-written // Markdown (a step's summary, a task's brief), spaced as the document // it is; and the roster's day bar, a chart. var rhythmSkip = []string{ "details:not([open]) > :not(summary)", "[equipo-roster-report-head] > :not(h3, [equipo-roster-why])", "[equipo-team-mark]", "[equipo-md]", "[equipo-daybar]", } // openDisclosures opens every closed disclosure in the page's flow, the // ones whose contents take their place on the page (a machine's // details, Change on a merge policy, a card's sub-chat), and leaves // shut the menus whose contents float over it. 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})()` // audit runs Fiesta's rhythm audit over the page's main region, and // over its feed when it has one: the audit reads a list as one block of // text and does not walk into it, and the roster, a conversation's // cards and messages, is a list. func (p *innerPage) audit() []rhythm.Finding { p.t.Helper() found := eval[[]rhythm.Finding](p, rhythm.Expression("main", rhythm.Options{Skip: rhythmSkip})) if eval[bool](p, `!!document.querySelector('main [equipo-feed]')`) { found = append(found, eval[[]rhythm.Finding](p, rhythm.Expression("main [equipo-feed]", rhythm.Options{Skip: rhythmSkip}))...) } return found } // brokenStacks is every stack in the page that an app's own rules have // bent: one that is not a column, centres its blocks, or has another // gap than the stack's, which its margins are measured against. A // card's centred row turned a stack into a centred column, which the // audit, reading only vertical gaps, cannot see. func (p *innerPage) brokenStacks() string { p.t.Helper() 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('; ')})()`) } // rhythmScreens are the screens the audit reads: the roster and the // screens beside it, the work lists and pages, the team and the // settings, and the forms under them. // // Left out, and why: /projects/accounts, an old page nothing links to, // whose budget heading is followed straight by a subheading (the // stack puts both 0.5rem apart, which the audit reads as a heading no // closer to its content); the sign-in door, which is estilo's card and // audited there; and the pages that need a fixture the gallery does not // make: a question, a rendered change, a task's preview, plan and // thread, a job, an invitation link, a device approval and the two // template diffs. func rhythmScreens(g *gallery) [][2]string { return append(innerScreens(g), [2]string{"roster", "/conversation"}, [2]string{"jobs", "/jobs"}, [2]string{"specialist", "/team/review"}, [2]string{"people", "/people"}, [2]string{"invite-new", "/invites/new"}, [2]string{"teams", "/teams"}, [2]string{"settings", "/conversation/settings"}, [2]string{"autonomy", "/conversation/settings/autonomy"}, [2]string{"thinking", "/conversation/settings/thinking"}, [2]string{"housekeeping-settings", "/conversation/settings/housekeeping"}, [2]string{"connections", "/conversation/settings/connections"}, [2]string{"connections-add", "/conversation/settings/connections/add"}, [2]string{"machines", "/conversation/settings/machines"}, [2]string{"machines-add", "/conversation/settings/machines/add"}, [2]string{"notebook", "/conversation/settings/notebook"}, [2]string{"usage", "/usage"}, [2]string{"housekeeping", "/housekeeping"}, [2]string{"account", "/settings"}, [2]string{"devices", "/settings/devices"}, [2]string{"coordinator", "/settings/coordinator"}, [2]string{"recovery", "/settings/recovery"}, [2]string{"preferences", "/preferences"}, [2]string{"onboarding", "/onboarding"}, [2]string{"task-new", "/tasks/new"}, [2]string{"merge", "/tasks/" + g.unchecked + "/merge"}, [2]string{"project-new", "/projects/new"}, [2]string{"playbooks", "/playbooks"}, [2]string{"playbook-new", "/playbooks/new"}, [2]string{"templates", "/templates"}, [2]string{"specialist-new", "/specialists/new"}, [2]string{"specialist-page", "/specialists/review"}, [2]string{"task-move", "/tasks/" + g.unchecked + "/move"}, ) } // landed fails unless the browser is on path's own page, drawn: not // redirected, not an error page, its fonts in. func (p *innerPage) landed(name, path string) { p.t.Helper() p.wait(`document.fonts.status==='loaded'`, name+"'s fonts") if got := eval[string](p, `location.pathname+location.search`); got != path { p.t.Fatalf("%s: asked for %s, landed on %s", name, path, got) } if eval[bool](p, `!!document.querySelector('main [rst-error]')`) { 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()`)) } } // TestBrowserRhythm: every main screen, the roster first among them, // read by Fiesta's rhythm audit at a desktop width and a phone's (Paul, // 2026-11-22: no ad-hoc spacing), as it loads and again with its // disclosures open. Every gap between two of a screen's blocks is a // step of the spacing scale, no text rests on a control, every heading // sits closer to its own content than to what comes before it, and // every stack is the stack's own column. func TestBrowserRhythm(t *testing.T) { g := newGallery(t) r := newRollupRig(t) var failed []string read := func(p *innerPage, what string) { if found := p.audit(); len(found) > 0 { failed = append(failed, fmt.Sprintf("%s: %s", what, rhythm.Report(found))) } if b := p.brokenStacks(); b != "" { failed = append(failed, fmt.Sprintf("%s: these stacks are not the stack's column: %s", what, b)) } if eval[int](p, openDisclosures) > 0 { if found := p.audit(); len(found) > 0 { failed = append(failed, fmt.Sprintf("%s, disclosures open: %s", what, rhythm.Report(found))) } if b := p.brokenStacks(); b != "" { failed = append(failed, fmt.Sprintf("%s, disclosures open: these stacks are not the stack's column: %s", what, b)) } } } for _, size := range []struct { w, h int64 touch bool }{{1280, 900, false}, {390, 844, true}} { p := openInner(t, g.a.inst.URL, g.a.inst.Cookie(), size.w, size.h, size.touch, "light", "reduce") for _, s := range rhythmScreens(g) { if s[0] == "index" && size.w > 800 { continue } p.open(s[1]) p.landed(s[0], s[1]) read(p, fmt.Sprintf("%s (%s) at %dpx", s[0], s[1], size.w)) } p.stop() // The roster with yesterday rolled up, its reports and its // decision cards. p = openInner(t, r.inst.URL, r.inst.Cookie(), size.w, size.h, size.touch, "light", "reduce") p.open("/conversation") p.landed("roster", "/conversation") p.wait(`document.querySelector('[equipo-roster-report]')`, "the roster's report") read(p, fmt.Sprintf("roster with reports at %dpx", size.w)) p.stop() } if len(failed) > 0 { t.Fatal(strings.Join(failed, "\n\n")) } }