//go:build browser package thintest import ( "context" "encoding/json" "fmt" "strings" "testing" "github.com/chromedp/cdproto/accessibility" "github.com/chromedp/cdproto/cdp" "github.com/chromedp/chromedp" ) func TestBrowserSpecialistRows(t *testing.T) { g := newTeamGallery(t) for _, width := range []int64{1280, 390} { t.Run(fmt.Sprint(width), func(t *testing.T) { p := openInner(t, g.a.inst.URL, g.a.inst.Cookie(), width, 844, width == 390, "light", "reduce") defer p.stop() path := "/tasks" if width == 390 { path = "/work" } p.open(path) p.wait(`document.querySelector('#nav-review [equipo-clock]').textContent.length>0`, "Review's clock") p.view(fmt.Sprintf("specialist-rows-%d", width)) checkSpecialistRows(p, "Looking over the changes") }) } } func checkSpecialistRows(p *innerPage, activity string) { p.t.Helper() checks := eval[map[string]bool](p, `(()=>{ const row=document.querySelector('#nav-review'), idle=document.querySelector('#nav-engineering'); const name=row.querySelector('[equipo-spec-name]'), title=row.querySelector('[equipo-nav-task]'), activity=row.querySelector('[equipo-spec-doing]'); const box=e=>e.getBoundingClientRect(), near=(a,b)=>Math.abs(a-b)<=1; const n=box(name), t=box(title), a=box(activity), c=box(row.querySelector('[equipo-clock]')), chevron=box(row.querySelector('.icon:last-of-type')); const ts=getComputedStyle(title), as=getComputedStyle(activity), is=getComputedStyle(idle), i=box(idle), ins=box(idle.querySelector('[equipo-spec-name]')), state=box(idle.querySelector('[equipo-spec-state]')); return { 'three separate lines': t.top>=n.bottom-1 && a.top>=t.bottom-1 && t.height<=parseFloat(ts.lineHeight)+1 && a.height<=parseFloat(as.lineHeight)+1, 'right edges within 1px': near(c.right,t.right) && near(c.right,a.right), 'full width below the name': near(n.left,t.left) && near(t.left,a.left), 'chevron in its own column': chevron.left>Math.max(c.right,t.right,a.right) && near((chevron.top+chevron.bottom)/2,(n.top+n.bottom)/2), 'title ellipsis only at the end': title.scrollWidth>title.clientWidth && ts.textOverflow==='ellipsis' && ts.whiteSpace==='nowrap' && ts.overflowX==='hidden', 'activity smaller and muted': parseFloat(as.fontSize)i.height, 'full tooltip': row.querySelector('[equipo-spec-now]').title===title.textContent+' ยท '+activity.textContent, 'no horizontal overflow': document.documentElement.scrollWidth<=innerWidth+1 }; })()`) for name, ok := range checks { if !ok { p.t.Errorf("specialist rows: %s", name) } } want := []string{"Swipe from the edge to go back on the Account pane", activity} found := false p.do(chromedp.Func(func(ctx context.Context, target *chromedp.Target) error { tree, err := cdp.Call(ctx, target, accessibility.GetFullAXTree, accessibility.GetFullAXTreeParams{}) if err != nil { return err } for _, node := range tree.Nodes { if node.Ignored || node.Role == nil || node.Name == nil { continue } var role, name string if json.Unmarshal(node.Role.Value, &role) == nil && json.Unmarshal(node.Name.Value, &name) == nil && role == "link" && strings.HasPrefix(name, "Review ") && strings.Contains(name, want[0]) && strings.Contains(name, want[1]) { found = true } } return nil })) if !found { p.t.Error("specialist rows: accessible name lacks full title or activity") } }