//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/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 })` // The sequence every press must produce, from the deck built above. type at struct { head string step string } var want []at for i := range 105 { steps := 0 if i%3 == 0 && i/3 < 34 { steps = 4 } for k := 0; k <= steps; k++ { want = append(want, at{fmt.Sprintf("Talk %03d", i), strconv.Itoa(k)}) } } here := func(s windowState) at { head, _, _ := strings.Cut(s.Now, "\n") return at{strings.TrimSpace(head), s.Step} } before := state(t, ctx) if before.Mode != "core" { t.Fatalf("the window starts in mode %q, want core", before.Mode) } if got := here(before); got != want[0] { t.Fatalf("the window starts at %+v, want %+v", got, want[0]) } if len(want) != 241 { t.Fatalf("the expected walk has %d positions, want 241 (240 presses)", len(want)) } for press := 1; press < len(want); press++ { run(t, ctx, key(kb.ArrowRight)) got := state(t, ctx) if got.Mode != "core" { t.Fatalf("press %d: the mode became %q", press, got.Mode) } if g := here(got); g != want[press] { t.Fatalf("press %d: the window is at %+v, want %+v", press, g, want[press]) } run(t, ctx, evalInto(&scroll, scrollJS)) if scroll.Y != 0 || scroll.SH > scroll.VH { t.Fatalf("press %d: the document scrolls: %+v", press, scroll) } } // One more at the end moves nothing. run(t, ctx, key(kb.ArrowRight)) if g := here(state(t, ctx)); g != want[len(want)-1] { t.Fatalf("a press past the end moved the window to %+v", g) } mt.waitRow(t, "t104", 0) }