//go:build browser package thintest import ( "fmt" "testing" ) // TestBrowserRollup: the conversation opens with yesterday as one day box // above today, the merge card still asking at the top of today with its // buttons. Show the conversation opens the day in place, under its box, // without leaving the page, and keeps the box where the reader is // looking; the day stays open while the conversation goes on (the live // feed re-renders the page); Hide the conversation closes it. At 1280 // and 390, light and dark; EQUIPO_BROWSER_ARTIFACTS keeps the shots // (rollup---collapsed.png, -open.png). func TestBrowserRollup(t *testing.T) { r := newRollupRig(t) y := r.key(r.yesterday) for i, tc := range []struct { width int64 scheme string }{{1280, "light"}, {1280, "dark"}, {390, "light"}, {390, "dark"}} { 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, 844, tc.width == 390, tc.scheme, "no-preference") defer p.stop() // The rig's person is in Madrid; so is their browser, or zone.js // would move their day (paused work). p.timezone("Europe/Madrid") p.open("/conversation") p.wait(`document.querySelector('[data-chat-stream]') && document.querySelector('[equipo-offline]').hidden`, "the conversation") box := `document.querySelector('[equipo-rollup][data-day="` + y + `"]')` p.check(`document.querySelectorAll('[equipo-rollup]').length===1 && !!`+box+` && !document.querySelector('[equipo-day-feed]')`, "not one collapsed day box") p.check(`!document.querySelector('[data-message="`+r.lastWord+`"]') && !!document.querySelector('[data-message="`+r.firstDay+`"]')`, "the boundary moved: yesterday shown or today rolled up") p.check(`(()=>{const c=document.querySelector('[data-card="`+r.askCard.ID+`"]');const d=document.querySelector('[data-today]');return !!c && !!c.querySelector('[data-merge-choice="merge"]') && !!(d.compareDocumentPosition(c)&4) && !`+box+`.contains(c)})()`, "the open merge card is not at the top of today with its buttons") p.check(`(()=>{const b=`+box+`.querySelector('[equipo-day-box]');const s=getComputedStyle(b);return s.borderLeftWidth===s.borderTopWidth && s.borderLeftColor===s.borderTopColor})()`, "a coloured left border on the day box") p.fits("the day box") // The shot starts at the top of the scrollback, where the box is. p.check(`(()=>{const s=document.querySelector('[equipo-scroll]');s.scrollTop=0;s.dispatchEvent(new Event('scroll'));return true})()`, "scroll up") p.wait(`document.querySelector('[equipo-scroll]').scrollTop===0`, "the top of the scrollback") p.shot(fmt.Sprintf("rollup-%d-%s-collapsed", tc.width, tc.scheme)) // Open the day: in place, no navigation, the box in view. p.click(`[data-day-toggle="` + y + `"]`) p.wait(`document.querySelector('[equipo-day-feed] [data-message="`+r.lastWord+`"]')`, "yesterday's transcript") p.stayed("Show the conversation") p.check(`(()=>{const t=document.querySelector('[data-day-toggle="`+y+`"]');return t.getAttribute('aria-expanded')==='true' && document.activeElement===t && t.textContent.trim()==='Hide the conversation'})()`, "the toggle lost its state or focus") p.check(`(()=>{const b=`+box+`.getBoundingClientRect(), s=document.querySelector('[equipo-scroll]').getBoundingClientRect();return b.top>=s.top-1 && b.top!e.closest('[equipo-rollup]')&&e.textContent.includes('Ok.')).length` before := eval[int](p, replies) text := fmt.Sprintf("Anything else from yesterday? (%d)", i) r.next(text) p.wait(`[...document.querySelectorAll('[equipo-message="own"]')].some(e=>e.textContent.includes(`+jsString(text)+`))`, "today's new message") p.wait(replies+`>`+fmt.Sprint(before), "the reply, rendered by the server") p.check(`!!document.querySelector('[equipo-rollup][data-day="`+y+`"][data-expanded] [data-message="`+r.lastWord+`"]')`, "the live feed closed the day") // Close it again. p.click(`[data-day-toggle="` + y + `"]`) p.wait(`!document.querySelector('[equipo-day-feed]') && document.querySelector('[data-day-toggle="`+y+`"]').getAttribute('aria-expanded')==='false'`, "the day closed") p.stayed("Hide the conversation") }) } }