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 "context"
7 "fmt"
8 "os"
9 "path/filepath"
10 "testing"
11
12 "amadan.net/oficina/equipo/internal/wire"
13 "github.com/chromedp/cdproto/input"
14 "github.com/chromedp/chromedp"
15)
16
17// view saves what the window shows (a drawer is fixed to it, so a full
18// page capture would stretch it) when EQUIPO_BROWSER_ARTIFACTS names a
19// directory.
20func (p *innerPage) view(name string) {
21 p.t.Helper()
22 dir := os.Getenv("EQUIPO_BROWSER_ARTIFACTS")
23 if dir == "" {
24 return
25 }
26 var buf []byte
27 p.do(chromedp.Func(func(ctx context.Context, target *chromedp.Target) error {
28 var err error
29 buf, err = chromedp.CaptureScreenshot()(ctx, target)
30 return err
31 }))
32 if err := os.MkdirAll(dir, 0700); err != nil {
33 p.t.Fatal(err)
34 }
35 if err := os.WriteFile(filepath.Join(dir, name+".png"), buf, 0600); err != nil {
36 p.t.Fatal(err)
37 }
38}
39
40// press clicks (or taps) the middle of what expression finds.
41func (p *innerPage) press(expression string) {
42 p.t.Helper()
43 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]})()`)
44 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)))
45}
46
47// TestBrowserTeamPanel: the sidebar's specialists at 1280 with a mouse
48// and at 390 with touch. Review at work is one row of three lines with the
49// living mark; a click on the row opens its drawer over the page (no
50// navigation) with the task, the activity in plain words, each command
51// behind a disclosure, the files touched and what it runs on, and it
52// follows new activity live. Engineering idle is one muted word; its
53// drawer shows its recent work and asks about the task it finished: the
54// question goes to its kept session and the answer arrives in place.
55func TestBrowserTeamPanel(t *testing.T) {
56 g := newTeamGallery(t)
57 a := g.a
58 newest := "Looking over the changes"
59 for _, size := range []struct {
60 w, h int64
61 touch bool
62 }{{1280, 900, false}, {390, 844, true}} {
63 p := openInner(t, a.inst.URL, a.inst.Cookie(), size.w, size.h, size.touch, "light", "no-preference")
64 rail := "/tasks"
65 if size.touch {
66 rail = "/work"
67 }
68 p.open(rail)
69 rev := `document.querySelector('#rail [data-specialist="review"]')`
70 eng := `document.querySelector('#rail [data-specialist="engineering"]')`
71 p.wait(rev+`.querySelector('[data-spec-star] [data-live]')`, "Review's living mark (Stardust)")
72 checkSpecialistRows(p, newest)
73 p.check(rev+`.querySelector('[equipo-spec-doing]').textContent===`+jsString(newest)+` && !`+rev+`.textContent.includes('/bin/') && !`+rev+`.textContent.includes('attempt')`, "Review's row content")
74 p.check(eng+`.dataset.state==='idle' && `+eng+`.querySelector('[equipo-spec-state]').textContent==='idle' && !`+eng+`.querySelector('[equipo-spec-now]')`, "Engineering idle")
75 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")
76 p.view(fmt.Sprintf("team-panel-rail-%d", size.w))
77
78 // The drawer: a click on the row, no navigation.
79 p.press(rev)
80 drawer := `document.querySelector('dialog[equipo-drawer]')`
81 p.wait(drawer+`?.open && `+drawer+`.querySelector('[equipo-team][data-team="review"]')`, "Review's drawer")
82 p.wait(drawer+`.getAnimations().length===0`, "the drawer settled")
83 p.stayed("drawer")
84 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<innerWidth/2)})()`, "the drawer is not at the window's edge")
85 p.check(drawer+`.querySelector('[equipo-team-task]').textContent==='Swipe from the edge to go back on the Account pane' && `+drawer+`.querySelector('[equipo-team-task]').getAttribute('href')==='/tasks/`+g.review+`'`, "the task, linked")
86 tl := drawer + `.querySelectorAll('[equipo-team-tl] > li')`
87 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")
88 p.check(`[...`+tl+`].every(l=>!l.querySelector('p').textContent.includes('/bin/') && !l.querySelector('[equipo-team-raw]').open)`, "raw shell outside a closed disclosure")
89 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")
90 p.check(`[...`+drawer+`.querySelectorAll('[equipo-team-files] li')].map(l=>l.textContent).join('|')==='AccountNavigationHost.swift|NavigationStack.swift'`, "files touched")
91 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")
92 p.check(`document.documentElement.scrollWidth<=innerWidth+1 && `+drawer+`.querySelector('[equipo-team]').scrollWidth<=`+drawer+`.querySelector('[equipo-team]').clientWidth+1`, "the drawer scrolls sideways")
93 p.view(fmt.Sprintf("team-panel-review-%d", size.w))
94 // Live: a new line arrives, plain, at the top; the open disclosure stays open.
95 live, plain := `/bin/bash -lc "xcodebuild test -scheme Woodstar -destination 'platform=iOS Simulator,name=iPhone 16'"`, "Running the tests"
96 if size.touch {
97 live, plain = `/bin/bash -lc "cd ios && swift build"`, "Building the project"
98 }
99 a.activity(fmt.Sprintf("tp-live-%d", size.w), wire.StepActivityReport{TaskID: g.review, StepID: g.reviewStep, Attempt: 1, Kind: wire.ActivityRun, Subject: live})
100 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")
101 p.check(`[...`+drawer+`.querySelectorAll('[equipo-team-raw]')].some(d=>d.open && d.textContent.includes('git diff'))`, "the open disclosure closed on a live update")
102 p.wait(rev+`.querySelector('[equipo-spec-doing]').getAnimations().every(a=>a.playState==='finished')`, "the activity settled")
103 p.stayed("live drawer")
104 newest = plain
105 // Closing: Escape with a keyboard, the close button by touch; focus
106 // returns to the row.
107 if size.touch {
108 p.press(drawer + `.querySelector('[data-team-close]')`)
109 } else {
110 p.do(chromedp.KeyEvent("\x1b"))
111 }
112 p.wait(`!`+drawer+`.open`, "the drawer closed")
113 p.wait(`document.activeElement===`+rev, "focus back on the row")
114 checkSpecialistRows(p, plain)
115
116 // Engineering idle: its recent work and an Ask box for the task it
117 // finished, which goes to its kept session.
118 p.press(eng)
119 p.wait(drawer+`?.open && `+drawer+`.querySelector('[equipo-team][data-team="engineering"]') && `+drawer+`.getAnimations().length===0`, "Engineering's drawer")
120 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")
121 form := drawer + `.querySelector('[data-team-ask]')`
122 p.check(`!!`+form+` && `+form+`.getAttribute('action')==='/tasks/`+g.running+`/ask'`, "the Ask box")
123 question := fmt.Sprintf("Why keep the anchor rather than the offset? (%d)", size.w)
124 p.check(`(()=>{const t=`+form+`.querySelector('textarea');t.focus();t.value=`+jsString(question)+`;return true})()`, "type")
125 p.press(form + `.querySelector('button[type=submit]')`)
126 p.wait(`[...`+drawer+`.querySelectorAll('[equipo-team-qs] li')].length>0 || !`+form+`.querySelector('[data-ask-error]').hidden`, "the question posted")
127 p.check(form+`.querySelector('[data-ask-error]').hidden`, "the question did not go through")
128 _, body := a.expect(wire.FrameAsk)
129 ask := body.(*wire.AskCommand)
130 if ask.Specialist != wire.SpecialistEngineering || ask.TaskID != g.running || ask.Text != question {
131 t.Fatalf("ask: %+v", ask)
132 }
133 p.wait(`[...`+drawer+`.querySelectorAll('[equipo-team-qs] li')].some(l=>l.textContent.includes(`+jsString(question)+`)) && `+form+`.querySelector('textarea').value===''`, "the question in the drawer")
134 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."})
135 p.wait(`[...`+drawer+`.querySelectorAll('[equipo-team-qs] li [equipo-markdown]')].some(m=>m.querySelector('strong')?.textContent==='anchor')`, "the answer in the drawer")
136 p.stayed("ask")
137 p.view(fmt.Sprintf("team-panel-engineering-%d", size.w))
138 p.stop()
139 }
140
141 // Without script the row is a link to the same panel as a page.
142 p := openInner(t, a.inst.URL, a.inst.Cookie(), 1280, 900, false, "dark", "reduce")
143 defer p.stop()
144 p.open("/team/review")
145 p.check(`!!document.querySelector('main [equipo-team][data-team="review"]') && document.querySelector('[data-team-close]').hidden`, "Review's page")
146 p.shot("team-panel-page-1280-dark")
147}
148