| 1 | //go:build browser |
| 2 | |
| 3 | package thintest |
| 4 | |
| 5 | import ( |
| 6 | "context" |
| 7 | "encoding/json" |
| 8 | "fmt" |
| 9 | "strings" |
| 10 | "testing" |
| 11 | |
| 12 | "github.com/chromedp/cdproto/accessibility" |
| 13 | "github.com/chromedp/cdproto/cdp" |
| 14 | "github.com/chromedp/chromedp" |
| 15 | ) |
| 16 | |
| 17 | func TestBrowserSpecialistRows(t *testing.T) { |
| 18 | g := newTeamGallery(t) |
| 19 | for _, width := range []int64{1280, 390} { |
| 20 | t.Run(fmt.Sprint(width), func(t *testing.T) { |
| 21 | p := openInner(t, g.a.inst.URL, g.a.inst.Cookie(), width, 844, width == 390, "light", "reduce") |
| 22 | defer p.stop() |
| 23 | path := "/tasks" |
| 24 | if width == 390 { |
| 25 | path = "/work" |
| 26 | } |
| 27 | p.open(path) |
| 28 | p.wait(`document.querySelector('#nav-review [equipo-clock]').textContent.length>0`, "Review's clock") |
| 29 | p.view(fmt.Sprintf("specialist-rows-%d", width)) |
| 30 | checkSpecialistRows(p, "Looking over the changes") |
| 31 | }) |
| 32 | } |
| 33 | } |
| 34 | |
| 35 | func checkSpecialistRows(p *innerPage, activity string) { |
| 36 | p.t.Helper() |
| 37 | checks := eval[map[string]bool](p, `(()=>{ |
| 38 | const row=document.querySelector('#nav-review'), idle=document.querySelector('#nav-engineering'); |
| 39 | const name=row.querySelector('[equipo-spec-name]'), title=row.querySelector('[equipo-nav-task]'), activity=row.querySelector('[equipo-spec-doing]'); |
| 40 | const box=e=>e.getBoundingClientRect(), near=(a,b)=>Math.abs(a-b)<=1; |
| 41 | const n=box(name), t=box(title), a=box(activity), c=box(row.querySelector('[equipo-clock]')), chevron=box(row.querySelector('.icon:last-of-type')); |
| 42 | 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]')); |
| 43 | return { |
| 44 | '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, |
| 45 | 'right edges within 1px': near(c.right,t.right) && near(c.right,a.right), |
| 46 | 'full width below the name': near(n.left,t.left) && near(t.left,a.left), |
| 47 | '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), |
| 48 | 'title ellipsis only at the end': title.scrollWidth>title.clientWidth && ts.textOverflow==='ellipsis' && ts.whiteSpace==='nowrap' && ts.overflowX==='hidden', |
| 49 | 'activity smaller and muted': parseFloat(as.fontSize)<parseFloat(ts.fontSize) && as.color===getComputedStyle(row.querySelector('[equipo-spec-state]')).color && as.color!==ts.color, |
| 50 | 'idle stays one line': !idle.querySelector('[equipo-spec-now]') && near((ins.top+ins.bottom)/2,(state.top+state.bottom)/2) && i.height<=Math.max(parseFloat(is.minHeight)||0,ins.height+parseFloat(is.paddingTop)+parseFloat(is.paddingBottom)+parseFloat(is.borderTopWidth)+parseFloat(is.borderBottomWidth))+1 && box(row).height>i.height, |
| 51 | 'full tooltip': row.querySelector('[equipo-spec-now]').title===title.textContent+' · '+activity.textContent, |
| 52 | 'no horizontal overflow': document.documentElement.scrollWidth<=innerWidth+1 |
| 53 | }; |
| 54 | })()`) |
| 55 | for name, ok := range checks { |
| 56 | if !ok { |
| 57 | p.t.Errorf("specialist rows: %s", name) |
| 58 | } |
| 59 | } |
| 60 | want := []string{"Swipe from the edge to go back on the Account pane", activity} |
| 61 | found := false |
| 62 | p.do(chromedp.Func(func(ctx context.Context, target *chromedp.Target) error { |
| 63 | tree, err := cdp.Call(ctx, target, accessibility.GetFullAXTree, accessibility.GetFullAXTreeParams{}) |
| 64 | if err != nil { |
| 65 | return err |
| 66 | } |
| 67 | for _, node := range tree.Nodes { |
| 68 | if node.Ignored || node.Role == nil || node.Name == nil { |
| 69 | continue |
| 70 | } |
| 71 | var role, name string |
| 72 | 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]) { |
| 73 | found = true |
| 74 | } |
| 75 | } |
| 76 | return nil |
| 77 | })) |
| 78 | if !found { |
| 79 | p.t.Error("specialist rows: accessible name lacks full title or activity") |
| 80 | } |
| 81 | } |
| 82 | |