//go:build browser package headless import ( "github.com/chromedp/chromedp" "testing" "amadan.net/oficina/equipo/internal/browsertest" ) // taskCard finds the task card whose title link reads title. func taskCard(title string) string { return `[...document.querySelectorAll('[equipo-card="task"]')].find(e=>e.querySelector('[equipo-card-line] a')?.textContent===` + jsonString(title) + `)` } // Slice 3: the person reports a bug; a quiet task receipt appears before // the reply and follows the task live to the pushed branch, its short // SHA and Open on Amadan. Open the task reaches Cancel on a phone, // and Cancel ends a slow second task. func TestBrowserTaskCard(t *testing.T) { _, inst, r := localEnv(t) r.start(t) c := inst.Cookie() p := openPage(t, inst.URL, c.Name, c.Value, 390, 844, false) defer p.stop() p.send("Fix the README typo in sample.\ntool:record_task:oficina/sample|Fix the README typo|The README says teh panes.\ntool:read_file:oficina/sample|README.md\ntool:add_finding:$task|The README has teh for the.|oficina/sample|README.md|5\ntool:start_task:$task|Fix the typo. edit:README.md|teh panes|the panes") first := taskCard("Fix the README typo") p.run(browsertest.Wait(`!!` + first)) // The receipt sits before its turn's reply, as a quiet line. p.run(browsertest.Wait(`(()=>{const r=` + first + `;const m=[...document.querySelectorAll('[equipo-message="incoming"][data-turn-id="'+r.dataset.turnId+'"]')][0];return !!m && !!(r.compareDocumentPosition(m)&4) && r.hasAttribute('equipo-receipt')})()`)) // Live: the stage moves on and the pushed branch appears without a reload. p.check(`(()=>{window.__nav=performance.getEntriesByType('navigation').length;return true})()`, "mark") p.run(browsertest.Wait(`(()=>{const a=` + first + `?.querySelector('[data-open-amadan]');return !!a && a.href.startsWith('https://amadan.net/oficina/sample?branch=equipo/') && a.target==='_blank' && a.rel==='noopener' && /^[0-9a-f]{7}$/.test(` + first + `.querySelector('[equipo-roster-facts] code').parentElement.nextElementSibling.textContent)})()`)) p.check(`performance.getEntriesByType('navigation').length===window.__nav`, "the page reloaded") p.check(`!`+first+`.querySelector('[data-task-retry]')`, "a pushed task offers Retry") p.send("tool:record_task:oficina/sample|Slow change|x\ntool:start_task:$task|stepsleep:20000 edit:README.md|teh|the") slow := taskCard("Slow change") p.run(browsertest.Wait(`!!` + slow + `?.querySelector('[equipo-roster-links] a[href^="/tasks/"]')`)) p.check(`!`+slow+`.querySelector('[equipo-receipt-more], [data-task-cancel]')`, "report retained its action menu") p.check(`(()=>{`+slow+`.querySelector('[equipo-roster-links] a[href^="/tasks/"]').click();return true})()`, "Open the task") p.run(browsertest.Wait(`!!document.querySelector('#task-head [data-task-cancel]')`)) p.check(`(()=>{document.querySelector('#task-head [equipo-menu] summary').click();return true})()`, "task actions") p.check(`(()=>{document.querySelector('#task-head [data-task-cancel]').click();return true})()`, "Cancel") p.run(browsertest.Wait(`!document.querySelector('#task-head [data-task-cancel]')`)) p.run(chromedp.Navigate(inst.URL+"/conversation"), browsertest.Wait(slow+`?.dataset.state==='cancelled'`)) }