//go:build browser package thintest import ( "fmt" "testing" "time" "github.com/chromedp/chromedp" ) // TestBrowserEmptyConversation: Paul, 2026-11-20, on the empty // conversation's one stern line: "it probably doesn't need to be // conversational. It can be maybe an illustration or something that // just entices you to type a first message." An empty conversation // shows a quiet drawing, a short line and three starters. A starter is a // real, named button reached by keyboard; tapping one (or Enter on it) // fills the composer with its opening words and puts the cursor after // them; it never sends. The starters fit a phone and leave with the // first message. EQUIPO_BROWSER_ARTIFACTS, when set, gets // empty--.png for 1280 dark and light and 390 dark and // light. func TestBrowserEmptyConversation(t *testing.T) { r, _ := instantRig(t) for _, tc := range []struct { width, height int64 touch bool scheme string }{{1280, 860, false, "dark"}, {1280, 860, false, "light"}, {390, 844, true, "dark"}, {390, 844, true, "light"}} { t.Run(fmt.Sprintf("%d-%s", tc.width, tc.scheme), func(t *testing.T) { p := openInner(t, r.inst.URL, r.inst.Cookie(), tc.width, tc.height, tc.touch, tc.scheme, "reduce") defer p.stop() p.open("/conversation") p.wait(`document.querySelector('[data-chat-stream]') && document.querySelector('[equipo-offline]').hidden`, "the conversation, online") p.check(`(()=>{document.documentElement.dataset.theme=`+jsString(tc.scheme)+`;return true})()`, "theme") // Every POST the page makes is counted: a starter sends nothing. p.check(`(()=>{const f=window.fetch.bind(window);window.__posts=0;window.fetch=(u,o)=>{if(o&&o.method==='POST')window.__posts++;return f(u,o)};return true})()`, "count posts") p.wait(`document.querySelector('[data-empty-state="conversation.empty"] svg[aria-hidden="true"]')`, "the drawing, hidden from screen readers") p.check(`(()=>{const h=document.querySelector('[data-empty-state="conversation.empty"] h2');return !!h && h.textContent.trim()==='What needs doing?'})()`, "the short line is a heading") p.check(`(()=>{const g=document.querySelector('[equipo-starters]');return !!g && g.getAttribute('aria-label')==='Ways to start'})()`, "the starters are a named group") p.check(`(()=>{const b=[...document.querySelectorAll('[equipo-starters] button')];return b.length===3 && b.every(x=>x.type==='submit' && x.name==='start' && x.value && x.textContent.trim() && !x.disabled && x.tabIndex===0)})()`, "three real, named buttons") p.check(`[...document.querySelectorAll('[equipo-starters] button')].map(b=>b.textContent.trim()).join('|')==='Fix a bug|Plan a feature|Ask about a project'`, "starter labels") min := 32.0 if tc.touch { min = 44 } p.check(fmt.Sprintf(`[...document.querySelectorAll('[equipo-starters] button')].every(b=>{const r=b.getBoundingClientRect();return r.height>=%v-0.5 && r.right<=innerWidth && r.left>=0})`, min), "starters meet the target floor and fit") // The empty state sits in the scroll area, above the composer, // and nothing in it overlaps the composer. p.check(`(()=>{const e=document.querySelector('[data-empty-state]').getBoundingClientRect(),c=document.querySelector('#chat-composer').getBoundingClientRect();return e.bottom<=c.top+1 && e.top>=0})()`, "the empty state clears the composer") p.fits("the empty conversation") p.shot(fmt.Sprintf("empty-%d-%s", tc.width, tc.scheme)) // Keyboard: from the conversation's scroll region, Tab reaches // the first starter, and Enter on it fills the composer. p.check(`(()=>{document.querySelector('[equipo-scroll]').focus();return document.activeElement===document.querySelector('[equipo-scroll]')})()`, "focus the region") p.do(chromedp.KeyEvent("\t")) p.wait(`document.activeElement===document.querySelector('[equipo-starters] button')`, "Tab to the first starter") p.check(`getComputedStyle(document.activeElement).outlineStyle!=='none'`, "the focused starter shows a ring") p.do(chromedp.KeyEvent("\r")) p.wait(`document.activeElement===document.querySelector('#chat-body') && document.querySelector('#chat-body').value==='Fix a bug where '`, "Enter fills the composer") p.check(`(()=>{const b=document.querySelector('#chat-body');return b.selectionStart===b.value.length && b.selectionEnd===b.value.length})()`, "the cursor is after the words") p.check(`document.querySelector('#composer').hasAttribute('data-has-content')`, "the send arrow shows") // A form submission navigates a moment after the click: wait it out. time.Sleep(400 * time.Millisecond) p.stayed("a starter") // Space on a starter does the same. p.check(`(()=>{const b=document.querySelector('#chat-body');b.value='';b.dispatchEvent(new Event('input'));document.querySelectorAll('[equipo-starters] button')[1].focus();return true})()`, "clear and focus the second starter") p.do(chromedp.KeyEvent(" ")) p.wait(`document.activeElement===document.querySelector('#chat-body') && document.querySelector('#chat-body').value==='Plan a feature that '`, "Space fills the composer") // A tap on another starter replaces the words it put there. pick := func(i int) { t.Helper() xy := eval[[]float64](p, fmt.Sprintf(`(()=>{const r=document.querySelectorAll('[equipo-starters] button')[%d].getBoundingClientRect();return [r.x+r.width/2,r.y+r.height/2]})()`, i)) if tc.touch { p.do(chromedp.TapXY(xy[0], xy[1])) } else { p.do(chromedp.MouseClickXY(xy[0], xy[1])) } } pick(2) p.wait(`document.activeElement===document.querySelector('#chat-body') && document.querySelector('#chat-body').value==='What’s the latest on '`, "a tap fills the composer") pick(1) p.wait(`document.querySelector('#chat-body').value==='Plan a feature that '`, "another starter replaces it") // Words the person typed are theirs: a starter does not wipe them. p.check(`(()=>{const b=document.querySelector('#chat-body');b.value='Mine';b.dispatchEvent(new Event('input'));return true})()`, "type") pick(0) p.wait(`document.activeElement===document.querySelector('#chat-body')`, "focus after a tap") p.check(`document.querySelector('#chat-body').value==='Mine'`, "typed words kept") p.check(`window.__posts===0 && !document.querySelector('[equipo-message="own"][data-message]:not(template *)')`, "a starter sent something") time.Sleep(400 * time.Millisecond) p.stayed("starters") p.check(`!!document.querySelector('[data-empty-state]')`, "the empty state stays until a message goes") }) } // The first message takes the empty state and its starters away. p := openInner(t, r.inst.URL, r.inst.Cookie(), 1280, 860, false, "light", "reduce") defer p.stop() p.open("/conversation") p.wait(`document.querySelector('[equipo-starters] button')`, "starters") p.check(`(()=>{document.querySelectorAll('[equipo-starters] button')[0].click();return true})()`, "pick") p.wait(`document.querySelector('#chat-body').value==='Fix a bug where '`, "filled") p.check(`(()=>{const b=document.querySelector('#chat-body');b.focus();b.setSelectionRange(b.value.length,b.value.length);return true})()`, "cursor at the end") p.do(chromedp.KeyEvent("the menu sticks"), chromedp.KeyEvent("\r")) p.wait(`!document.querySelector('[data-empty-state]') && !document.querySelector('[equipo-starters]')`, "the empty state gone after the first message") }