| 1 | //go:build browser |
| 2 | |
| 3 | package headless |
| 4 | |
| 5 | import ( |
| 6 | "github.com/chromedp/chromedp" |
| 7 | "testing" |
| 8 | |
| 9 | "amadan.net/oficina/equipo/internal/browsertest" |
| 10 | ) |
| 11 | |
| 12 | // taskCard finds the task card whose title link reads title. |
| 13 | func taskCard(title string) string { |
| 14 | return `[...document.querySelectorAll('[equipo-card="task"]')].find(e=>e.querySelector('[equipo-card-line] a')?.textContent===` + jsonString(title) + `)` |
| 15 | } |
| 16 | |
| 17 | // Slice 3: the person reports a bug; a quiet task receipt appears before |
| 18 | // the reply and follows the task live to the pushed branch, its short |
| 19 | // SHA and Open on Amadan. Open the task reaches Cancel on a phone, |
| 20 | // and Cancel ends a slow second task. |
| 21 | func TestBrowserTaskCard(t *testing.T) { |
| 22 | _, inst, r := localEnv(t) |
| 23 | r.start(t) |
| 24 | c := inst.Cookie() |
| 25 | p := openPage(t, inst.URL, c.Name, c.Value, 390, 844, false) |
| 26 | defer p.stop() |
| 27 | 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") |
| 28 | first := taskCard("Fix the README typo") |
| 29 | p.run(browsertest.Wait(`!!` + first)) |
| 30 | // The receipt sits before its turn's reply, as a quiet line. |
| 31 | 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')})()`)) |
| 32 | // Live: the stage moves on and the pushed branch appears without a reload. |
| 33 | p.check(`(()=>{window.__nav=performance.getEntriesByType('navigation').length;return true})()`, "mark") |
| 34 | 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)})()`)) |
| 35 | p.check(`performance.getEntriesByType('navigation').length===window.__nav`, "the page reloaded") |
| 36 | p.check(`!`+first+`.querySelector('[data-task-retry]')`, "a pushed task offers Retry") |
| 37 | p.send("tool:record_task:oficina/sample|Slow change|x\ntool:start_task:$task|stepsleep:20000 edit:README.md|teh|the") |
| 38 | slow := taskCard("Slow change") |
| 39 | |
| 40 | p.run(browsertest.Wait(`!!` + slow + `?.querySelector('[equipo-roster-links] a[href^="/tasks/"]')`)) |
| 41 | p.check(`!`+slow+`.querySelector('[equipo-receipt-more], [data-task-cancel]')`, "report retained its action menu") |
| 42 | p.check(`(()=>{`+slow+`.querySelector('[equipo-roster-links] a[href^="/tasks/"]').click();return true})()`, "Open the task") |
| 43 | p.run(browsertest.Wait(`!!document.querySelector('#task-head [data-task-cancel]')`)) |
| 44 | p.check(`(()=>{document.querySelector('#task-head [equipo-menu] summary').click();return true})()`, "task actions") |
| 45 | p.check(`(()=>{document.querySelector('#task-head [data-task-cancel]').click();return true})()`, "Cancel") |
| 46 | p.run(browsertest.Wait(`!document.querySelector('#task-head [data-task-cancel]')`)) |
| 47 | p.run(chromedp.Navigate(inst.URL+"/conversation"), browsertest.Wait(slow+`?.dataset.state==='cancelled'`)) |
| 48 | } |
| 49 | |