//go:build browser package thintest import ( "context" "fmt" "os" "path/filepath" "testing" "amadan.net/oficina/equipo/internal/wire" "github.com/chromedp/cdproto/input" "github.com/chromedp/chromedp" ) // view saves what the window shows (a drawer is fixed to it, so a full // page capture would stretch it) when EQUIPO_BROWSER_ARTIFACTS names a // directory. func (p *innerPage) view(name string) { p.t.Helper() dir := os.Getenv("EQUIPO_BROWSER_ARTIFACTS") if dir == "" { return } var buf []byte p.do(chromedp.Func(func(ctx context.Context, target *chromedp.Target) error { var err error buf, err = chromedp.CaptureScreenshot()(ctx, target) return err })) if err := os.MkdirAll(dir, 0700); err != nil { p.t.Fatal(err) } if err := os.WriteFile(filepath.Join(dir, name+".png"), buf, 0600); err != nil { p.t.Fatal(err) } } // press clicks (or taps) the middle of what expression finds. func (p *innerPage) press(expression string) { p.t.Helper() box := eval[[]float64](p, `(()=>{const e=`+expression+`;e.scrollIntoView({block:'center'});const r=e.getBoundingClientRect();return [r.x+r.width/2,r.y+r.height/2]})()`) p.do(chromedp.MouseEvent(input.DispatchMouseEventTypeMousePressed, box[0], box[1], chromedp.ButtonLeft, chromedp.ClickCount(1)), chromedp.MouseEvent(input.DispatchMouseEventTypeMouseReleased, box[0], box[1], chromedp.ButtonLeft, chromedp.ClickCount(1))) } // TestBrowserTeamPanel: the sidebar's specialists at 1280 with a mouse // and at 390 with touch. Review at work is one row of three lines with the // living mark; a click on the row opens its drawer over the page (no // navigation) with the task, the activity in plain words, each command // behind a disclosure, the files touched and what it runs on, and it // follows new activity live. Engineering idle is one muted word; its // drawer shows its recent work and asks about the task it finished: the // question goes to its kept session and the answer arrives in place. func TestBrowserTeamPanel(t *testing.T) { g := newTeamGallery(t) a := g.a newest := "Looking over the changes" for _, size := range []struct { w, h int64 touch bool }{{1280, 900, false}, {390, 844, true}} { p := openInner(t, a.inst.URL, a.inst.Cookie(), size.w, size.h, size.touch, "light", "no-preference") rail := "/tasks" if size.touch { rail = "/work" } p.open(rail) rev := `document.querySelector('#rail [data-specialist="review"]')` eng := `document.querySelector('#rail [data-specialist="engineering"]')` p.wait(rev+`.querySelector('[data-spec-star] [data-live]')`, "Review's living mark (Stardust)") checkSpecialistRows(p, newest) p.check(rev+`.querySelector('[equipo-spec-doing]').textContent===`+jsString(newest)+` && !`+rev+`.textContent.includes('/bin/') && !`+rev+`.textContent.includes('attempt')`, "Review's row content") p.check(eng+`.dataset.state==='idle' && `+eng+`.querySelector('[equipo-spec-state]').textContent==='idle' && !`+eng+`.querySelector('[equipo-spec-now]')`, "Engineering idle") p.check(`(()=>{const s=getComputedStyle(`+eng+`.querySelector('[equipo-spec-state]')),n=getComputedStyle(`+rev+`.querySelector('[equipo-spec-state]'));return s.color!==n.color})()`, "idle is not muted") p.view(fmt.Sprintf("team-panel-rail-%d", size.w)) // The drawer: a click on the row, no navigation. p.press(rev) drawer := `document.querySelector('dialog[equipo-drawer]')` p.wait(drawer+`?.open && `+drawer+`.querySelector('[equipo-team][data-team="review"]')`, "Review's drawer") p.wait(drawer+`.getAnimations().length===0`, "the drawer settled") p.stayed("drawer") p.check(`(()=>{const d=`+drawer+`.getBoundingClientRect();return d.right>=document.querySelector('main').getBoundingClientRect().right-1 && d.right<=innerWidth && d.height>=innerHeight-1 && (`+fmt.Sprint(size.touch)+` ? d.width>=innerWidth-1 : d.width li')` p.check(`(()=>{const ls=[...`+tl+`].map(l=>l.querySelector('p > span').textContent);return ls.join('|').startsWith(`+jsString(newest)+`) && ls.join('|').endsWith('Looking over the changes|Searching for interactivePopGestureRecognizer|Reading AccountNavigationHost.swift|Reading NavigationStack.swift')})()`, "the timeline in plain words, newest first") p.check(`[...`+tl+`].every(l=>!l.querySelector('p').textContent.includes('/bin/') && !l.querySelector('[equipo-team-raw]').open)`, "raw shell outside a closed disclosure") p.check(`(()=>{const d=[...`+drawer+`.querySelectorAll('[equipo-team-raw]')].find(d=>d.textContent.includes('git diff'));d.querySelector('summary').click();return d.open && d.querySelector('code').textContent==='/bin/bash -lc "git diff 1111111...a91c3d0"' && d.querySelector('code').getBoundingClientRect().height>0})()`, "the disclosure") p.check(`[...`+drawer+`.querySelectorAll('[equipo-team-files] li')].map(l=>l.textContent).join('|')==='AccountNavigationHost.swift|NavigationStack.swift'`, "files touched") p.check(drawer+`.querySelector('[equipo-team-runs]').textContent.includes('Claude') && !`+drawer+`.querySelector('[data-team-ask]')`, "runs on, and no Ask box on a running step") p.check(`document.documentElement.scrollWidth<=innerWidth+1 && `+drawer+`.querySelector('[equipo-team]').scrollWidth<=`+drawer+`.querySelector('[equipo-team]').clientWidth+1`, "the drawer scrolls sideways") p.view(fmt.Sprintf("team-panel-review-%d", size.w)) // Live: a new line arrives, plain, at the top; the open disclosure stays open. live, plain := `/bin/bash -lc "xcodebuild test -scheme Woodstar -destination 'platform=iOS Simulator,name=iPhone 16'"`, "Running the tests" if size.touch { live, plain = `/bin/bash -lc "cd ios && swift build"`, "Building the project" } a.activity(fmt.Sprintf("tp-live-%d", size.w), wire.StepActivityReport{TaskID: g.review, StepID: g.reviewStep, Attempt: 1, Kind: wire.ActivityRun, Subject: live}) p.wait(drawer+`.querySelector('[equipo-team-tl] > li p > span').textContent===`+jsString(plain)+` && `+rev+`.querySelector('[equipo-spec-doing]').textContent===`+jsString(plain), "the live line in the drawer and the row") p.check(`[...`+drawer+`.querySelectorAll('[equipo-team-raw]')].some(d=>d.open && d.textContent.includes('git diff'))`, "the open disclosure closed on a live update") p.wait(rev+`.querySelector('[equipo-spec-doing]').getAnimations().every(a=>a.playState==='finished')`, "the activity settled") p.stayed("live drawer") newest = plain // Closing: Escape with a keyboard, the close button by touch; focus // returns to the row. if size.touch { p.press(drawer + `.querySelector('[data-team-close]')`) } else { p.do(chromedp.KeyEvent("\x1b")) } p.wait(`!`+drawer+`.open`, "the drawer closed") p.wait(`document.activeElement===`+rev, "focus back on the row") checkSpecialistRows(p, plain) // Engineering idle: its recent work and an Ask box for the task it // finished, which goes to its kept session. p.press(eng) p.wait(drawer+`?.open && `+drawer+`.querySelector('[equipo-team][data-team="engineering"]') && `+drawer+`.getAnimations().length===0`, "Engineering's drawer") p.check(`[...`+drawer+`.querySelectorAll('[equipo-team-recent] a')].map(a=>a.textContent).slice(0,2).join('|')==='Swipe from the edge to go back on the Account pane|Task list loses its scroll position after a refresh'`, "recent work, newest first") form := drawer + `.querySelector('[data-team-ask]')` p.check(`!!`+form+` && `+form+`.getAttribute('action')==='/tasks/`+g.running+`/ask'`, "the Ask box") question := fmt.Sprintf("Why keep the anchor rather than the offset? (%d)", size.w) p.check(`(()=>{const t=`+form+`.querySelector('textarea');t.focus();t.value=`+jsString(question)+`;return true})()`, "type") p.press(form + `.querySelector('button[type=submit]')`) p.wait(`[...`+drawer+`.querySelectorAll('[equipo-team-qs] li')].length>0 || !`+form+`.querySelector('[data-ask-error]').hidden`, "the question posted") p.check(form+`.querySelector('[data-ask-error]').hidden`, "the question did not go through") _, body := a.expect(wire.FrameAsk) ask := body.(*wire.AskCommand) if ask.Specialist != wire.SpecialistEngineering || ask.TaskID != g.running || ask.Text != question { t.Fatalf("ask: %+v", ask) } p.wait(`[...`+drawer+`.querySelectorAll('[equipo-team-qs] li')].some(l=>l.textContent.includes(`+jsString(question)+`)) && `+form+`.querySelector('textarea').value===''`, "the question in the drawer") a.answer(fmt.Sprintf("tp-ans-%d", size.w), wire.AnswerReport{TaskID: g.running, QuestionID: ask.QuestionID, Attempt: ask.Attempt, State: wire.QuestionAnswered, Text: "The offset moves when rows above it change; the **anchor** row does not."}) p.wait(`[...`+drawer+`.querySelectorAll('[equipo-team-qs] li [equipo-markdown]')].some(m=>m.querySelector('strong')?.textContent==='anchor')`, "the answer in the drawer") p.stayed("ask") p.view(fmt.Sprintf("team-panel-engineering-%d", size.w)) p.stop() } // Without script the row is a link to the same panel as a page. p := openInner(t, a.inst.URL, a.inst.Cookie(), 1280, 900, false, "dark", "reduce") defer p.stop() p.open("/team/review") p.check(`!!document.querySelector('main [equipo-team][data-team="review"]') && document.querySelector('[data-team-close]').hidden`, "Review's page") p.shot("team-panel-page-1280-dark") }