//go:build browser package thintest import ( "fmt" "testing" "time" "github.com/chromedp/chromedp" "amadan.net/oficina/equipo/internal/wire" ) // click activates the element selector finds, as a tap or a click does. func (p *innerPage) click(selector string) { p.t.Helper() p.check(`(()=>{const e=document.querySelector(`+jsString(selector)+`);if(!e)return false;e.click();return true})()`, "click "+selector) p.do(chromedp.Sleep(50 * time.Millisecond)) } // TestBrowserHousekeeping: the Housekeeping view and the digest line at // 1280 with a mouse and at 390 with touch. The view lists what Equipo // combined with its evidence and Undo in reach; today's three budgets are // quiet meters; the conversation's header leads to the view and the // digest line links there; Undo from the view restores the task; nothing // scrolls sideways. Screens are saved when EQUIPO_BROWSER_ARTIFACTS names // a directory (hk--.png). func TestBrowserHousekeeping(t *testing.T) { r := newToolRig(t) for i, title := range []string{"Swipe back from the edge doesn't work", "Timeline jumps when images load"} { r.pair(fmt.Sprintf("b%d", i), title) } // The second pair's record_task combines the first; the sweep the // second. r.tidy() if n := len(r.housekeeping().Actions); n != 2 { t.Fatalf("combined %d", n) } // Tomorrow at 08:30 the digest line is written. r.clock(time.Now().UTC().Add(24 * time.Hour).Truncate(24 * time.Hour).Add(8*time.Hour + 30*time.Minute)) r.tick() r.inst.Store.Chat().SetHousekeepingClock(daytime()) for _, size := range []struct { w, h int64 touch bool }{{1280, 900, false}, {390, 844, true}} { p := openInner(t, r.inst.URL, r.inst.Cookie(), size.w, size.h, size.touch, "light", "no-preference") // The conversation: the header's way to the view, the digest line. p.open("/conversation") p.wait(`document.querySelector('[data-digest]')`, "digest line") p.check(`document.querySelector('[data-digest]').textContent.includes('Tidied 2 things.')`, "digest words") p.check(`document.querySelector('[data-digest-link]').getAttribute('href')==='/housekeeping'`, "digest link") if !size.touch { p.check(`(()=>{const a=document.querySelector('[data-housekeeping-link]');const b=a.getBoundingClientRect();return b.width>0&&b.height>0&&b.top>=0})()`, "header link visible") } p.check(`document.querySelectorAll('[equipo-card="combined"]').length===2`, "two quiet receipts") p.fits("conversation") p.shot(fmt.Sprintf("hk-conversation-%d", size.w)) // The view. p.click(`[data-digest-link]`) p.wait(`document.querySelector('[data-housekeeping]')`, "the view") // Settled, as opened directly (the phone slides the page in). p.open("/housekeeping") p.check(`document.querySelectorAll('[data-hk-meter]').length===3`, "three meters") p.check(`document.querySelectorAll('[equipo-hk-action]').length===2`, "two actions") p.check(`[...document.querySelectorAll('[equipo-hk-action] [equipo-hk-line]')].every(e=>e.textContent.includes('Combined'))`, "action lines") p.check(`[...document.querySelectorAll('[equipo-hk-action] [equipo-hk-meta]')].every(e=>/\d+% alike, \d+ words in common/.test(e.textContent))`, "evidence") p.check(`document.querySelectorAll('[data-detector]').length===2 && !document.querySelector('[data-detector][data-off]')`, "detectors on") p.check(`document.querySelector('[data-hk-settings-link]').getAttribute('href')==='/conversation/settings/housekeeping'`, "the way to Settings") if size.touch { p.check(`[...document.querySelectorAll('[data-hk-undo]')].every(b=>{const r=b.getBoundingClientRect();return r.height>=44&&r.width>0})`, "Undo within reach on touch") } else { p.check(`[...document.querySelectorAll('[data-hk-undo]')].every(b=>b.getBoundingClientRect().width>0)`, "Undo visible") } p.fits("housekeeping") p.shot(fmt.Sprintf("hk-view-%d", size.w)) p.stop() } // Live: the view follows the stream. A new combine arrives, Undo // applies and a detector switches, all without a reload. p := openInner(t, r.inst.URL, r.inst.Cookie(), 1280, 900, false, "light", "no-preference") defer p.stop() p.open("/housekeeping") r.pair("b2", "Compose sheet keyboard covers the send button") r.tidy() p.wait(`document.querySelectorAll('[equipo-hk-action]').length===3`, "the new action, live") p.stayed("a new action") id := eval[string](p, `document.querySelector('[equipo-hk-action]').dataset.action`) p.click(`[data-action="` + id + `"] [data-hk-undo]`) p.wait(`document.querySelector('[data-action="`+id+`"][data-undone]')`, "the action undone") p.stayed("Undo") p.check(`!document.querySelector('[data-action="`+id+`"] [data-hk-undo]')`, "no Undo after Undo") p.check(`document.querySelector('[data-action="`+id+`"] [data-hk-state]').textContent==='Undone'`, "state words") a := r.housekeeping() for _, x := range a.Actions { if x.ID == id { if k, _ := r.client.Task(r.ctx, x.Subject.ID); k.Folded != nil { t.Fatal("Undo from the view did not restore the task") } } } p.click(`[data-detector="duplicate_possible"] [data-hk-detector-off]`) p.wait(`document.querySelector('[data-detector="duplicate_possible"][data-off]')`, "detector off") p.stayed("a detector switch") // A change made elsewhere (another device) carries only a housekeeping // event: the view follows it too. h := r.housekeeping() if _, err := r.client.SetDetector(r.ctx, "duplicate_possible", true, h.Revision); err != nil { t.Fatal(err) } p.wait(`document.querySelector('[data-detector="duplicate_possible"]:not([data-off])')`, "switched on elsewhere, live") p.stayed("a change from elsewhere") p.shot("hk-view-undone-1280") // Settings' Housekeeping section, at both sizes: Pause, quiet hours // saved and shown again, and the way to the activity view. for _, size := range []struct { w, h int64 touch bool }{{1280, 900, false}, {390, 844, true}} { q := openInner(t, r.inst.URL, r.inst.Cookie(), size.w, size.h, size.touch, "light", "no-preference") q.open("/conversation/settings/housekeeping") q.check(`!!document.querySelector('[data-hk-settings] [data-hk-pause]') && document.querySelector('[data-hk-activity]').getAttribute('href')==='/housekeeping'`, "the section") q.check(`document.querySelector('[data-hk-quiet-on]').checked && document.querySelector('[data-hk-quiet-from]').value==='22' && document.querySelector('[data-hk-quiet-until]').value==='8'`, "default quiet hours") q.fits("settings") q.shot(fmt.Sprintf("hk-settings-%d", size.w)) q.stop() } q := openInner(t, r.inst.URL, r.inst.Cookie(), 1280, 900, false, "light", "no-preference") defer q.stop() q.open("/conversation/settings/housekeeping") q.check(`(()=>{window.__hkmark=1;for(const [s,v] of [['[data-hk-quiet-from]','23'],['[data-hk-quiet-until]','7']]){const e=document.querySelector(s);e.value=v;e.dispatchEvent(new Event('change',{bubbles:true}))}return true})()`, "choose hours") q.click(`[data-savebar-save]`) // Saved in the background (Paul: a page post replayed the sliding nav). q.wait(`window.__hkmark===1 && document.querySelector('#housekeeping [equipo-saved-tick][data-shown]') && document.querySelector('[data-hk-quiet-from]').value==='23' && document.querySelector('[data-hk-quiet-until]').value==='7'`, "quiet hours saved") if h := r.housekeeping(); h.Quiet != (wire.QuietHours{From: 23, Until: 7}) { t.Fatalf("quiet hours from Settings: %+v", h.Quiet) } q.check(`(()=>{window.__hkmark=1;return true})()`, "mark") q.click(`[data-hk-pause]`) q.wait(`window.__hkmark===1 && document.querySelector('[data-hk-status][data-paused] [data-hk-resume]')`, "paused") q.stayed("Pause from Settings") if h := r.housekeeping(); !h.Paused { t.Fatal("Pause from Settings did not take") } q.shot("hk-settings-paused-1280") // The view says so and leads back to Settings. q.open("/housekeeping") q.check(`!!document.querySelector('[data-housekeeping][data-paused] [data-hk-settings-link]')`, "paused on the view") }