oficina / slides Public

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

Plain git — no account needed to clone.

Download

Download this file

1//go:build browser
2
3// Seeing a slide's steps, and marking what is in the talk (steps and
4// presenter spec §4, In the editor; fixtures/play-through.mjs,
5// strip.mjs, commands.mjs): the "N presses" control in the slide's
6// bottom end corner that plays the slide through on the stage, Esc (or a
7// change of slide, or an edit) back to the finished slide; the strip's
8// count, the dashed edge on a full-only slide and the slim bar of a
9// parked one, final at the first paint; Skip in the short version and
10// Park, exclusive toggles in the strip's menu and the Slide menu; and
11// Deck settings' How things arrive. Every write is read back over the
12// API.
13package slidestest
14
15import (
16 "context"
17 "encoding/json"
18 "fmt"
19 "net/http"
20 "regexp"
21 "strings"
22 "testing"
23
24 "amadan.net/rastrillo/rastrillo/harness"
25 "github.com/chromedp/cdproto/accessibility"
26 "github.com/chromedp/cdproto/cdp"
27 "github.com/chromedp/cdproto/page"
28 "github.com/chromedp/chromedp"
29 "github.com/chromedp/chromedp/kb"
30)
31
32// talkEditorDeck: a slide whose three texts arrive on presses 1, 2 and
33// 3 under a heading that arrives with it; a slide without steps; a
34// full-only slide; a parked one; and a last plain one.
35const talkEditorDeck = `[
36 {"op":"add_slide","id":"pressslide1","layout":"flow","template":"title-body"},
37 {"op":"add_block","slide":"pressslide1","id":"presshead001","type":"heading","region":"heading","props":{"level":1},"markdown":"Three presses"},
38 {"op":"add_block","slide":"pressslide1","id":"presstext001","type":"text","region":"body","markdown":"First"},
39 {"op":"add_block","slide":"pressslide1","id":"presstext002","type":"text","region":"body","markdown":"Second"},
40 {"op":"add_block","slide":"pressslide1","id":"presstext003","type":"text","region":"body","markdown":"Third"},
41 {"op":"set_block","slide":"pressslide1","id":"presstext001","step":1},
42 {"op":"set_block","slide":"pressslide1","id":"presstext002","step":2},
43 {"op":"set_block","slide":"pressslide1","id":"presstext003","step":3},
44 {"op":"add_slide","id":"plainslide2","layout":"flow","template":"title-body"},
45 {"op":"add_block","slide":"plainslide2","id":"plainhead002","type":"heading","region":"heading","props":{"level":1},"markdown":"No presses"},
46 {"op":"add_block","slide":"plainslide2","id":"plaintext002","type":"text","region":"body","markdown":"Words"},
47 {"op":"add_slide","id":"fullslide01","layout":"flow","template":"title-body"},
48 {"op":"add_block","slide":"fullslide01","id":"fullhead0001","type":"heading","region":"heading","props":{"level":1},"markdown":"Only in full"},
49 {"op":"set_slide","id":"fullslide01","talk":"full"},
50 {"op":"add_slide","id":"parkslide01","layout":"flow","template":"title-body"},
51 {"op":"add_block","slide":"parkslide01","id":"parkhead0001","type":"heading","region":"heading","props":{"level":1},"markdown":"Parked one"},
52 {"op":"set_slide","id":"parkslide01","talk":"parked"},
53 {"op":"add_slide","id":"lastslide01","layout":"flow","template":"title-body"},
54 {"op":"add_block","slide":"lastslide01","id":"lasthead0001","type":"heading","region":"heading","props":{"level":1},"markdown":"The end"}]`
55
56// openTalkEditor opens the editor on talkEditorDeck's first slide, and
57// an agent's token to read the deck back and to edit it as a colleague.
58func openTalkEditor(t *testing.T) (*tidyEditor, string) {
59 t.Helper()
60 te := openTidyEditorOn(t, 1280, 800, func(a *testApp, cookies []*http.Cookie) string { return quieterDeck(t, a, cookies, talkEditorDeck) })
61 token := mintAgent(t, te.app, te.cookies, "talk-editor")
62 te.goToSlide("pressslide1")
63 return te, token
64}
65
66// pressesSel is the stage's presses control.
67const pressesSel = `[slides-stage-pane] [slides-presses]`
68
69// pressesState: the control's words, whether it is drawn, and the
70// boxes on the stage waiting for a press, in the slide's order.
71type pressesState struct {
72 Text string
73 Shown bool
74 Waiting []string
75}
76
77const pressesStateJS = `(() => {
78 const b = document.querySelector('` + pressesSel + `')
79 const waiting = [...document.querySelectorAll('[slides-stage] [data-waiting]')].map(e => e.closest('[slides-block]')?.dataset.id || '?')
80 return { Text: b ? b.textContent.trim() : '', Shown: !!b && b.checkVisibility(), Waiting: waiting }
81})()`
82
83func (te *tidyEditor) presses() pressesState {
84 var s pressesState
85 te.rig.Run(evalInto(&s, pressesStateJS))
86 return s
87}
88
89// untilPresses waits until the control says text, with the boxes given
90// waiting (and only those), and none of them drawn.
91func (te *tidyEditor) untilPresses(t *testing.T, text string, waiting ...string) {
92 t.Helper()
93 want := strings.Join(waiting, " ")
94 te.rig.Run(waitFor(`(() => {
95 const s = ` + pressesStateJS + `
96 const hidden = [...document.querySelectorAll('[slides-stage] [data-waiting]')].every(e => !e.checkVisibility({ visibilityProperty: true }))
97 return s.Text === ` + quote(text) + ` && s.Waiting.join(' ') === ` + quote(want) + ` && hidden
98 })()`))
99}
100
101// TestPlayThroughWalksThePresses: on a slide with three presses the
102// control says so, a real button at the slide's bottom end corner,
103// outside the slide and never over it; a click plays press 1, → and Space while it has
104// focus play the next ones, each hiding what has not yet arrived; a
105// click after the last is the finished slide again. Nothing is written.
106func TestPlayThroughWalksThePresses(t *testing.T) {
107 te, token := openTalkEditor(t)
108 te.rig.Run(waitFor(`document.querySelector('` + pressesSel + `')?.checkVisibility()`))
109 if s := te.presses(); s.Text != "3 presses" || len(s.Waiting) != 0 {
110 t.Errorf("at rest the control is %+v, want 3 presses and nothing waiting", s)
111 }
112 te.atCorner(t, "at rest")
113 te.rig.Screen(`[slides-stage-pane]`, "a slide with three presses, at rest")
114
115 te.rig.Run(waitFor(`document.querySelector('`+pressesSel+`')`), chromedp.Click(chromedp.CSS(pressesSel)))
116 te.untilPresses(t, "Press 1 of 3. Esc shows the finished slide.", "presstext002", "presstext003")
117 te.atCorner(t, "playing press 1")
118 te.rig.Screen(`[slides-stage-pane]`, "playing: press 1 of 3")
119 te.rig.Run(waitFor(`document.activeElement === document.querySelector('`+pressesSel+`')`), chromedp.KeyEvent(kb.ArrowRight))
120 te.untilPresses(t, "Press 2 of 3. Esc shows the finished slide.", "presstext003")
121 te.rig.Run(chromedp.KeyEvent(" "))
122 te.untilPresses(t, "Press 3 of 3. Esc shows the finished slide.")
123 te.atCorner(t, "playing press 3")
124 te.rig.Run(chromedp.Click(chromedp.CSS(pressesSel)))
125 te.untilPresses(t, "3 presses")
126 te.atCorner(t, "back at rest")
127
128 s := te.apiSlide(t, token, "pressslide1")
129 if stepOf(s, "presstext001") != 1 || stepOf(s, "presstext002") != 2 || stepOf(s, "presstext003") != 3 || s["talk"] != nil {
130 t.Errorf("playing the slide changed it: %v", s)
131 }
132}
133
134// atCorner checks the presses control is a real button just under the
135// slide's bottom end corner, its end edge on the slide's whatever its
136// words: never over the slide or the notes, never past the slide's
137// start or the window's edges, and at least a 24px target.
138func (te *tidyEditor) atCorner(t *testing.T, when string) {
139 t.Helper()
140 var where string
141 te.rig.Run(chromedp.Sleep(100e6), evalInto(&where, `(() => {
142 const b = document.querySelector('`+pressesSel+`'), s = document.querySelector('[slides-stage] [slides-slide]')
143 const r = b.getBoundingClientRect(), q = s.getBoundingClientRect(), out = []
144 if (b.tagName !== 'BUTTON' || b.type !== 'button') out.push('it is a ' + b.tagName + ', not a button')
145 if (b.closest('[slides-slide]')) out.push('it is inside the slide')
146 if (r.top < q.bottom) out.push('it is over the slide: ' + JSON.stringify(r) + ' on ' + JSON.stringify(q))
147 if (Math.abs(q.right - r.right) > 1 || r.top - q.bottom > 8 || r.left < q.left - 0.5) out.push('it is not at the bottom end corner: ' + JSON.stringify(r) + ' under ' + JSON.stringify(q))
148 if (r.left < 0 || r.right > document.documentElement.clientWidth) out.push('it is past the window: ' + JSON.stringify(r))
149 const notes = document.querySelector('[slides-notes-pane]')?.getBoundingClientRect()
150 if (notes && notes.height && r.bottom > notes.top) out.push('it is over the notes: ' + JSON.stringify(r) + ' above ' + JSON.stringify(notes))
151 if (r.width < 24 || r.height < 24) out.push('it is smaller than a 24px target: ' + r.width + 'x' + r.height)
152 if (b.scrollWidth > b.clientWidth + 1) out.push('its words overflow it: ' + b.scrollWidth + ' in ' + b.clientWidth)
153 return out.join('; ')
154 })()`))
155 if where != "" {
156 t.Errorf("%s, the presses control (%q): %s", when, te.presses().Text, where)
157 }
158}
159
160// TestEscReturnsToTheFinishedSlide: while playing, Esc, a change of
161// slide, an edit here and a colleague's edit each show the finished
162// slide again.
163func TestEscReturnsToTheFinishedSlide(t *testing.T) {
164 te, token := openTalkEditor(t)
165 play := func() {
166 te.rig.Run(
167 waitFor(`document.querySelector('`+pressesSel+`')?.checkVisibility()`),
168 chromedp.Click(chromedp.CSS(pressesSel)),
169 )
170 te.untilPresses(t, "Press 1 of 3. Esc shows the finished slide.", "presstext002", "presstext003")
171 }
172
173 play()
174 te.rig.Run(chromedp.KeyEvent(kb.Escape))
175 te.untilPresses(t, "3 presses")
176 te.rig.Run(waitFor(`document.activeElement === document.querySelector('` + pressesSel + `')`))
177
178 // At 320px wide the whole sentence stays at the corner, inside the
179 // slide's width and the window, and Esc puts the count back there.
180 te.size(320, 700)
181 te.rig.Run(chromedp.Evaluate[chromedp.Void](`document.querySelector('` + pressesSel + `').scrollIntoView({ block: 'center' })`))
182 te.atCorner(t, "320px, at rest")
183 play()
184 te.atCorner(t, "320px, playing")
185 te.rig.Run(chromedp.KeyEvent(kb.Escape))
186 te.untilPresses(t, "3 presses")
187 te.atCorner(t, "320px, after Esc")
188 te.size(1280, 800)
189
190 play()
191 te.goToSlide("plainslide2")
192 if s := te.presses(); s.Shown || len(s.Waiting) != 0 {
193 t.Errorf("on a slide without presses after leaving one being played: %+v", s)
194 }
195 te.goToSlide("pressslide1")
196 te.untilPresses(t, "3 presses")
197
198 // An edit here: a word typed into the first text, the one shown.
199 play()
200 te.rig.Run(chromedp.Evaluate[chromedp.Void](`(() => {
201 const p = document.querySelector('[slides-stage] [slides-block][data-id="presstext001"] p')
202 const r = document.createRange(); r.selectNodeContents(p); r.collapse(false)
203 const s = getSelection(); s.removeAllRanges(); s.addRange(r)
204 p.closest('[contenteditable]').focus()
205 })()`), chromedp.KeyEvent("!"))
206 te.untilPresses(t, "3 presses")
207 te.untilSlide(t, token, "pressslide1", "with First!", func(s map[string]any) bool {
208 b, _ := blockOf(s, "presstext001")
209 return strings.Contains(fmt.Sprint(b), "First!")
210 })
211
212 // A colleague's.
213 play()
214 apiJSON(t, te.app, http.MethodPost, "/api/v1/decks/"+te.sqid()+"/ops", token,
215 `{"ops":[{"op":"set_slide","id":"pressslide1","transition":"fade"}]}`, http.StatusOK)
216 te.untilPresses(t, "3 presses")
217}
218
219// TestNoPressControlWithoutSteps: a slide with no steps has no control
220// and no count in the strip, and a slide whose last step is taken away
221// loses both.
222func TestNoPressControlWithoutSteps(t *testing.T) {
223 te, token := openTalkEditor(t)
224 te.goToSlide("plainslide2")
225 te.rig.Run(chromedp.Sleep(300e6))
226 if s := te.presses(); s.Shown {
227 t.Errorf("a slide without steps shows the control %+v", s)
228 }
229 if c := te.stripCount("plainslide2"); c.Text != "" || c.Shown {
230 t.Errorf("a slide without steps has a count in the strip: %+v", c)
231 }
232 te.goToSlide("pressslide1")
233 te.rig.Run(waitFor(`document.querySelector('` + pressesSel + `')?.checkVisibility()`))
234 apiJSON(t, te.app, http.MethodPost, "/api/v1/decks/"+te.sqid()+"/ops", token,
235 `{"ops":[{"op":"set_block","slide":"pressslide1","id":"presstext001","step":null},{"op":"set_block","slide":"pressslide1","id":"presstext002","step":null},{"op":"set_block","slide":"pressslide1","id":"presstext003","step":null}]}`, http.StatusOK)
236 te.rig.Run(waitFor(`!document.querySelector('` + pressesSel + `')?.checkVisibility()`))
237 te.rig.Run(waitFor(`!document.querySelector('[slides-strip-item][data-slide-id="pressslide1"] [slides-strip-presses]')?.checkVisibility()`))
238}
239
240// stripCount is slide id's count in the strip: its words, whether they
241// are drawn, and whether they sit in its picture's bottom end corner.
242type stripCountState struct {
243 Text string
244 Shown bool
245 Corner bool
246 Visible bool
247}
248
249func (te *tidyEditor) stripCount(id string) stripCountState {
250 var c stripCountState
251 te.rig.Run(evalInto(&c, `(() => {
252 const li = document.querySelector('[slides-strip-item][data-slide-id="`+id+`"]')
253 const c = li.querySelector('[slides-strip-presses]'), th = li.querySelector('[slides-thumb]')
254 if (!c) return { Text: '', Shown: false }
255 const r = c.getBoundingClientRect(), q = th.getBoundingClientRect()
256 return { Text: c.textContent.trim(), Shown: c.checkVisibility(),
257 Corner: r.right <= q.right + 0.5 && r.bottom <= q.bottom + 0.5 && q.right - r.right <= 12 && q.bottom - r.bottom <= 12 && r.left >= q.left && r.top >= q.top }
258 })()`))
259 return c
260}
261
262// stripIndex is slide id's place in the strip, 1-based.
263func (te *tidyEditor) stripIndex(id string) int {
264 var n int
265 te.rig.Run(evalInto(&n, `[...document.querySelectorAll('[slides-strip] > [slides-strip-item]')].findIndex(li => li.dataset.slideId === '`+id+`') + 1`))
266 return n
267}
268
269// TestStripCountsPresses: a slide with presses carries the count, small,
270// in its picture's bottom end corner and in its link's name; it follows
271// a step added to a slide that had none.
272func TestStripCountsPresses(t *testing.T) {
273 te, token := openTalkEditor(t)
274 if c := te.stripCount("pressslide1"); c.Text != "3 presses" || !c.Shown || !c.Corner {
275 t.Errorf("the slide with three presses: its count is %+v, want 3 presses drawn in the picture's bottom end corner", c)
276 }
277 if name := stripName(t, te.rig, 0); name != "1 Three presses 3 presses Current slide" && name != "1 Three presses Current slide 3 presses" {
278 t.Errorf("the slide with three presses is named %q, want its count in it", name)
279 }
280 if c := te.stripCount("lastslide01"); c.Text != "" || c.Shown {
281 t.Errorf("a slide without steps has a count %+v", c)
282 }
283 te.rig.Screen(`[slides-strip-nav]`, "the strip, a slide with three presses")
284 apiJSON(t, te.app, http.MethodPost, "/api/v1/decks/"+te.sqid()+"/ops", token,
285 `{"ops":[{"op":"set_block","slide":"plainslide2","id":"plaintext002","step":1}]}`, http.StatusOK)
286 te.rig.Run(waitFor(`document.querySelector('[slides-strip-item][data-slide-id="plainslide2"] [slides-strip-presses]')?.textContent.trim() === '1 press'`))
287 if c := te.stripCount("plainslide2"); !c.Shown || !c.Corner {
288 t.Errorf("a step added: the count is %+v, want 1 press drawn in the corner", c)
289 }
290}
291
292// TestAFullOnlySlideHasADashedEdge: the full-only slide's picture has a
293// dashed edge and its name says Full version only; the others have
294// neither, and taking it off takes both away.
295func TestAFullOnlySlideHasADashedEdge(t *testing.T) {
296 te, token := openTalkEditor(t)
297 edge := func(id string) string {
298 var s string
299 te.rig.Run(evalInto(&s, `(t => { const c = getComputedStyle(t); return c.outlineStyle + ' ' + c.borderTopStyle })(document.querySelector('[slides-strip-item][data-slide-id="`+id+`"] [slides-thumb]'))`))
300 return s
301 }
302 if e := edge("fullslide01"); !strings.Contains(e, "dashed") {
303 t.Errorf("the full-only slide's picture's edge is %q, want dashed", e)
304 }
305 for _, id := range []string{"pressslide1", "plainslide2", "lastslide01"} {
306 if e := edge(id); strings.Contains(e, "dashed") {
307 t.Errorf("%s's picture's edge is %q, want no dashes", id, e)
308 }
309 }
310 n := te.stripIndex("fullslide01")
311 if name := stripName(t, te.rig, n-1); name != "3 Only in full Full version only" {
312 t.Errorf("the full-only slide is named %q, want 3 Only in full Full version only", name)
313 }
314 te.rig.Screen(`[slides-strip-nav]`, "the strip, a full-only slide")
315 apiJSON(t, te.app, http.MethodPost, "/api/v1/decks/"+te.sqid()+"/ops", token,
316 `{"ops":[{"op":"set_slide","id":"fullslide01","talk":null}]}`, http.StatusOK)
317 te.rig.Run(waitFor(`!document.querySelector('[slides-strip-item][data-slide-id="fullslide01"]').hasAttribute('data-talk')`))
318 if e := edge("fullslide01"); strings.Contains(e, "dashed") {
319 t.Errorf("back in the talk, the slide's edge is still %q", e)
320 }
321 if name := stripName(t, te.rig, n-1); name != "3 Only in full" {
322 t.Errorf("back in the talk, the slide is named %q", name)
323 }
324}
325
326// TestAParkedSlideIsASlimBarInPlace: the parked slide keeps its place
327// in the strip, drawn as a slim bar showing its title and no picture,
328// and named with Parked after its title.
329func TestAParkedSlideIsASlimBarInPlace(t *testing.T) {
330 te, _ := openTalkEditor(t)
331 if n := te.stripIndex("parkslide01"); n != 4 {
332 t.Errorf("the parked slide is %d in the strip, want 4, its place in the deck", n)
333 }
334 var bar struct {
335 Bar, Thumb float64
336 Title string
337 TitleShown bool
338 PictureShown bool
339 Number, NumberT string
340 }
341 te.rig.Run(evalInto(&bar, `(() => {
342 const li = document.querySelector('[slides-strip-item][data-slide-id="parkslide01"]')
343 const other = document.querySelector('[slides-strip-item][data-slide-id="lastslide01"]')
344 const label = li.querySelector('[slides-strip-label]')
345 const r = label.getBoundingClientRect()
346 return { Bar: li.getBoundingClientRect().height, Thumb: other.getBoundingClientRect().height,
347 Title: label.textContent, TitleShown: label.checkVisibility() && r.width > 40 && r.height > 8,
348 PictureShown: li.querySelector('[slides-thumb]').checkVisibility(),
349 Number: li.querySelector('[slides-strip-number]').textContent }
350 })()`))
351 if bar.Bar <= 0 || bar.Bar > bar.Thumb/2 {
352 t.Errorf("the parked slide is %.1fpx tall beside a slide's %.1fpx, want a slim bar", bar.Bar, bar.Thumb)
353 }
354 if bar.Title != "Parked one" || !bar.TitleShown {
355 t.Errorf("the parked bar's title is %q (drawn %v), want Parked one drawn", bar.Title, bar.TitleShown)
356 }
357 if bar.PictureShown {
358 t.Error("the parked bar still draws the slide's picture")
359 }
360 if bar.Number != "4" {
361 t.Errorf("the parked bar's number is %q, want 4", bar.Number)
362 }
363 if name := stripName(t, te.rig, 3); name != "4 Parked one Parked" {
364 t.Errorf("the parked slide is named %q, want 4 Parked one Parked", name)
365 }
366 te.rig.Screen(`[slides-strip-nav]`, "the strip, a parked slide as a slim bar")
367 // It still opens on the stage, finished.
368 te.goToSlide("parkslide01")
369}
370
371// stripTalkJS: each strip item's data-talk, count and talk words, in
372// order, as "id:talk:count:words".
373const stripTalkJS = `[...document.querySelectorAll('[slides-strip] > [slides-strip-item]')].map(li =>
374 li.dataset.slideId + ':' + (li.dataset.talk || '') + ':' + (li.querySelector('[slides-strip-presses]')?.textContent.trim() || '') + ':' + (li.querySelector('[slides-strip-talk]')?.textContent.trim() || ''))`
375
376// TestStripIsFinalAtFirstPaint: the server draws each strip item's
377// talk, its words and its count; once the bundle is bound nothing of it
378// has changed (a watcher from the end of parsing, before any script,
379// saw no change).
380func TestStripIsFinalAtFirstPaint(t *testing.T) {
381 te := newTidyEditor(t, 1280, 800, func(a *testApp, cookies []*http.Cookie) string { return quieterDeck(t, a, cookies, talkEditorDeck) })
382 body := mustGet(t, te.app, te.path, http.StatusOK, te.cookies).Body.String()
383 live := regexp.MustCompile(`(?s)<template.*?</template>`).ReplaceAllString(body, "")
384 for _, want := range []string{
385 `data-slide-id="fullslide01" data-talk="full"`,
386 `data-slide-id="parkslide01" data-talk="parked"`,
387 `<span slides-strip-presses>3 presses</span>`,
388 `<span slides-strip-talk>Full version only</span>`,
389 `<span slides-strip-talk>Parked</span>`,
390 } {
391 if !strings.Contains(live, want) {
392 t.Errorf("the server's strip has no %s", want)
393 }
394 }
395 te.rig.Run(
396 cdpStep(page.AddScriptToEvaluateOnNewDocument, page.AddScriptToEvaluateOnNewDocumentParams{Source: `
397 window.__stripChanges = []
398 // From the end of parsing, before any script runs: the
399 // parser's own insertions are the first paint, not changes.
400 const watch = () => new MutationObserver(list => {
401 for (const m of list) {
402 const t = m.target.nodeType === 1 ? m.target : m.target.parentElement
403 if (!t || !t.closest('[slides-strip-item]')) continue
404 if (m.type === 'attributes' && m.attributeName !== 'data-talk' && m.attributeName !== 'aria-pressed') continue
405 if (m.type !== 'attributes' && !t.closest('[slides-strip-presses], [slides-strip-talk], [slides-strip-label]')) continue
406 window.__stripChanges.push(m.type + ' ' + (m.attributeName || '') + ' on ' + t.closest('[slides-strip-item]').dataset.slideId)
407 }
408 }).observe(document, { subtree: true, childList: true, attributes: true, characterData: true })
409 document.addEventListener('readystatechange', () => { if (document.readyState === 'interactive') watch() })`}),
410 chromedp.Navigate(te.rig.Origin+te.path),
411 chromedp.WaitVisible(chromedp.CSS(`[slides-editor]`)),
412 waitFor(editorBound),
413 chromedp.Sleep(500e6),
414 )
415 var changes, items []string
416 te.rig.Run(evalInto(&changes, `window.__stripChanges`), evalInto(&items, stripTalkJS))
417 if len(changes) != 0 {
418 t.Errorf("the strip changed once the bundle bound: %q", changes)
419 }
420 want := "pressslide1::3 presses:|plainslide2:::|fullslide01:full::Full version only|parkslide01:parked::Parked|lastslide01:::"
421 if got := strings.Join(items, "|"); got != want {
422 t.Errorf("the strip is %s, want %s", got, want)
423 }
424}
425
426// talkRows: a menu's two talk rows as the accessibility tree has them,
427// "role:name:pressed" each. Both menus are plain disclosures of buttons
428// (estilo's menubar <details>, rastrillo's dropdown), so a toggle row
429// is a button that is pressed or not, as the View menu's rows are.
430func (te *tidyEditor) talkRows(t *testing.T, menu string) string {
431 t.Helper()
432 var rows []string
433 for _, c := range []string{"slide-talk-full", "slide-talk-parked"} {
434 sel := menu + ` [data-command="` + c + `"], ` + menu + ` [data-slide-command="` + c + `"]`
435 var nodes []*chromedp.Node
436 te.rig.Run(harness.Into(&nodes, chromedp.Nodes(chromedp.CSS(sel))))
437 te.rig.Run(chromedp.Func(func(ctx2 context.Context, t *chromedp.Target) error {
438 res, err := cdp.Call(ctx2, t, accessibility.GetPartialAXTree, accessibility.GetPartialAXTreeParams{BackendNodeID: nodes[0].BackendNodeID, FetchRelatives: new(false)})
439 if err != nil {
440 return err
441 }
442 ax := res.Nodes
443 if len(ax) == 0 {
444 return fmt.Errorf("%s is not in the accessibility tree", sel)
445 }
446 n := ax[0]
447 var role, name string
448 if n.Role != nil {
449 _ = json.Unmarshal(n.Role.Value, &role)
450 }
451 if n.Name != nil {
452 _ = json.Unmarshal(n.Name.Value, &name)
453 }
454 pressed := "none"
455 for _, p := range n.Properties {
456 if p.Name == accessibility.PropertyNamePressed {
457 var v any
458 _ = json.Unmarshal(p.Value.Value, &v)
459 pressed = fmt.Sprint(v)
460 }
461 }
462 rows = append(rows, role+":"+strings.Join(strings.Fields(name), " ")+":"+pressed)
463 return nil
464 }))
465 }
466 return strings.Join(rows, " | ")
467}
468
469// talkRowsAre is talkRows' answer for a slide whose talk is full, parked or "".
470func talkRowsAre(talk string) string {
471 return "button:Skip in the short version:" + fmt.Sprint(talk == "full") + " | button:Park:" + fmt.Sprint(talk == "parked")
472}
473
474const (
475 stripMenu = `[slides-strip-item][data-slide-id="pressslide1"] [slides-strip-menu]`
476 slideMenu = `[slides-menu="slide"]`
477)
478
479func talkIs(want string) func(map[string]any) bool {
480 return func(s map[string]any) bool {
481 got, _ := s["talk"].(string)
482 return got == want
483 }
484}
485
486// TestParkAndSkipAreExclusive: the strip item's menu and the Slide menu
487// each have Skip in the short version and Park as toggle buttons,
488// pressed or not in the accessibility tree; each
489// is one write that clears the other, and choosing a checked one again
490// takes it away. One undo takes one back.
491func TestParkAndSkipAreExclusive(t *testing.T) {
492 te, token := openTalkEditor(t)
493 openStrip := chromedp.Steps(
494 chromedp.Click(chromedp.CSS(stripMenu+` > summary`)),
495 waitFor(`document.querySelector('`+stripMenu+`').open`),
496 )
497 openSlide := chromedp.Steps(
498 chromedp.Click(chromedp.CSS(slideMenu+` > summary`)),
499 waitFor(`document.querySelector('`+slideMenu+`').open`),
500 )
501 te.rig.Run(openStrip)
502 if got := te.talkRows(t, stripMenu); got != talkRowsAre("") {
503 t.Errorf("the strip item's menu has %q, want %q", got, talkRowsAre(""))
504 }
505 te.rig.Screen(`[slides-strip-nav]`, "the strip item's menu with its talk rows")
506 te.rig.Run(waitFor(`document.querySelector('`+stripMenu+` [data-slide-command="slide-talk-full"]')`),
507 chromedp.Click(chromedp.CSS(stripMenu+` [data-slide-command="slide-talk-full"]`)), waitFor(`!document.querySelector('`+stripMenu+`').open`))
508 te.untilSlide(t, token, "pressslide1", "full only", talkIs("full"))
509
510 te.rig.Run(openSlide)
511 if got := te.talkRows(t, slideMenu); got != talkRowsAre("full") {
512 t.Errorf("full only, the Slide menu has %q, want %q", got, talkRowsAre("full"))
513 }
514 te.rig.Run(waitFor(`document.querySelector('`+slideMenu+` [data-command="slide-talk-parked"]')`),
515 chromedp.Click(chromedp.CSS(slideMenu+` [data-command="slide-talk-parked"]`)), waitFor(`!document.querySelector('`+slideMenu+`').open`))
516 te.untilSlide(t, token, "pressslide1", "parked", talkIs("parked"))
517 te.rig.Run(waitFor(`document.querySelector('[slides-strip-item][data-slide-id="pressslide1"]').dataset.talk === 'parked'`))
518
519 te.rig.Run(openStrip)
520 if got := te.talkRows(t, stripMenu); got != talkRowsAre("parked") {
521 t.Errorf("parked, the strip item's menu has %q, want %q", got, talkRowsAre("parked"))
522 }
523 te.rig.Run(chromedp.KeyEvent(kb.Escape))
524
525 // One undo: full only again, not in the talk.
526 te.rig.Run(
527 chromedp.Click(chromedp.CSS(`[slides-menu="edit"] > summary`)),
528 waitFor(`document.querySelector('[slides-menu="edit"]')?.open === true`),
529 chromedp.Click(chromedp.CSS(`[slides-menu="edit"] [data-command="undo"]`)),
530 )
531 te.untilSlide(t, token, "pressslide1", "full only again", talkIs("full"))
532
533 // Skip again, already checked: back in the talk.
534 te.rig.Run(openSlide, chromedp.Click(chromedp.CSS(slideMenu+` [data-command="slide-talk-full"]`)))
535 te.untilSlide(t, token, "pressslide1", "back in the talk", talkIs(""))
536 te.rig.Run(openSlide)
537 if got := te.talkRows(t, slideMenu); got != talkRowsAre("") {
538 t.Errorf("back in the talk, the Slide menu has %q, want %q", got, talkRowsAre(""))
539 }
540}
541
542// TestHowThingsArriveIsSaved: Deck settings has How things arrive,
543// Appear at first; Fade in and Rise are written, and Appear takes the
544// setting away.
545func TestHowThingsArriveIsSaved(t *testing.T) {
546 te, token := openTalkEditor(t)
547 te.rig.Run(openDeckSettings())
548 var field struct {
549 Label string
550 Value string
551 Options []string
552 }
553 te.rig.Run(evalInto(&field, `(() => {
554 const s = document.querySelector('[slides-deck-dialog] [name="rst-deck-arrive"]')
555 return { Label: s.labels[0]?.textContent.trim() || '', Value: s.value, Options: [...s.options].map(o => o.value + '=' + o.textContent.trim()) }
556 })()`))
557 if field.Label != "How things arrive" || field.Value != "appear" || strings.Join(field.Options, "|") != "appear=Appear|fade=Fade in|rise=Rise" {
558 t.Errorf("Deck settings' arrival field is %+v", field)
559 }
560 te.rig.Screen(`[slides-deck-dialog]`, "Deck settings with How things arrive")
561 arrive := func() string {
562 view := apiJSON(t, te.app, http.MethodGet, "/api/v1/decks/"+te.sqid(), token, "", http.StatusOK)
563 meta, _ := view["meta"].(map[string]any)
564 v, _ := meta["arrive"].(string)
565 return v
566 }
567 for _, v := range []string{"fade", "rise", "appear"} {
568 te.rig.Run(chromedp.SetValue(chromedp.CSS(`[slides-deck-dialog] [name="rst-deck-arrive"]`), v),
569 chromedp.Evaluate[chromedp.Void](`document.querySelector('[slides-deck-dialog] [name="rst-deck-arrive"]').dispatchEvent(new Event('change', { bubbles: true }))`))
570 want := v
571 if v == "appear" {
572 want = ""
573 }
574 for tries := 0; arrive() != want && tries < 200; tries++ {
575 te.rig.Run(chromedp.Sleep(100e6))
576 }
577 if got := arrive(); got != want {
578 t.Errorf("chose %s: the deck's arrive is %q, want %q", v, got, want)
579 }
580 }
581}
582