oficina / equipo Public

Clone
git clone https://amadan.net/oficina/equipo

Plain git — no account needed to clone.

Download

Download this file

1//go:build browser
2
3package thintest
4
5import (
6 "fmt"
7 "testing"
8)
9
10// TestBrowserRollup: the conversation opens with yesterday as one day box
11// above today, the merge card still asking at the top of today with its
12// buttons. Show the conversation opens the day in place, under its box,
13// without leaving the page, and keeps the box where the reader is
14// looking; the day stays open while the conversation goes on (the live
15// feed re-renders the page); Hide the conversation closes it. At 1280
16// and 390, light and dark; EQUIPO_BROWSER_ARTIFACTS keeps the shots
17// (rollup-<width>-<scheme>-collapsed.png, -open.png).
18func TestBrowserRollup(t *testing.T) {
19 r := newRollupRig(t)
20 y := r.key(r.yesterday)
21 for i, tc := range []struct {
22 width int64
23 scheme string
24 }{{1280, "light"}, {1280, "dark"}, {390, "light"}, {390, "dark"}} {
25 t.Run(fmt.Sprintf("%d-%s", tc.width, tc.scheme), func(t *testing.T) {
26 p := openInner(t, r.inst.URL, r.inst.Cookie(), tc.width, 844, tc.width == 390, tc.scheme, "no-preference")
27 defer p.stop()
28 // The rig's person is in Madrid; so is their browser, or zone.js
29 // would move their day (paused work).
30 p.timezone("Europe/Madrid")
31 p.open("/conversation")
32 p.wait(`document.querySelector('[data-chat-stream]') && document.querySelector('[equipo-offline]').hidden`, "the conversation")
33 box := `document.querySelector('[equipo-rollup][data-day="` + y + `"]')`
34 p.check(`document.querySelectorAll('[equipo-rollup]').length===1 && !!`+box+` && !document.querySelector('[equipo-day-feed]')`, "not one collapsed day box")
35 p.check(`!document.querySelector('[data-message="`+r.lastWord+`"]') && !!document.querySelector('[data-message="`+r.firstDay+`"]')`, "the boundary moved: yesterday shown or today rolled up")
36 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")
37 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")
38 p.fits("the day box")
39 // The shot starts at the top of the scrollback, where the box is.
40 p.check(`(()=>{const s=document.querySelector('[equipo-scroll]');s.scrollTop=0;s.dispatchEvent(new Event('scroll'));return true})()`, "scroll up")
41 p.wait(`document.querySelector('[equipo-scroll]').scrollTop===0`, "the top of the scrollback")
42 p.shot(fmt.Sprintf("rollup-%d-%s-collapsed", tc.width, tc.scheme))
43
44 // Open the day: in place, no navigation, the box in view.
45 p.click(`[data-day-toggle="` + y + `"]`)
46 p.wait(`document.querySelector('[equipo-day-feed] [data-message="`+r.lastWord+`"]')`, "yesterday's transcript")
47 p.stayed("Show the conversation")
48 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")
49 p.check(`(()=>{const b=`+box+`.getBoundingClientRect(), s=document.querySelector('[equipo-scroll]').getBoundingClientRect();return b.top>=s.top-1 && b.top<s.bottom})()`, "the opened day is not in view")
50 p.fits("the open day")
51 p.shot(fmt.Sprintf("rollup-%d-%s-open", tc.width, tc.scheme))
52
53 // The conversation goes on: the feed re-renders, the day stays open.
54 replies := `[...document.querySelectorAll('[equipo-message="incoming"]')].filter(e=>!e.closest('[equipo-rollup]')&&e.textContent.includes('Ok.')).length`
55 before := eval[int](p, replies)
56 text := fmt.Sprintf("Anything else from yesterday? (%d)", i)
57 r.next(text)
58 p.wait(`[...document.querySelectorAll('[equipo-message="own"]')].some(e=>e.textContent.includes(`+jsString(text)+`))`, "today's new message")
59 p.wait(replies+`>`+fmt.Sprint(before), "the reply, rendered by the server")
60 p.check(`!!document.querySelector('[equipo-rollup][data-day="`+y+`"][data-expanded] [data-message="`+r.lastWord+`"]')`, "the live feed closed the day")
61
62 // Close it again.
63 p.click(`[data-day-toggle="` + y + `"]`)
64 p.wait(`!document.querySelector('[equipo-day-feed]') && document.querySelector('[data-day-toggle="`+y+`"]').getAttribute('aria-expanded')==='false'`, "the day closed")
65 p.stayed("Hide the conversation")
66 })
67 }
68}
69