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// The talk's whole shape, walked press by press (Task 16). It is slow
4// and only runs when asked: SLIDES_WALK=1 go test -tags browser -run
5// TestPresenterWalksTheWholeTalk ./internal/slidestest/
6package slidestest
7
8import (
9 "fmt"
10 "os"
11 "strconv"
12 "strings"
13 "testing"
14
15 "github.com/chromedp/chromedp/kb"
16)
17
18// TestPresenterWalksTheWholeTalk is a deck of the talk's real size: 105
19// slides in the talk (34 of them with four steps), 40 parked and 24
20// shown only in the full version. In the core talk that is 104 slide
21// changes and 136 steps, 240 presses. Every press must change the
22// window's slide or step, and the document must never scroll.
23func TestPresenterWalksTheWholeTalk(t *testing.T) {
24 if os.Getenv("SLIDES_WALK") == "" {
25 t.Skip("set SLIDES_WALK=1 to walk the whole talk")
26 }
27 mt := newMovesTalk(t)
28 // Start from an empty deck of our own on the same rig.
29 sqid := mt.fr.deck(t, "Walk", `[]`)
30 var ops []string
31 add := func(id, head, talk string, steps int) {
32 ops = append(ops,
33 `{"op":"add_slide","id":`+quote(id)+`,"layout":"flow","template":"title-body"}`,
34 `{"op":"add_block","slide":`+quote(id)+`,"id":`+quote(id+"h")+`,"type":"heading","region":"heading","props":{"level":1},"markdown":`+quote(head)+`}`)
35 for k := 1; k <= steps; k++ {
36 b := quote(id + "b" + strconv.Itoa(k))
37 ops = append(ops,
38 `{"op":"add_block","slide":`+quote(id)+`,"id":`+b+`,"type":"text","region":"body","markdown":`+quote("line "+strconv.Itoa(k))+`}`,
39 `{"op":"set_block","slide":`+quote(id)+`,"id":`+b+`,"step":`+strconv.Itoa(k)+`}`)
40 }
41 if talk != "" {
42 ops = append(ops, `{"op":"set_slide","id":`+quote(id)+`,"talk":`+quote(talk)+`}`)
43 }
44 }
45 for i := range 105 {
46 steps := 0
47 if i%3 == 0 && i/3 < 34 {
48 steps = 4
49 }
50 add(fmt.Sprintf("t%03d", i), fmt.Sprintf("Talk %03d", i), "", steps)
51 // Interleave the others: 64 across the 105.
52 if i < 64 {
53 talk := "parked"
54 if i%8 < 3 {
55 talk = "full"
56 }
57 add(fmt.Sprintf("x%03d", i), fmt.Sprintf("Aside %03d", i), talk, 0)
58 }
59 }
60 for i := 0; i < len(ops); i += 100 {
61 mt.fr.ops(t, sqid, "["+strings.Join(ops[i:min(i+100, len(ops))], ",")+"]")
62 }
63 mt.session, mt.token = startPresenting(t, mt.fr.app, "/d/"+sqid, mt.fr.cookies)
64
65 ctx := mt.fr.rig.Context()
66 open(t, ctx, mt.fr.rig.Origin, mt.presenter())
67 var scroll struct{ Y, SH, VH float64 }
68 const scrollJS = `({ Y: window.scrollY, SH: document.documentElement.scrollHeight, VH: innerHeight })`
69 // The sequence every press must produce, from the deck built above.
70 type at struct {
71 head string
72 step string
73 }
74 var want []at
75 for i := range 105 {
76 steps := 0
77 if i%3 == 0 && i/3 < 34 {
78 steps = 4
79 }
80 for k := 0; k <= steps; k++ {
81 want = append(want, at{fmt.Sprintf("Talk %03d", i), strconv.Itoa(k)})
82 }
83 }
84 here := func(s windowState) at {
85 head, _, _ := strings.Cut(s.Now, "\n")
86 return at{strings.TrimSpace(head), s.Step}
87 }
88 before := state(t, ctx)
89 if before.Mode != "core" {
90 t.Fatalf("the window starts in mode %q, want core", before.Mode)
91 }
92 if got := here(before); got != want[0] {
93 t.Fatalf("the window starts at %+v, want %+v", got, want[0])
94 }
95 if len(want) != 241 {
96 t.Fatalf("the expected walk has %d positions, want 241 (240 presses)", len(want))
97 }
98 for press := 1; press < len(want); press++ {
99 run(t, ctx, key(kb.ArrowRight))
100 got := state(t, ctx)
101 if got.Mode != "core" {
102 t.Fatalf("press %d: the mode became %q", press, got.Mode)
103 }
104 if g := here(got); g != want[press] {
105 t.Fatalf("press %d: the window is at %+v, want %+v", press, g, want[press])
106 }
107 run(t, ctx, evalInto(&scroll, scrollJS))
108 if scroll.Y != 0 || scroll.SH > scroll.VH {
109 t.Fatalf("press %d: the document scrolls: %+v", press, scroll)
110 }
111 }
112 // One more at the end moves nothing.
113 run(t, ctx, key(kb.ArrowRight))
114 if g := here(state(t, ctx)); g != want[len(want)-1] {
115 t.Fatalf("a press past the end moved the window to %+v", g)
116 }
117 mt.waitRow(t, "t104", 0)
118}
119