//go:build browser package thintest import ( "encoding/json" "fmt" "strings" "testing" "amadan.net/oficina/equipo/internal/wire" ) func TestBrowserActivitySubjects(t *testing.T) { r := newToolRig(t) title := "Project threads with a long title " + strings.Repeat("é", 20) id := taskID(t, r.call("record", wire.ToolRecordTask, map[string]string{"repo": "oficina/sample", "title": title})) words, _ := r.client.Thinking(r.ctx) raw, _ := json.Marshal(words.Sets[0].Phrases["think"]) js := func(v string) string { b, _ := json.Marshal(v); return string(b) } for _, width := range []int64{1280, 390} { t.Run(fmt.Sprint(width), func(t *testing.T) { p := openInner(t, r.inst.URL, r.inst.Cookie(), width, 900, width == 390, "light", "no-preference") defer p.stop() p.open("/conversation") line := `document.querySelector('[equipo-thinking][data-turn="` + r.turn + `"]')` phrase := line + `?.querySelector('[equipo-phrase] [data-in]')?.textContent` p.wait(string(raw)+`.includes(`+phrase+`)`, "set phrase during thinking") r.call("read-"+fmt.Sprint(width), wire.ToolReadTask, map[string]string{"task": id}) short := "Checking ‘" + string([]rune(title)[:39]) + "…’…" full := "Checking ‘" + title + "’…" p.wait(phrase+`===`+js(short), "named activity, with a shortened title") p.check(line+`.querySelector('[equipo-activity]').textContent===`+js(full)+` && `+line+`.querySelector('[equipo-activity-line]').title===`+js(full), "full label for screen readers and tooltip") // The cycling timer must never replace tool activity with a set phrase. elapsed := eval[string](p, line+`.querySelector('[equipo-elapsed]').textContent`) p.check(`(()=>{const now=Date.now;Date.now=()=>now()+60000;return true})()`, "advance phrase clock") p.wait(line+`.querySelector('[equipo-elapsed]').textContent!==`+js(elapsed), "elapsed timer advanced") if width == 1280 { p.check(`!`+line+`.querySelector('[equipo-phrase]').hasAttribute('data-cut')`, "desktop has room for the shortened label") } p.shot(fmt.Sprintf("activity-subject-%d", width)) p.check(phrase+`===`+js(short), "tool label stays visible") if err := r.runner.Send(r.ctx, "think-"+fmt.Sprint(width), wire.FrameActivity, wire.ActivityReport{TurnID: r.turn, Attempt: 1, Kind: wire.ActivityThink}); err != nil { t.Fatal(err) } p.wait(string(raw)+`.includes(`+phrase+`)`, "set phrase returns between tools") p.check(line+`.querySelector('[equipo-activity]').textContent==='Thinking'`, "plain thinking label for screen readers") }) } }