| 1 | //go:build browser |
| 2 | |
| 3 | package thintest |
| 4 | |
| 5 | import ( |
| 6 | "fmt" |
| 7 | "testing" |
| 8 | "time" |
| 9 | |
| 10 | "github.com/chromedp/chromedp" |
| 11 | ) |
| 12 | |
| 13 | // TestBrowserEmptyConversation: Paul, 2026-11-20, on the empty |
| 14 | // conversation's one stern line: "it probably doesn't need to be |
| 15 | // conversational. It can be maybe an illustration or something that |
| 16 | // just entices you to type a first message." An empty conversation |
| 17 | // shows a quiet drawing, a short line and three starters. A starter is a |
| 18 | // real, named button reached by keyboard; tapping one (or Enter on it) |
| 19 | // fills the composer with its opening words and puts the cursor after |
| 20 | // them; it never sends. The starters fit a phone and leave with the |
| 21 | // first message. EQUIPO_BROWSER_ARTIFACTS, when set, gets |
| 22 | // empty-<width>-<scheme>.png for 1280 dark and light and 390 dark and |
| 23 | // light. |
| 24 | func TestBrowserEmptyConversation(t *testing.T) { |
| 25 | r, _ := instantRig(t) |
| 26 | for _, tc := range []struct { |
| 27 | width, height int64 |
| 28 | touch bool |
| 29 | scheme string |
| 30 | }{{1280, 860, false, "dark"}, {1280, 860, false, "light"}, {390, 844, true, "dark"}, {390, 844, true, "light"}} { |
| 31 | t.Run(fmt.Sprintf("%d-%s", tc.width, tc.scheme), func(t *testing.T) { |
| 32 | p := openInner(t, r.inst.URL, r.inst.Cookie(), tc.width, tc.height, tc.touch, tc.scheme, "reduce") |
| 33 | defer p.stop() |
| 34 | p.open("/conversation") |
| 35 | p.wait(`document.querySelector('[data-chat-stream]') && document.querySelector('[equipo-offline]').hidden`, "the conversation, online") |
| 36 | p.check(`(()=>{document.documentElement.dataset.theme=`+jsString(tc.scheme)+`;return true})()`, "theme") |
| 37 | // Every POST the page makes is counted: a starter sends nothing. |
| 38 | 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") |
| 39 | p.wait(`document.querySelector('[data-empty-state="conversation.empty"] svg[aria-hidden="true"]')`, "the drawing, hidden from screen readers") |
| 40 | 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") |
| 41 | p.check(`(()=>{const g=document.querySelector('[equipo-starters]');return !!g && g.getAttribute('aria-label')==='Ways to start'})()`, "the starters are a named group") |
| 42 | 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") |
| 43 | 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") |
| 44 | min := 32.0 |
| 45 | if tc.touch { |
| 46 | min = 44 |
| 47 | } |
| 48 | 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") |
| 49 | // The empty state sits in the scroll area, above the composer, |
| 50 | // and nothing in it overlaps the composer. |
| 51 | 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") |
| 52 | p.fits("the empty conversation") |
| 53 | p.shot(fmt.Sprintf("empty-%d-%s", tc.width, tc.scheme)) |
| 54 | |
| 55 | // Keyboard: from the conversation's scroll region, Tab reaches |
| 56 | // the first starter, and Enter on it fills the composer. |
| 57 | p.check(`(()=>{document.querySelector('[equipo-scroll]').focus();return document.activeElement===document.querySelector('[equipo-scroll]')})()`, "focus the region") |
| 58 | p.do(chromedp.KeyEvent("\t")) |
| 59 | p.wait(`document.activeElement===document.querySelector('[equipo-starters] button')`, "Tab to the first starter") |
| 60 | p.check(`getComputedStyle(document.activeElement).outlineStyle!=='none'`, "the focused starter shows a ring") |
| 61 | p.do(chromedp.KeyEvent("\r")) |
| 62 | p.wait(`document.activeElement===document.querySelector('#chat-body') && document.querySelector('#chat-body').value==='Fix a bug where '`, "Enter fills the composer") |
| 63 | 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") |
| 64 | p.check(`document.querySelector('#composer').hasAttribute('data-has-content')`, "the send arrow shows") |
| 65 | // A form submission navigates a moment after the click: wait it out. |
| 66 | time.Sleep(400 * time.Millisecond) |
| 67 | p.stayed("a starter") |
| 68 | // Space on a starter does the same. |
| 69 | 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") |
| 70 | p.do(chromedp.KeyEvent(" ")) |
| 71 | p.wait(`document.activeElement===document.querySelector('#chat-body') && document.querySelector('#chat-body').value==='Plan a feature that '`, "Space fills the composer") |
| 72 | |
| 73 | // A tap on another starter replaces the words it put there. |
| 74 | pick := func(i int) { |
| 75 | t.Helper() |
| 76 | 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)) |
| 77 | if tc.touch { |
| 78 | p.do(chromedp.TapXY(xy[0], xy[1])) |
| 79 | } else { |
| 80 | p.do(chromedp.MouseClickXY(xy[0], xy[1])) |
| 81 | } |
| 82 | } |
| 83 | pick(2) |
| 84 | p.wait(`document.activeElement===document.querySelector('#chat-body') && document.querySelector('#chat-body').value==='What’s the latest on '`, "a tap fills the composer") |
| 85 | pick(1) |
| 86 | p.wait(`document.querySelector('#chat-body').value==='Plan a feature that '`, "another starter replaces it") |
| 87 | // Words the person typed are theirs: a starter does not wipe them. |
| 88 | p.check(`(()=>{const b=document.querySelector('#chat-body');b.value='Mine';b.dispatchEvent(new Event('input'));return true})()`, "type") |
| 89 | pick(0) |
| 90 | p.wait(`document.activeElement===document.querySelector('#chat-body')`, "focus after a tap") |
| 91 | p.check(`document.querySelector('#chat-body').value==='Mine'`, "typed words kept") |
| 92 | p.check(`window.__posts===0 && !document.querySelector('[equipo-message="own"][data-message]:not(template *)')`, "a starter sent something") |
| 93 | time.Sleep(400 * time.Millisecond) |
| 94 | p.stayed("starters") |
| 95 | p.check(`!!document.querySelector('[data-empty-state]')`, "the empty state stays until a message goes") |
| 96 | }) |
| 97 | } |
| 98 | // The first message takes the empty state and its starters away. |
| 99 | p := openInner(t, r.inst.URL, r.inst.Cookie(), 1280, 860, false, "light", "reduce") |
| 100 | defer p.stop() |
| 101 | p.open("/conversation") |
| 102 | p.wait(`document.querySelector('[equipo-starters] button')`, "starters") |
| 103 | p.check(`(()=>{document.querySelectorAll('[equipo-starters] button')[0].click();return true})()`, "pick") |
| 104 | p.wait(`document.querySelector('#chat-body').value==='Fix a bug where '`, "filled") |
| 105 | p.check(`(()=>{const b=document.querySelector('#chat-body');b.focus();b.setSelectionRange(b.value.length,b.value.length);return true})()`, "cursor at the end") |
| 106 | p.do(chromedp.KeyEvent("the menu sticks"), chromedp.KeyEvent("\r")) |
| 107 | p.wait(`!document.querySelector('[data-empty-state]') && !document.querySelector('[equipo-starters]')`, "the empty state gone after the first message") |
| 108 | } |
| 109 | |