//go:build browser package thintest import ( "fmt" "testing" "github.com/chromedp/chromedp" ) // TestBrowserTaskRows: the redesigned rows at 1280 with a mouse and at // 390 with touch, light and dark, on a list past twenty rows. Every // action is the same size and sits in the same slot on every row; an // exploration waiting on its direction leads with What next?, which // opens its direction card; long titles clamp to two lines and the // detail line keeps to one; at 390 the cells restack and the action // takes the row's width beside the menu. Each view is saved as // rows--.png when EQUIPO_BROWSER_ARTIFACTS names a // directory. func TestBrowserTaskRows(t *testing.T) { f := newRowsFixture(t, 16) r := f.r row := func(id string) string { return `document.querySelector('[equipo-trow][data-task="` + id + `"]')` } rows := `[...document.querySelectorAll('#work-tasks [equipo-trow]')]` acts := `[...document.querySelectorAll('#work-tasks [equipo-act]')]` box := `(e=>e.getBoundingClientRect())` for _, size := range []struct { w, h int64 touch bool }{{1280, 900, false}, {390, 844, true}} { for _, scheme := range []string{"light", "dark"} { p := openInner(t, r.inst.URL, r.inst.Cookie(), size.w, size.h, size.touch, scheme, "reduce") p.open("/tasks") p.fits("tasks") if n := eval[int](p, rows+`.length`); n < 20 { t.Fatalf("%d rows", n) } p.check(acts+`.length===4`, "not one action on each of the four Needs you rows") // Every action the same size; the menu, last, in one place. 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") 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") 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") // The icons are decoration; the label names the action. 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") // What next? is the exploration's action, with its fork icon. next := row(f.explore) + `.querySelector('[equipo-act]')` p.check(next+`.textContent.trim()==='What next?' && `+next+`.dataset.act==='next' && !!`+next+`.querySelector('svg')`, "What next? is not the exploration's action") 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") // Long titles clamp to two lines; detail lines keep to one and // carry the whole line as a tooltip. title := row(f.long) + `.querySelector('[equipo-row-link]')` 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") 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") // The status is never cut off: it wraps, to two lines at most here. 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") // No action's label overflows its button. 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(', ')`)) if size.touch { // 390: no column names; project and age share the top line, // the action takes the row less the menu, 40px tall. p.check(`getComputedStyle(document.querySelector('[equipo-tcols]')).display==='none'`, "column names at 390") 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") 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") p.check(`getComputedStyle(`+row(f.retry)+`.querySelector('[equipo-trow-from] [data-long]')).display!=='none'`, "From your conversation missing at 390") } else { // 1280: the column names line up with their cells. 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") 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") // Focus: the action shows its ring and its solid fill. 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") for i := 0; i < 4 && !eval[bool](p, `document.activeElement===`+next); i++ { p.do(chromedp.KeyEvent("\t")) } p.check(`document.activeElement===`+next, "Tab did not reach What next?") p.wait(`(()=>{const s=getComputedStyle(`+next+`);return s.outlineStyle==='solid' && s.color==='rgb(255, 255, 255)'})()`, "the action's focus ring and fill") } p.shot(fmt.Sprintf("rows-%d-%s", size.w, scheme)) // Show N more opens the rest of Done. p.check(`!!document.querySelector('[equipo-trow-more]') && document.querySelectorAll('[data-group="done"] [equipo-trow]').length===1`, "Done not folded") p.check(`(()=>{document.querySelector('[equipo-trow-more]').click();return true})()`, "Show more") p.wait(`location.search==='?done=all' && document.querySelectorAll('[data-group="done"] [equipo-trow]').length===3`, "the rest of Done") // What next? opens the direction card. p.open("/tasks") p.check(`(()=>{`+next+`.click();return true})()`, "What next? click") p.wait(`location.pathname==='/tasks/`+f.explore+`' && location.hash==='#decide' && !!document.querySelector('#decide [value="build"]')`, "the direction card") p.check(`(()=>{const b=document.querySelector('#decide').getBoundingClientRect();return b.top0})()`, "the direction card is out of view") p.stop() } } }