| new file mode 100644 |
| index 0000000..7515d19 |
| --- /dev/null |
| +++ b/internal/slidestest/presenter_walk_browser_test.go |
| @@ -0,0 +1,101 @@ |
| +//go:build browser |
| + |
| +// The talk's whole shape, walked press by press (Task 16). It is slow |
| +// and only runs when asked: SLIDES_WALK=1 go test -tags browser -run |
| +// TestPresenterWalksTheWholeTalk ./internal/slidestest/ |
| +package slidestest |
| + |
| +import ( |
| + "fmt" |
| + "os" |
| + "strconv" |
| + "strings" |
| + "testing" |
| + |
| + "github.com/chromedp/chromedp" |
| + "github.com/chromedp/chromedp/kb" |
| +) |
| + |
| +// TestPresenterWalksTheWholeTalk is a deck of the talk's real size: 105 |
| +// slides in the talk (34 of them with four steps), 40 parked and 24 |
| +// shown only in the full version. In the core talk that is 104 slide |
| +// changes and 136 steps, 240 presses. Every press must change the |
| +// window's slide or step, and the document must never scroll. |
| +func TestPresenterWalksTheWholeTalk(t *testing.T) { |
| + if os.Getenv("SLIDES_WALK") == "" { |
| + t.Skip("set SLIDES_WALK=1 to walk the whole talk") |
| + } |
| + mt := newMovesTalk(t) |
| + // Start from an empty deck of our own on the same rig. |
| + sqid := mt.fr.deck(t, "Walk", `[]`) |
| + var ops []string |
| + add := func(id, head, talk string, steps int) { |
| + ops = append(ops, |
| + `{"op":"add_slide","id":`+quote(id)+`,"layout":"flow","template":"title-body"}`, |
| + `{"op":"add_block","slide":`+quote(id)+`,"id":`+quote(id+"h")+`,"type":"heading","region":"heading","props":{"level":1},"markdown":`+quote(head)+`}`) |
| + for k := 1; k <= steps; k++ { |
| + b := quote(id + "b" + strconv.Itoa(k)) |
| + ops = append(ops, |
| + `{"op":"add_block","slide":`+quote(id)+`,"id":`+b+`,"type":"text","region":"body","markdown":`+quote("line "+strconv.Itoa(k))+`}`, |
| + `{"op":"set_block","slide":`+quote(id)+`,"id":`+b+`,"step":`+strconv.Itoa(k)+`}`) |
| + } |
| + if talk != "" { |
| + ops = append(ops, `{"op":"set_slide","id":`+quote(id)+`,"talk":`+quote(talk)+`}`) |
| + } |
| + } |
| + for i := range 105 { |
| + steps := 0 |
| + if i%3 == 0 && i/3 < 34 { |
| + steps = 4 |
| + } |
| + add(fmt.Sprintf("t%03d", i), fmt.Sprintf("Talk %03d", i), "", steps) |
| + // Interleave the others: 64 across the 105. |
| + if i < 64 { |
| + talk := "parked" |
| + if i%8 < 3 { |
| + talk = "full" |
| + } |
| + add(fmt.Sprintf("x%03d", i), fmt.Sprintf("Aside %03d", i), talk, 0) |
| + } |
| + } |
| + for i := 0; i < len(ops); i += 100 { |
| + mt.fr.ops(t, sqid, "["+strings.Join(ops[i:min(i+100, len(ops))], ",")+"]") |
| + } |
| + mt.session, mt.token = startPresenting(t, mt.fr.app, "/d/"+sqid, mt.fr.cookies) |
| + |
| + ctx := mt.fr.rig.Context() |
| + open(t, ctx, mt.fr.rig.Origin, mt.presenter()) |
| + var scroll struct{ Y, SH, VH float64 } |
| + const scrollJS = `({ Y: window.scrollY, SH: document.documentElement.scrollHeight, VH: innerHeight })` |
| + seen := map[string]bool{} |
| + presses := 0 |
| + before := state(t, ctx) |
| + if before.Mode != "core" { |
| + t.Fatalf("the window starts in mode %q, want core", before.Mode) |
| + } |
| + for { |
| + if !strings.HasPrefix(before.Now, "Talk") { |
| + t.Fatalf("press %d: the window shows %q, which is not a talk slide", presses, before.Now) |
| + } |
| + seen[before.Slide] = true |
| + run(t, ctx, key(kb.ArrowRight)) |
| + got := state(t, ctx) |
| + if got.Slide == before.Slide && got.Step == before.Step { |
| + break // the last press of the talk moves nothing |
| + } |
| + presses++ |
| + if got.Mode != "core" { |
| + t.Fatalf("press %d: the mode became %q", presses, got.Mode) |
| + } |
| + run(t, ctx, chromedp.Evaluate(scrollJS, &scroll)) |
| + if scroll.Y != 0 || scroll.SH > scroll.VH { |
| + t.Fatalf("press %d: the document scrolls: %+v", presses, scroll) |
| + } |
| + before = got |
| + } |
| + seen[before.Slide] = true |
| + if len(seen) != 105 || presses != 240 { |
| + t.Fatalf("walked %d slides and %d presses, want 105 and 240", len(seen), presses) |
| + } |
| + mt.waitRow(t, "t104", 0) |
| +} |