oficina / equipo Public

Clone
git clone https://amadan.net/oficina/equipo

Plain git — no account needed to clone.

Download

Download this file

1//go:build browser
2
3package thintest
4
5import (
6 "fmt"
7 "testing"
8
9 "github.com/chromedp/chromedp"
10)
11
12// TestBrowserTaskRows: the redesigned rows at 1280 with a mouse and at
13// 390 with touch, light and dark, on a list past twenty rows. Every
14// action is the same size and sits in the same slot on every row; an
15// exploration waiting on its direction leads with What next?, which
16// opens its direction card; long titles clamp to two lines and the
17// detail line keeps to one; at 390 the cells restack and the action
18// takes the row's width beside the menu. Each view is saved as
19// rows-<width>-<scheme>.png when EQUIPO_BROWSER_ARTIFACTS names a
20// directory.
21func TestBrowserTaskRows(t *testing.T) {
22 f := newRowsFixture(t, 16)
23 r := f.r
24 row := func(id string) string { return `document.querySelector('[equipo-trow][data-task="` + id + `"]')` }
25 rows := `[...document.querySelectorAll('#work-tasks [equipo-trow]')]`
26 acts := `[...document.querySelectorAll('#work-tasks [equipo-act]')]`
27 box := `(e=>e.getBoundingClientRect())`
28 for _, size := range []struct {
29 w, h int64
30 touch bool
31 }{{1280, 900, false}, {390, 844, true}} {
32 for _, scheme := range []string{"light", "dark"} {
33 p := openInner(t, r.inst.URL, r.inst.Cookie(), size.w, size.h, size.touch, scheme, "reduce")
34 p.open("/tasks")
35 p.fits("tasks")
36 if n := eval[int](p, rows+`.length`); n < 20 {
37 t.Fatalf("%d rows", n)
38 }
39 p.check(acts+`.length===4`, "not one action on each of the four Needs you rows")
40
41 // Every action the same size; the menu, last, in one place.
42 p.check(`(()=>{const w=`+acts+`.map(a=>`+box+`(a).width),h=`+acts+`.map(a=>`+box+`(a).height);return Math.max(...w)-Math.min(...w)<0.5 && Math.max(...h)-Math.min(...h)<0.5})()`, "action buttons differ in size")
43 p.check(`(()=>{const m=`+rows+`.map(r=>`+box+`(r.querySelector('[equipo-menu] > summary')));return m.length>=20 && m.every(b=>Math.abs(b.right-m[0].right)<0.5 && (`+fmt.Sprint(size.touch)+` || Math.abs(b.width-m[0].width)<0.5))})()`, "the menu moves between rows")
44 p.check(`(()=>{const a=`+acts+`.map(e=>`+box+`(e));return a.every(b=>Math.abs(b.left-a[0].left)<0.5 && Math.abs(b.right-a[0].right)<0.5)})()`, "the action slot moves between rows")
45 // The icons are decoration; the label names the action.
46 p.check(acts+`.every(a=>a.querySelector('svg').getAttribute('aria-hidden')==='true' && a.textContent.trim().length>0)`, "an action's icon speaks, or it has no label")
47
48 // What next? is the exploration's action, with its fork icon.
49 next := row(f.explore) + `.querySelector('[equipo-act]')`
50 p.check(next+`.textContent.trim()==='What next?' && `+next+`.dataset.act==='next' && !!`+next+`.querySelector('svg')`, "What next? is not the exploration's action")
51 p.check(row(f.push)+`.querySelector('[equipo-act]').textContent.trim()==='Retry push' && `+row(f.rounds)+`.querySelector('[equipo-act]').textContent.trim()==='Another round'`, "Retry push or Another round")
52
53 // Long titles clamp to two lines; detail lines keep to one and
54 // carry the whole line as a tooltip.
55 title := row(f.long) + `.querySelector('[equipo-row-link]')`
56 p.check(`(()=>{const l=`+title+`;const lh=parseFloat(getComputedStyle(l).lineHeight);return `+box+`(l).height<=2*lh+1 && l.scrollHeight>l.clientHeight})()`, "the long title is not clamped to two lines")
57 p.check(`[...document.querySelectorAll('[equipo-trow-note]')].every(n=>`+box+`(n).height<=parseFloat(getComputedStyle(n).fontSize)*1.8 && (n.textContent.trim()==='' || n.title.length>0))`, "a detail line wraps or has no tooltip")
58 // The status is never cut off: it wraps, to two lines at most here.
59 p.check(`[...document.querySelectorAll('[equipo-trow] [equipo-stage-name]')].every(n=>n.scrollWidth<=n.clientWidth && n.scrollHeight<=n.clientHeight+1 && `+box+`(n).height<=parseFloat(getComputedStyle(n).lineHeight)*2+1)`, "a status is cut off or runs past two lines")
60 // No action's label overflows its button.
61 p.check(acts+`.every(a=>{const l=a.querySelector('span');return l.scrollWidth<=l.clientWidth})`, "an action's label overflows its button: "+eval[string](p, acts+`.map(a=>a.textContent.trim()+' '+a.querySelector('span').scrollWidth+'/'+a.querySelector('span').clientWidth).join(', ')`))
62
63 if size.touch {
64 // 390: no column names; project and age share the top line,
65 // the action takes the row less the menu, 40px tall.
66 p.check(`getComputedStyle(document.querySelector('[equipo-tcols]')).display==='none'`, "column names at 390")
67 p.check(rows+`.every(r=>{const a=`+box+`(r.querySelector('[equipo-trow-proj]')),g=`+box+`(r.querySelector(':scope > [equipo-ago]'));return Math.abs(a.top-g.top)<6 && g.right<=`+box+`(r).right})`, "project and age not on one line")
68 p.check(`(()=>{const r=`+row(f.retry)+`,a=`+box+`(r.querySelector('[equipo-act]')),m=`+box+`(r.querySelector('[equipo-menu] > summary')),b=`+box+`(r);const pad=parseFloat(getComputedStyle(r).paddingLeft);return Math.abs(a.left-(b.left+pad))<1 && Math.abs(m.right-(b.right-pad))<1 && a.height>=40 && m.width>=40 && a.top>=`+box+`(r.querySelector('[equipo-trow-from]')).bottom})()`, "the 390 action is not full width under From")
69 p.check(`getComputedStyle(`+row(f.retry)+`.querySelector('[equipo-trow-from] [data-long]')).display!=='none'`, "From your conversation missing at 390")
70 } else {
71 // 1280: the column names line up with their cells.
72 p.check(`(()=>{const c=[...document.querySelectorAll('[equipo-tcols] > span')].map(e=>`+box+`(e).left),r=`+row(f.retry)+`;const cells=['[equipo-trow-proj]','[equipo-trow-task]','[equipo-trow-status]','[equipo-trow-from]'].map(s=>`+box+`(r.querySelector(s)).left);return cells.every((x,i)=>Math.abs(x-c[i])<1)})()`, "column names off their cells")
73 p.check(`(()=>{const a=`+box+`(`+row(f.retry)+`.querySelector('[equipo-act]'));return a.width>=155 && a.width<=157 && a.height>=27 && a.height<=29})()`, "action is not 156 by 28")
74 // Focus: the action shows its ring and its solid fill.
75 p.check(`(()=>{const s=`+row(f.explore)+`.querySelector('a[equipo-source]')||`+row(f.explore)+`.querySelector('[equipo-row-link]');s.focus();return document.activeElement===s})()`, "focus before the action")
76 for i := 0; i < 4 && !eval[bool](p, `document.activeElement===`+next); i++ {
77 p.do(chromedp.KeyEvent("\t"))
78 }
79 p.check(`document.activeElement===`+next, "Tab did not reach What next?")
80 p.wait(`(()=>{const s=getComputedStyle(`+next+`);return s.outlineStyle==='solid' && s.color==='rgb(255, 255, 255)'})()`, "the action's focus ring and fill")
81 }
82 p.shot(fmt.Sprintf("rows-%d-%s", size.w, scheme))
83
84 // Show N more opens the rest of Done.
85 p.check(`!!document.querySelector('[equipo-trow-more]') && document.querySelectorAll('[data-group="done"] [equipo-trow]').length===1`, "Done not folded")
86 p.check(`(()=>{document.querySelector('[equipo-trow-more]').click();return true})()`, "Show more")
87 p.wait(`location.search==='?done=all' && document.querySelectorAll('[data-group="done"] [equipo-trow]').length===3`, "the rest of Done")
88
89 // What next? opens the direction card.
90 p.open("/tasks")
91 p.check(`(()=>{`+next+`.click();return true})()`, "What next? click")
92 p.wait(`location.pathname==='/tasks/`+f.explore+`' && location.hash==='#decide' && !!document.querySelector('#decide [value="build"]')`, "the direction card")
93 p.check(`(()=>{const b=document.querySelector('#decide').getBoundingClientRect();return b.top<innerHeight && b.bottom>0})()`, "the direction card is out of view")
94 p.stop()
95 }
96 }
97}
98