oficina / slides Public

Presenting: steps on the slide window, follow link and remote

A session with a position draws its slide at a step on /p/{session}
and /s/{token}?follow=1: the session's, or ?slide=N&step=k (N through
the full talk, step clamped into the slide's presses). The counter
counts through the talk being given. A scriptless press redirects to
the page it came from with slide and step, so a resubmitted form lands
on the same page and counts once. present.js applies a step in place
from data-press, marking data-arriving only on what just arrived, and
the remote says "step n of total" on a slide with presses. The press
buttons on such sessions say Next and Back.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev f8781646cefec25ffac04aa725ecbcd590c96f68 parent 5b35e86
11 files changed, +757 −35
  • internal/slides/credits/assets.json +1 −1
  • internal/slides/locales/en.toml +7 −0
  • internal/slides/presentation.go +63 −14
  • internal/slides/presenting_position.go +106 −1
  • internal/slides/static/present.js +108 −13
  • internal/slides/templates/present.html +8 −2
  • internal/slides/templates/present_controls.html +6 −0
  • internal/slides/templates/remote.html +7 −1
  • internal/slidestest/present_steps_browser_test.go +228 −0
  • internal/slidestest/present_steps_test.go +218 −0
  • internal/slidestest/present_test.go +5 −3
diff --git a/internal/slides/credits/assets.json b/internal/slides/credits/assets.json
index d31b8f9..293f95f 100644
--- a/internal/slides/credits/assets.json
+++ b/internal/slides/credits/assets.json
@@ -68,7 +68,7 @@
"internal/slides/static/fonts/LiberationSerif-Regular.woff2": "922f544d0eabdf45ecd389b3bb35367e670b736e40851d01e53c150352c012f2",
"internal/slides/static/fontsgate.971e476eab8b8588.js": "971e476eab8b8588be520ac38eb823ab19beb2567db734555a7edc40d58567b2",
"internal/slides/static/fontshold.876f3d8d396da42f.js": "876f3d8d396da42f81954539f30b7200edfcde719d2920504707822f176a36ab",
- "internal/slides/static/present.js": "abcb8ee91742624a48f2196b760cb5368ed9b3392dd4c82acff7b6c7e018c1fa",
+ "internal/slides/static/present.js": "554d9df41f33ad307a888503e7c571b3bdd3686c6cd9e5b2f7f51f6b9f6d3cb7",
"internal/slides/static/rastrillo.js": "13a8ca6fa9ac25833f6485ab50a521dff7bd811372025dc5141b96522b60098b",
"internal/slides/static/select.js": "e231bad4b964464addfacd52d2260d4bdc0a02938fc033a25fdd9cbeb3671be1",
"internal/slides/static/shell.js": "bdc4d635fb8f14ef7089f7f692290baea645b13543be36328e7667fe8aed2caf",
diff --git a/internal/slides/locales/en.toml b/internal/slides/locales/en.toml
index b51cfa2..531135b 100644
--- a/internal/slides/locales/en.toml
+++ b/internal/slides/locales/en.toml
@@ -665,6 +665,13 @@ slides.present.clock = "Time now"
slides.present.started = "Started {when}"
slides.present.elapsed = "Running {n} min"
+# A session with a position presses through a slide's steps before it
+# leaves the slide, so its buttons say Back and Next rather than naming
+# a slide, and the phone says which step under where the talk is.
+slides.present.press.next = "Next"
+slides.present.press.back = "Back"
+slides.present.step.count = "step {n} of {total}"
+
# A session that is over — ended, or past its twelve hours. A 410, and
# worded as one: the talk finished, which is a different thing from an
# address that was never real.
diff --git a/internal/slides/presentation.go b/internal/slides/presentation.go
index 913c6c5..a81ce2e 100644
--- a/internal/slides/presentation.go
+++ b/internal/slides/presentation.go
@@ -475,9 +475,20 @@ type surfacePage struct {
HasSlide bool
Slide template.HTML
- Now int
- Total int
- Counter string
+ // Now is the 1-based slide number events carry (eventFor), and
+ // Total the slides a reader may see. Place and Places are what the
+ // counter and the progress bar say: for a session with a position,
+ // the slide's place in the talk being given (talkPlace).
+ Now int
+ Total int
+ Place int
+ Places int
+ Counter string
+ // Stepped marks a session with a position, whose slide is drawn at
+ // Step (the surface's data-step), so static/present.js can apply
+ // the next step in place.
+ Stepped bool
+ Step int
// Announce is what the surface's live region says when it changes
// to this slide in place (static/present.js): "Slide 3 of 12:
// Revenue".
@@ -574,6 +585,10 @@ type remotePage struct {
NextLabel string
Next template.HTML
HasNext bool
+ // Stepped, Step and StepCount: see presented.
+ Stepped bool
+ Step int
+ StepCount string
NotesLabel string
Notes template.HTML
@@ -696,7 +711,17 @@ func (a *app) renderSurface(w http.ResponseWriter, r *http.Request, d Deck, p Pr
// the script fetches the slide an event just named.
index := clampSlide(p.Slide, len(view.Slides))
live := true
- if raw := q.Get("slide"); raw != "" {
+ // A session with a position draws its slide at a step: the
+ // session's, or the one ?step=k names (stepPlace).
+ var reveal *int
+ if p.Positional {
+ at, ok := stepPlace(view, p, q)
+ if !ok {
+ a.notFound(w, r)
+ return
+ }
+ index, live, reveal = at.index, at.live, &at.step
+ } else if raw := q.Get("slide"); raw != "" {
n, ok := slideIndex(raw, len(view.Slides))
if !ok {
a.notFound(w, r)
@@ -710,7 +735,7 @@ func (a *app) renderSurface(w http.ResponseWriter, r *http.Request, d Deck, p Pr
// (assets.go): the presentation's for a projector, the share
// link's for a follower.
html, err := slidehtml.SlideWith(view, index, slidehtml.Desktop,
- slidehtml.Options{AssetBase: assetBaseFor(opt.base)})
+ slidehtml.Options{AssetBase: assetBaseFor(opt.base), Reveal: reveal})
if err != nil {
a.fail(w, r, "render slide", err)
return
@@ -728,7 +753,12 @@ func (a *app) renderSurface(w http.ResponseWriter, r *http.Request, d Deck, p Pr
page.Slide = html
page.Now = index + 1
page.Total = len(view.Slides)
- page.Counter = rastrillo.Tf(r, "slides.present.progress", "n", page.Now, "total", page.Total)
+ page.Place, page.Places = page.Now, page.Total
+ if reveal != nil {
+ page.Stepped, page.Step = true, *reveal
+ page.Place, page.Places = talkPlace(view, positionOf(p).Mode, index)
+ }
+ page.Counter = rastrillo.Tf(r, "slides.present.progress", "n", page.Place, "total", page.Places)
page.Announce = rastrillo.Tf(r, "slides.slide.announce", "n", page.Now, "total", page.Total, "title", slideLabel(r, view.Slides[index], page.Now))
page.ProgressLabel = rastrillo.T(r, "slides.present.progress.label")
page.PagerLabel = rastrillo.T(r, "slides.viewer.pager")
@@ -749,12 +779,13 @@ func (a *app) renderSurface(w http.ResponseWriter, r *http.Request, d Deck, p Pr
// the pager posts commands, so the projector's own next button
// moves the talk rather than only this browser.
page.Token = opt.token
+ back, next := pressLabels(r, p)
page.Controls = &controls{
Action: "/p/" + p.Sqid + "/command",
Token: opt.token,
Buttons: withPressIDs([]commandButton{
- {Op: "prev", Label: page.PrevLabel},
- {Op: "next", Label: page.NextLabel},
+ {Op: "prev", Label: back},
+ {Op: "next", Label: next},
}),
}
page.NotesHref = "/p/" + p.Sqid + "/notes?t=" + url.QueryEscape(opt.token)
@@ -913,6 +944,13 @@ type presented struct {
Next template.HTML
HasNext bool
Notes template.HTML
+ // For a session with a position: Stepped, the step it is at (the
+ // page's data-step, so the remote reloads for a step too), and
+ // "step 2 of 4" for a slide with presses, empty for one without.
+ // The pictures stay the finished slides (P3).
+ Stepped bool
+ Step int
+ StepCount string
}
// presentedFor builds them. A slide that will not draw leaves its half
@@ -925,11 +963,20 @@ func presentedFor(r *http.Request, view *deck.Deck, p Presentation) presented {
return presented{}
}
index := clampSlide(p.Slide, count)
- out := presented{
- Now: index + 1,
- Counter: rastrillo.Tf(r, "slides.present.progress", "n", index+1, "total", count),
- Current: slideThumbImg(r, view, p, index),
+ n, total := index+1, count
+ var out presented
+ if p.Positional {
+ var presses int
+ index, out.Step, presses = sessionPlace(view, p)
+ out.Stepped = true
+ n, total = talkPlace(view, positionOf(p).Mode, index)
+ if presses > 0 {
+ out.StepCount = rastrillo.Tf(r, "slides.present.step.count", "n", out.Step, "total", presses)
+ }
}
+ out.Now = index + 1
+ out.Counter = rastrillo.Tf(r, "slides.present.progress", "n", n, "total", total)
+ out.Current = slideThumbImg(r, view, p, index)
if index+1 < count {
out.HasNext = true
out.Next = slideThumbImg(r, view, p, index+1)
@@ -972,12 +1019,13 @@ func commandControls(r *http.Request, p Presentation, token string) *controls {
if p.Blackout {
blackout = rastrillo.T(r, "slides.present.unblackout")
}
+ back, next := pressLabels(r, p)
return &controls{
Action: "/p/" + p.Sqid + "/command",
Token: token,
Buttons: withPressIDs([]commandButton{
- {Op: "prev", Label: rastrillo.T(r, "slides.present.prev")},
- {Op: "next", Label: rastrillo.T(r, "slides.present.next")},
+ {Op: "prev", Label: back},
+ {Op: "next", Label: next},
{Op: "blackout", Label: blackout},
{Op: "end", Label: rastrillo.T(r, "slides.present.end")},
}),
@@ -1032,6 +1080,7 @@ func (a *app) remote(w http.ResponseWriter, r *http.Request) {
shown := presentedFor(r, view, p)
page.Now, page.Counter, page.Current = shown.Now, shown.Counter, shown.Current
page.Next, page.HasNext, page.Notes = shown.Next, shown.HasNext, shown.Notes
+ page.Stepped, page.Step, page.StepCount = shown.Stepped, shown.Step, shown.StepCount
render(w, "remote", page)
}
diff --git a/internal/slides/presenting_position.go b/internal/slides/presenting_position.go
index 97f76de..2315daf 100644
--- a/internal/slides/presenting_position.go
+++ b/internal/slides/presenting_position.go
@@ -18,12 +18,14 @@ import (
"crypto/rand"
"errors"
"net/http"
+ "net/url"
"regexp"
"strconv"
"strings"
"time"
"amadan.net/oficina/slides/internal/slides/deck"
+ "amadan.net/rastrillo/rastrillo"
"gorm.io/gorm"
)
@@ -55,6 +57,9 @@ type positionAnswer struct {
Black bool `json:"black"`
Seq int64 `json:"seq"`
DeckSeq int64 `json:"deckSeq"`
+ // number is the slide's 1-based number in the full talk, which a
+ // scriptless press's redirect names (pressLanding). Not on the wire.
+ number int
}
// mayDrive is who may move a Positional session: whoever holds the
@@ -154,12 +159,111 @@ func (a *app) presentPress(w http.ResponseWriter, r *http.Request, p Presentatio
return
}
if ref := r.Header.Get("Referer"); ref != "" && a.sameOrigin(ref) {
- http.Redirect(w, r, ref, http.StatusSeeOther)
+ http.Redirect(w, r, pressLanding(ref, answer), http.StatusSeeOther)
return
}
w.WriteHeader(http.StatusNoContent)
}
+// pressLanding is where a form's press sends the browser back to: the
+// page it came from, saying the slide and step the talk is now at, so a
+// projector with scripts off draws that state (stepPlace) and a press
+// resubmitted lands on the same page as the first. ref is already known
+// to be this app's own.
+func pressLanding(ref string, at positionAnswer) string {
+ u, err := url.Parse(ref)
+ if err != nil {
+ return ref
+ }
+ q := u.Query()
+ q.Set("slide", strconv.Itoa(at.number))
+ q.Set("step", strconv.Itoa(at.Step))
+ u.RawQuery = q.Encode()
+ return u.String()
+}
+
+// place is a slide of the reader deck, the step it is drawn at, and
+// whether that is where the session is.
+type place struct {
+ index, step int
+ live bool
+}
+
+// stepPlace is what a surface of a session with a position draws.
+// Without ?slide it is the session's own place. ?slide=N counts from 1
+// through the full talk (the reader deck, and talkSlide.Number), and
+// is read as ?slide= always was: a number outside the talk, or not a
+// number, is ok false, the 404 (a parked slide's old place must reach
+// nobody). ?step=k clamps into the slide's presses; a step that is not
+// a number is the same 404. A slide named without a step is drawn at
+// the session's step when it is the session's slide, and finished
+// otherwise.
+func stepPlace(view *deck.Deck, p Presentation, q url.Values) (place, bool) {
+ cur, curStep, _ := sessionPlace(view, p)
+ raw := q.Get("slide")
+ if raw == "" {
+ return place{index: cur, step: curStep, live: true}, true
+ }
+ index, ok := slideIndex(raw, len(view.Slides))
+ if !ok {
+ return place{}, false
+ }
+ presses := len(deck.Presses(view.Slides[index]))
+ step := presses
+ if rawStep := q.Get("step"); rawStep != "" {
+ k, err := strconv.Atoi(rawStep)
+ if err != nil {
+ return place{}, false
+ }
+ step = min(max(k, 0), presses)
+ } else if index == cur {
+ step = curStep
+ }
+ return place{index: index, step: step, live: index == cur && step == curStep}, true
+}
+
+// sessionPlace is the session's position in the reader deck: the index
+// of its slide, the step (settled into the deck as it is now, as a
+// press would settle it), and how many presses the slide has.
+func sessionPlace(view *deck.Deck, p Presentation) (index, step, presses int) {
+ pos := deck.SettleNear(view, positionOf(p), p.Slide)
+ for i, s := range view.Slides {
+ if s.ID == pos.Slide {
+ return i, pos.Step, len(deck.Presses(s))
+ }
+ }
+ index = clampSlide(p.Slide, len(view.Slides))
+ return index, 0, len(deck.Presses(view.Slides[index]))
+}
+
+// talkPlace is the counter's "n / total" for the slide at index: its
+// place in the talk being given, in mode. A slide outside that talk (a
+// full-only slide shown in the short version) takes the place of the
+// slide before it. A talk with nothing in it counts the reader deck.
+func talkPlace(view *deck.Deck, mode deck.Mode, index int) (int, int) {
+ order := deck.TalkOrder(view, mode)
+ if len(order) == 0 {
+ return index + 1, len(view.Slides)
+ }
+ n := 1
+ for k, i := range order {
+ if i <= index {
+ n = k + 1
+ }
+ }
+ return n, len(order)
+}
+
+// pressLabels are the back and forward buttons' words: a press may be
+// a step rather than a slide on a session with a position, so there
+// they say Back and Next; a session begun before keeps its own.
+func pressLabels(r *http.Request, p Presentation) (back, next string) {
+ if p.Positional {
+ return rastrillo.T(r, "slides.present.press.back"), rastrillo.T(r, "slides.present.press.next")
+ }
+ return rastrillo.T(r, "slides.present.prev"), rastrillo.T(r, "slides.present.next")
+}
+
// pressCommandFrom reads the form. A missing or malformed press id is
// errBadCommand: without one a press resent cannot be told from a
// second press. So is a step or a mode that is present but malformed;
@@ -282,6 +386,7 @@ func (a *app) applyPress(r *http.Request, p Presentation, cmd pressCommand) (pos
Black: updated.Blackout,
Seq: updated.Seq,
DeckSeq: deckSeq,
+ number: updated.Slide + 1,
}, nil
}
diff --git a/internal/slides/static/present.js b/internal/slides/static/present.js
index 33bab7e..ebaf68d 100644
--- a/internal/slides/static/present.js
+++ b/internal/slides/static/present.js
@@ -112,32 +112,91 @@
var requested = displayed;
var newest = 0;
+ // Steps, on a session with a position. Its surface says which step
+ // the slide is drawn at (data-step), and each box or list item that
+ // arrives on a press carries data-press, with data-waiting while its
+ // press has not come. Moving to another step of the same slide is done
+ // here, in place: data-waiting follows the step, and data-arriving
+ // goes on what has just arrived and nothing else, until its effect
+ // ends or the next step comes (slides.css draws the effect, and leaves
+ // it out under reduced motion). Back within a slide animates nothing.
+ // A page without data-step (a session begun before positions) has
+ // null for its step and none of this applies.
+ function shownStep() {
+ var step = root.getAttribute('data-step');
+ return step === null ? null : Number(step) || 0;
+ }
+ var requestedStep = shownStep();
+ // unstepped is a stage's markup without what a step changes: two
+ // drawings of one slide at different steps are the same once it is
+ // taken out, and installed is that of the slide on the stage.
+ function unstepped(html) {
+ var t = document.createElement('template');
+ t.innerHTML = html;
+ var marked = t.content.querySelectorAll('[data-waiting], [data-arriving]');
+ for (var i = 0; i < marked.length; i++) {
+ marked[i].removeAttribute('data-waiting');
+ marked[i].removeAttribute('data-arriving');
+ }
+ return t.innerHTML;
+ }
+ var installed = stage ? unstepped(stage.innerHTML) : '';
+ function reveal(step) {
+ var settled = stage.querySelectorAll('[data-arriving]');
+ for (var i = 0; i < settled.length; i++) settled[i].removeAttribute('data-arriving');
+ var marked = stage.querySelectorAll('[data-press]');
+ for (var j = 0; j < marked.length; j++) {
+ var el = marked[j];
+ if (Number(el.getAttribute('data-press')) > step) {
+ el.setAttribute('data-waiting', '');
+ } else if (el.hasAttribute('data-waiting')) {
+ el.removeAttribute('data-waiting');
+ el.setAttribute('data-arriving', '');
+ el.addEventListener('animationend', arrived);
+ }
+ }
+ root.setAttribute('data-step', String(step));
+ requestedStep = step;
+ }
+ function arrived(e) {
+ if (e.target !== e.currentTarget) return;
+ e.currentTarget.removeAttribute('data-arriving');
+ e.currentTarget.removeEventListener('animationend', arrived);
+ }
+
// pageFor is this same surface's page for a slide: same capability,
- // same token, ?slide=n. Its stage and its bar (counter, progress, the
- // pager or the presenter's buttons) are what the slide looks like here.
- function pageFor(slide) {
+ // same token, ?slide=n, and &step=k on a session with a position. Its
+ // stage and its bar (counter, progress, the pager or the presenter's
+ // buttons) are what the slide looks like here.
+ function pageFor(slide, step) {
var u = new URL(location.href);
u.searchParams.set('slide', String(slide));
+ if (step === null) u.searchParams.delete('step');
+ else u.searchParams.set('step', String(step));
return u.href;
}
- function show(slide) {
+ function show(slide, step) {
// Slide numbers on the wire are 1-based; anything else is not an
// event this page understands and is left alone rather than fetched.
- if (!(slide > 0) || slide === requested) return;
+ if (!(slide > 0) || (slide === requested && step === requestedStep)) return;
requested = slide;
+ requestedStep = step;
var mine = ++newest;
// The stage and the bar together, from this surface's own page for
// the slide, so the counter and the pager move with the slide (a
// fragment moved the stage alone). The blackout is the stream's: the
// page for an explicit slide is never blacked out.
- fetchPage(pageFor(slide))
+ fetchPage(pageFor(slide, step))
.then(function (html) { return swapFrom(html, null, false, mine, true); })
.catch(function () {
// Only this request's own failure rolls the record back, and
// only while it is still the newest: otherwise the next event
// for this slide would be suppressed as one already asked for.
- if (mine === newest && requested === slide) requested = displayed;
+ if (mine === newest && requested === slide && requestedStep === step) {
+ requested = displayed;
+ requestedStep = shownStep();
+ }
});
}
@@ -194,7 +253,18 @@
hadOp = op ? op.value : null;
hadRel = active.getAttribute && active.getAttribute('rel');
}
- stage.innerHTML = nextStage.innerHTML;
+ // The same slide at another step changes in place; anything else
+ // is swapped whole, as a slide always was.
+ var nextStep = nextRoot.getAttribute('data-step');
+ var drawn = unstepped(nextStage.innerHTML);
+ if (nextStep !== null && shownStep() !== null && drawn === installed) {
+ reveal(Number(nextStep) || 0);
+ } else {
+ stage.innerHTML = nextStage.innerHTML;
+ installed = drawn;
+ if (nextStep === null) root.removeAttribute('data-step');
+ else root.setAttribute('data-step', nextStep);
+ }
if (bar && nextBar) {
var fresh = document.importNode(nextBar, true);
bar.replaceWith(fresh);
@@ -222,6 +292,7 @@
}
var slide = Number(nextRoot.getAttribute('data-slide')) || displayed;
displayed = requested = slide;
+ requestedStep = shownStep();
root.setAttribute('data-slide', String(slide));
if (!keepBlackout) {
root.setAttribute('data-blackout', nextRoot.getAttribute('data-blackout') || 'false');
@@ -288,7 +359,11 @@
// presenter view once did exactly that about fifty times a second
// (polish audit B3). The record is taken off at load, so it only
// ever guards the load straight after the reload that wrote it.
+ //
+ // A page that says its step (the remote, on a session with a
+ // position, data-step) reloads for a step as for a slide.
var renderedBlackout = root.getAttribute('data-blackout') === 'true';
+ var renderedStep = root.getAttribute('data-step');
var reloadKey = 'slides-present-reload:' + window.location.pathname;
var reloadedFor = null;
try {
@@ -296,12 +371,14 @@
window.sessionStorage.removeItem(reloadKey);
} catch (err) { /* no storage: see follow */ }
- function follow(state) {
+ function follow(state, step) {
var slide = Number(state.slide);
if (!(slide > 0)) return;
var blackout = !!state.blackout;
- if (slide === displayed && blackout === renderedBlackout) return;
- var want = String(slide) + (blackout ? ':blackout' : '');
+ if (renderedStep === null) step = null;
+ if (slide === displayed && blackout === renderedBlackout &&
+ (step === null || String(step) === renderedStep)) return;
+ var want = String(slide) + (step === null ? '' : '.' + step) + (blackout ? ':blackout' : '');
if (want === reloadedFor) return;
try {
window.sessionStorage.setItem(reloadKey, want);
@@ -318,17 +395,35 @@
// never a delta — so applying one is exactly right rather than
// approximately, and a page that missed some is right again on the
// next one.
+ //
+ // A session with a position names its slide by id and numbers its
+ // events (seq): one older than an event already applied is late and
+ // changes nothing, and its step is applied in place when the slide is
+ // the one on the stage.
+ var appliedSeq = 0;
function apply(state) {
if (state.ended) { window.location.reload(); return; }
- if (!stage || !fragmentHref) { follow(state); return; }
+ var seq = Number(state.seq) || 0;
+ if (seq) {
+ if (seq < appliedSeq) return;
+ appliedSeq = seq;
+ }
+ var step = state.slideId ? Number(state.step) || 0 : null;
+ if (!stage || !fragmentHref) { follow(state, step); return; }
// The stream's state is newer than any request still out: none of
// them may be applied after it. The slide it names is fetched afresh
// unless it is the one already shown.
newest++;
requested = displayed;
+ requestedStep = shownStep();
root.setAttribute('data-blackout', state.blackout ? 'true' : 'false');
if (note) note.hidden = !state.blackout;
- show(Number(state.slide));
+ var slide = Number(state.slide);
+ if (step !== null && requestedStep !== null && slide === displayed) {
+ if (step !== requestedStep) reveal(step);
+ return;
+ }
+ show(slide, step);
}
// The stream is the page's only while the page is: leaving it (another
diff --git a/internal/slides/templates/present.html b/internal/slides/templates/present.html
index ea356cf..cba575e 100644
--- a/internal/slides/templates/present.html
+++ b/internal/slides/templates/present.html
@@ -9,7 +9,12 @@
Nothing here needs the script. With it, static/present.js swaps
the slide when the session moves; without it, the follow view has
- a meta refresh and the presenter has next and previous. */}}
+ a meta refresh and the presenter has next and previous.
+
+ A session with a position draws its slide at a step (data-step):
+ the session's, or the ?slide=N&step=k a scriptless press redirects
+ to. present.js applies a step change in place, from the data-press
+ each arriving box carries. */}}
{{define "page-head"}}<link rel="stylesheet" href="{{asset "static/slides.css"}}">
{{if .Refresh}}{{/* The scriptless heartbeat: an audience with no
JavaScript still moves with the presenter, five seconds behind.
@@ -112,6 +117,7 @@
{{- if .StreamHref}} data-stream="{{.StreamHref}}"{{end}}
{{- if .FragmentHref}} data-fragment="{{.FragmentHref}}"{{end}}
data-slide="{{.Now}}"
+ {{- if .Stepped}} data-step="{{.Step}}"{{end}}
data-blackout="{{if .Blackout}}true{{else}}false{{end}}"
{{- with .Announce}} data-announce="{{.}}"{{end}}
{{- if .Token}} data-remote-token="{{.Token}}"{{end}}
@@ -131,7 +137,7 @@
beside it is the same fact as a picture, and is hidden from
assistive tech rather than announced twice. */}}
<p slides-counter><span class="rst-sr-only">{{.ProgressLabel}}</span> {{.Counter}}</p>
- <progress slides-progress value="{{.Now}}" max="{{.Total}}" aria-hidden="true"></progress>
+ <progress slides-progress value="{{.Place}}" max="{{.Places}}" aria-hidden="true"></progress>
{{if .NotesHref}}<a rst-btn href="{{.NotesHref}}">{{.NotesLabel}}</a>{{end}}
{{if .BackHref}}<a rst-btn href="{{.BackHref}}">{{.BackLabel}}</a>{{end}}
</div>
diff --git a/internal/slides/templates/present_controls.html b/internal/slides/templates/present_controls.html
index 76ac76c..d8505eb 100644
--- a/internal/slides/templates/present_controls.html
+++ b/internal/slides/templates/present_controls.html
@@ -8,6 +8,12 @@
it is there, so the two paths send identical requests and there is
no second protocol to keep in step.
+ On a session with a position a press may be a step, not a slide:
+ the forward and back buttons say Next and Back, and the redirect
+ names the slide and step the press reached
+ (presenting_position.go's pressLanding), so the page it lands on
+ draws that state and a resubmitted form lands on the same page.
+
The capability rides as a hidden field rather than living in the
form's action: an action carrying a token would put it in the
address bar of every page the redirect lands on.
diff --git a/internal/slides/templates/remote.html b/internal/slides/templates/remote.html
index 17e3769..bec17bc 100644
--- a/internal/slides/templates/remote.html
+++ b/internal/slides/templates/remote.html
@@ -51,7 +51,7 @@
flex-wrap: wrap;
gap: var(--rst-sp-2);
}
- [slides-counter] {
+ [slides-counter], [slides-step-count] {
color: var(--rst-text-muted);
margin: 0;
}
@@ -61,6 +61,7 @@
<div slides-remote data-session="{{.Session}}" data-remote-token="{{.Controls.Token}}"
data-slide="{{.Now}}"
+ {{- if .Stepped}} data-step="{{.Step}}"{{end}}
data-blackout="{{if .Blackout}}true{{else}}false{{end}}">
<div slides-remote-preview>
<div>
@@ -73,6 +74,11 @@
</div>
</div>
<p slides-counter>{{.Counter}}</p>
+ {{/* Which step, on a slide with presses only. The picture above
+ stays the finished slide (P3); this line is what says how far
+ through it the room is. data-step is what present.js compares,
+ so a step reloads this page as a slide does. */}}
+ {{with .StepCount}}<p slides-step-count>{{.}}</p>{{end}}
{{if .Blackout}}
{{template "status-pill" dict "Tone" "neutral" "Label" .BlackoutLabel}}
{{end}}
diff --git a/internal/slidestest/present_steps_browser_test.go b/internal/slidestest/present_steps_browser_test.go
new file mode 100644
index 0000000..b17ed54
--- /dev/null
+++ b/internal/slidestest/present_steps_browser_test.go
@@ -0,0 +1,228 @@
+//go:build browser
+
+// Steps with the script on: present.js applies a step in place, from
+// each box's data-press, and marks data-arriving only on what has just
+// arrived (Task 6). The Go tests read the markup; only a browser shows
+// that the slide stays the same node and that reduced motion appears.
+package slidestest
+
+import (
+ "context"
+ "encoding/json"
+ "net/http"
+ "net/url"
+ "strconv"
+ "strings"
+ "testing"
+
+ "amadan.net/rastrillo/rastrillo/harness"
+ "github.com/chromedp/cdproto/emulation"
+ "github.com/chromedp/chromedp"
+ "github.com/chromedp/chromedp/kb"
+)
+
+// stepsTalk is a browser beside a session on stepsDeck, which the test
+// drives over HTTP with the remote token.
+type stepsTalk struct {
+ rig *harness.Rig
+ app *testApp
+ cookies []*http.Cookie
+ deck string // /d/{sqid}
+ session, token string
+}
+
+func newStepsTalk(t *testing.T) *stepsTalk {
+ t.Helper()
+ rig, app := newRigApp(t, nil)
+ cookies := signedIn(t, app, allowedAddress)
+ deck := stepsDeck(t, app, cookies)
+ session, token := startPresenting(t, app, deck, cookies)
+ return &stepsTalk{rig: rig, app: app, cookies: cookies, deck: deck, session: session, token: token}
+}
+
+func (st *stepsTalk) press(t *testing.T, name string) {
+ t.Helper()
+ press(t, st.app, st.session, st.token, op(t, name), nil)
+}
+
+// stageState is what the stage shows: the presses still waiting, the
+// ones marked arriving, the surface's data-slide and data-step, and
+// whether the slide is the node marked by markSection.
+type stageState struct {
+ Waiting []string `json:"waiting"`
+ Arriving []string `json:"arriving"`
+ Slide string `json:"slide"`
+ Step string `json:"step"`
+ Same bool `json:"same"`
+}
+
+const markSection = `(window.__section = document.querySelector('[slides-stage] [slides-slide]'), true)`
+
+func (st *stepsTalk) stage(t *testing.T) stageState {
+ t.Helper()
+ var raw string
+ st.rig.Run(chromedp.Evaluate(`JSON.stringify((() => {
+ const stage = document.querySelector('[slides-stage]');
+ const root = document.querySelector('[slides-surface]');
+ const presses = sel => [...stage.querySelectorAll(sel)].map(e => e.dataset.press);
+ return {
+ waiting: presses('[data-waiting]'),
+ arriving: presses('[data-arriving]'),
+ slide: root.getAttribute('data-slide'),
+ step: root.getAttribute('data-step'),
+ same: stage.querySelector('[slides-slide]') === window.__section,
+ };
+ })())`, &raw))
+ var out stageState
+ if err := json.Unmarshal([]byte(raw), &out); err != nil {
+ t.Fatalf("read the stage: %v\n%s", err, raw)
+ }
+ return out
+}
+
+// waitWaiting waits until n presses are waiting on the stage.
+func waitWaiting(n string) chromedp.Action {
+ return waitFor(`document.querySelectorAll('[slides-stage] [data-waiting]').length === ` + n)
+}
+
+// TestFollowRevealsInPlace: a step heard on the stream changes the
+// follow view's slide in place, the section the same node, and only
+// what has just arrived is marked arriving; a step back marks nothing.
+func TestFollowRevealsInPlace(t *testing.T) {
+ st := newStepsTalk(t)
+ share := mintShareLink(t, st.app, st.deck, st.cookies)
+ st.rig.Run(
+ chromedp.Navigate(st.rig.Origin+"/s/"+share+"?follow=1"),
+ chromedp.WaitVisible(`[slides-stage] [slides-slide]`, chromedp.ByQuery),
+ waitWaiting("4"),
+ chromedp.Evaluate(markSection, nil),
+ )
+
+ for _, want := range []struct{ op, waiting, arriving, step string }{
+ {"next", "2,3,4", "1", "1"},
+ {"next", "3,4", "2", "2"},
+ {"prev", "2,3,4", "", "1"},
+ } {
+ st.press(t, want.op)
+ st.rig.Run(waitWaiting(strconv.Itoa(len(strings.Split(want.waiting, ",")))))
+ got := st.stage(t)
+ if !got.Same {
+ t.Fatalf("after %s the slide is a new node; a step applies in place", want.op)
+ }
+ if strings.Join(got.Waiting, ",") != want.waiting || strings.Join(got.Arriving, ",") != want.arriving || got.Step != want.step {
+ t.Errorf("after %s: waiting %v arriving %v step %q, want waiting %s arriving [%s] step %s",
+ want.op, got.Waiting, got.Arriving, got.Step, want.waiting, want.arriving, want.step)
+ }
+ }
+}
+
+// TestBackFromTheNextSlideLandsFullyBuilt: back from the slide after a
+// stepped one lands on it with every press shown, and nothing arriving;
+// Back again, from the projector's own button, steps back in place.
+func TestBackFromTheNextSlideLandsFullyBuilt(t *testing.T) {
+ st := newStepsTalk(t)
+ st.rig.Run(
+ chromedp.Navigate(st.rig.Origin+"/p/"+st.session+"?t="+url.QueryEscape(st.token)),
+ chromedp.WaitVisible(`[slides-stage] [slides-slide]`, chromedp.ByQuery),
+ waitWaiting("4"),
+ chromedp.Evaluate(markSection, nil),
+ // The projector's own Next, on the page as it loaded: a step,
+ // in place.
+ chromedp.Click(`[slides-bar] button[slides-op="next"]`, chromedp.ByQuery),
+ waitWaiting("3"),
+ )
+ if got := st.stage(t); !got.Same || strings.Join(got.Arriving, ",") != "1" || got.Step != "1" {
+ t.Fatalf("Next on the loaded projector: same node %v, arriving %v, step %q, want press 1 arriving in place at step 1",
+ got.Same, got.Arriving, got.Step)
+ }
+ for range 4 {
+ st.press(t, "next")
+ }
+ st.rig.Run(
+ waitFor(`document.querySelector('[slides-surface]').getAttribute('data-slide') === '2'`),
+ chromedp.KeyEvent(kb.ArrowLeft),
+ waitFor(`document.querySelector('[slides-surface]').getAttribute('data-slide') === '1'`),
+ )
+ got := st.stage(t)
+ if len(got.Waiting) != 0 || len(got.Arriving) != 0 || got.Step != "4" {
+ t.Fatalf("back onto the stepped slide: waiting %v arriving %v step %q, want it built (step 4) with nothing arriving",
+ got.Waiting, got.Arriving, got.Step)
+ }
+
+ st.rig.Run(
+ chromedp.Evaluate(markSection, nil),
+ chromedp.Click(`[slides-bar] button[slides-op="prev"]`, chromedp.ByQuery),
+ waitWaiting("1"),
+ )
+ got = st.stage(t)
+ if !got.Same || strings.Join(got.Waiting, ",") != "4" || len(got.Arriving) != 0 || got.Step != "3" {
+ t.Errorf("Back within the slide: same node %v, waiting %v arriving %v step %q, want the same node at step 3 with 4 waiting and nothing arriving",
+ got.Same, got.Waiting, got.Arriving, got.Step)
+ }
+}
+
+// TestReducedMotionAppears: with the deck set to fade, what arrives
+// fades and is unmarked once it has; with reduced motion asked for it
+// simply appears.
+func TestReducedMotionAppears(t *testing.T) {
+ st := newStepsTalk(t)
+ token := mintAgent(t, st.app, st.cookies, "arrive")
+ apiJSON(t, st.app, http.MethodPost, "/api/v1/decks/"+strings.TrimPrefix(st.deck, "/d/")+"/ops", token,
+ `{"ops":[{"op":"set_meta","arrive":"fade"}]}`, http.StatusOK)
+ share := mintShareLink(t, st.app, st.deck, st.cookies)
+
+ // Each element as it is marked arriving: its animation, opacity and
+ // visibility at that moment.
+ const watch = `(() => {
+ window.__seen = [];
+ if (window.__watch) window.__watch.disconnect();
+ (window.__watch = new MutationObserver(ms => {
+ for (const m of ms) {
+ if (!m.target.hasAttribute('data-arriving')) continue;
+ const cs = getComputedStyle(m.target);
+ window.__seen.push({press: m.target.dataset.press, animation: cs.animationName, opacity: cs.opacity, visibility: cs.visibility});
+ }
+ })).observe(document.querySelector('[slides-stage]'), {attributes: true, subtree: true, attributeFilter: ['data-arriving']});
+ return true;
+ })()`
+ type seen struct{ Press, Animation, Opacity, Visibility string }
+ read := func() []seen {
+ var raw string
+ st.rig.Run(chromedp.Evaluate(`JSON.stringify(window.__seen)`, &raw))
+ var out []seen
+ if err := json.Unmarshal([]byte(raw), &out); err != nil {
+ t.Fatalf("read what arrived: %v\n%s", err, raw)
+ }
+ return out
+ }
+
+ st.rig.Run(
+ chromedp.Navigate(st.rig.Origin+"/s/"+share+"?follow=1"),
+ chromedp.WaitVisible(`[slides-stage] [slides-slide][data-arrive="fade"]`, chromedp.ByQuery),
+ waitWaiting("4"),
+ chromedp.Evaluate(watch, nil),
+ )
+ st.press(t, "next")
+ st.rig.Run(
+ waitWaiting("3"),
+ waitFor(`!document.querySelector('[slides-stage] [data-arriving]')`),
+ )
+ if got := read(); len(got) != 1 || got[0].Press != "1" || got[0].Animation != "slides-arrive-fade" {
+ t.Fatalf("with motion allowed, press 1 arrived as %+v, want it alone, fading", got)
+ }
+
+ st.rig.Run(
+ chromedp.ActionFunc(func(ctx context.Context) error {
+ return emulation.SetEmulatedMedia().WithFeatures([]*emulation.MediaFeature{
+ {Name: "prefers-reduced-motion", Value: "reduce"},
+ }).Do(ctx)
+ }),
+ chromedp.Evaluate(watch, nil),
+ )
+ st.press(t, "next")
+ st.rig.Run(waitWaiting("2"))
+ got := read()
+ if len(got) != 1 || got[0].Press != "2" || got[0].Animation != "none" || got[0].Opacity != "1" || got[0].Visibility != "visible" {
+ t.Errorf("with reduced motion, press 2 arrived as %+v, want it shown at once with no animation", got)
+ }
+}
diff --git a/internal/slidestest/present_steps_test.go b/internal/slidestest/present_steps_test.go
new file mode 100644
index 0000000..331361a
--- /dev/null
+++ b/internal/slidestest/present_steps_test.go
@@ -0,0 +1,218 @@
+package slidestest
+
+import (
+ "net/http"
+ "net/http/httptest"
+ "net/url"
+ "regexp"
+ "strconv"
+ "strings"
+ "testing"
+)
+
+// Steps on the three screens that show the talk as it stands: the
+// projector, the audience's follow view and the phone remote (Task 6).
+// stepsDeck's first slide, "steps", has four boxes, one per press.
+
+// controlForm is a rendered control form: its action and its fields.
+type controlForm struct {
+ action string
+ fields url.Values
+}
+
+var (
+ formBlock = regexp.MustCompile(`(?s)<form method="post" action="([^"]+)"[^>]*>(.*?)</form>`)
+ formInput = regexp.MustCompile(`<input type="hidden" name="([^"]+)" value="([^"]*)">`)
+ waitingBox = regexp.MustCompile(`<[^>]*\bdata-press="(\d+)"[^>]*\bdata-waiting\b[^>]*>`)
+ pressedBox = regexp.MustCompile(`\bdata-press="\d+"`)
+)
+
+// formFor finds the control form for op on a page.
+func formFor(t *testing.T, page, op string) controlForm {
+ t.Helper()
+ for _, m := range formBlock.FindAllStringSubmatch(page, -1) {
+ fields := url.Values{}
+ for _, in := range formInput.FindAllStringSubmatch(m[2], -1) {
+ fields.Set(in[1], strings.ReplaceAll(in[2], "&amp;", "&"))
+ }
+ if fields.Get("op") == op {
+ return controlForm{action: strings.ReplaceAll(m[1], "&amp;", "&"), fields: fields}
+ }
+ }
+ t.Fatalf("no %q form on the page:\n%s", op, page)
+ return controlForm{}
+}
+
+// submit posts a form as a browser with scripts off does: the fields
+// as rendered, the page it is on as the Referer.
+func submit(t *testing.T, a *testApp, f controlForm, referer string) *httptest.ResponseRecorder {
+ t.Helper()
+ req := httptest.NewRequest(http.MethodPost, f.action, strings.NewReader(f.fields.Encode()))
+ req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
+ req.Header.Set("Origin", testOrigin)
+ req.Header.Set("Sec-Fetch-Site", "same-origin")
+ req.Header.Set("Referer", testOrigin+referer)
+ rec := httptest.NewRecorder()
+ a.ServeHTTP(rec, req)
+ return rec
+}
+
+// landing is where a scriptless press sends the browser: same origin,
+// and carrying slide and step. It returns the path and query.
+func landing(t *testing.T, rec *httptest.ResponseRecorder) (string, url.Values) {
+ t.Helper()
+ if rec.Code != http.StatusSeeOther {
+ t.Fatalf("a scriptless press: status %d, want 303\n%s", rec.Code, rec.Body)
+ }
+ u, err := url.Parse(rec.Header().Get("Location"))
+ if err != nil {
+ t.Fatalf("the press's Location %q: %v", rec.Header().Get("Location"), err)
+ }
+ q := u.Query()
+ if q.Get("slide") == "" || q.Get("step") == "" {
+ t.Fatalf("a scriptless press redirected to %q, which says no slide and step", u)
+ }
+ return u.RequestURI(), q
+}
+
+// waitingPresses is the press numbers still waiting on a page.
+func waitingPresses(page string) []string {
+ var out []string
+ for _, m := range waitingBox.FindAllStringSubmatch(page, -1) {
+ out = append(out, m[1])
+ }
+ return out
+}
+
+// TestScriptlessPressWalksEveryStep: with scripts off, Next on the
+// projector is a form; each one posts, comes back to a page that says
+// which slide and step, and that page shows one press more, until the
+// slide is built and the next one takes the talk to the next slide.
+func TestScriptlessPressWalksEveryStep(t *testing.T) {
+ a := newApp(t)
+ cookies := signedIn(t, a, allowedAddress)
+ session, token := startPresenting(t, a, stepsDeck(t, a, cookies), cookies)
+
+ at := "/p/" + session + "?t=" + url.QueryEscape(token)
+ page := mustGet(t, a, at, http.StatusOK, nil).Body.String()
+ if got := waitingPresses(page); strings.Join(got, ",") != "1,2,3,4" {
+ t.Fatalf("the projector at the start: waiting presses %v, want 1,2,3,4", got)
+ }
+ if !strings.Contains(page, `slides-op="next">Next<`) || !strings.Contains(page, `slides-op="prev">Back<`) {
+ t.Errorf("the projector's press buttons are not called Next and Back:\n%s", page)
+ }
+ for step := 1; step <= 4; step++ {
+ next, q := landing(t, submit(t, a, formFor(t, page, "next"), at))
+ if q.Get("slide") != "1" || q.Get("step") != strconv.Itoa(step) {
+ t.Fatalf("next %d landed on slide %s step %s, want slide 1 step %d", step, q.Get("slide"), q.Get("step"), step)
+ }
+ at = next
+ page = mustGet(t, a, at, http.StatusOK, nil).Body.String()
+ if got := waitingPresses(page); len(got) != 4-step {
+ t.Fatalf("after %d presses %d boxes wait (%v), want %d", step, len(got), got, 4-step)
+ }
+ if !strings.Contains(page, `data-step="`+strconv.Itoa(step)+`"`) {
+ t.Errorf("after %d presses the surface does not say data-step=%q", step, strconv.Itoa(step))
+ }
+ }
+ next, q := landing(t, submit(t, a, formFor(t, page, "next"), at))
+ if q.Get("slide") != "2" || q.Get("step") != "0" {
+ t.Fatalf("the fifth next landed on slide %s step %s, want slide 2 step 0", q.Get("slide"), q.Get("step"))
+ }
+ page = mustGet(t, a, next, http.StatusOK, nil).Body.String()
+ if !strings.Contains(page, `data-slide="2"`) || !strings.Contains(page, `data-id="plain"`) {
+ t.Fatalf("the fifth next did not show the next slide:\n%s", page)
+ }
+ // The counter counts through the talk being given: the short one
+ // has steps, plain and last.
+ if !strings.Contains(page, "2 / 3") {
+ t.Errorf("the counter on the second slide of a three-slide talk does not say 2 / 3:\n%s", page)
+ }
+}
+
+// TestAResubmittedPressCountsOnce: the same form posted twice (a reload
+// that resubmits, a double click with scripts off) is one press.
+func TestAResubmittedPressCountsOnce(t *testing.T) {
+ a := newApp(t)
+ cookies := signedIn(t, a, allowedAddress)
+ session, token := startPresenting(t, a, stepsDeck(t, a, cookies), cookies)
+
+ at := "/p/" + session + "?t=" + url.QueryEscape(token)
+ form := formFor(t, mustGet(t, a, at, http.StatusOK, nil).Body.String(), "next")
+ first, _ := landing(t, submit(t, a, form, at))
+ again, _ := landing(t, submit(t, a, form, at))
+ if _, step, _ := rowPosition(t, a, session); step != 1 {
+ t.Errorf("one press sent twice left the talk at step %d, want 1", step)
+ }
+ if first != again {
+ t.Errorf("the resubmitted press landed on %q, the first on %q", again, first)
+ }
+}
+
+// TestFollowDrawsTheCurrentStep: the audience's follow view draws the
+// talk at its step, not the finished slide, and ?slide=N&step=k draws
+// that state, its fragment included.
+func TestFollowDrawsTheCurrentStep(t *testing.T) {
+ a := newApp(t)
+ cookies := signedIn(t, a, allowedAddress)
+ path := stepsDeck(t, a, cookies)
+ session, token := startPresenting(t, a, path, cookies)
+ share := mintShareLink(t, a, path, cookies)
+
+ press(t, a, session, token, op(t, "next"), nil)
+ press(t, a, session, token, op(t, "next"), nil)
+
+ follow := mustGet(t, a, "/s/"+share+"?follow=1", http.StatusOK, nil).Body.String()
+ if got := waitingPresses(follow); strings.Join(got, ",") != "3,4" {
+ t.Errorf("the follow view at step 2 has presses %v waiting, want 3,4", got)
+ }
+ if !strings.Contains(follow, `data-step="2"`) {
+ t.Errorf("the follow view's surface does not say data-step=\"2\"")
+ }
+
+ named := mustGet(t, a, "/s/"+share+"?follow=1&slide=1&step=3", http.StatusOK, nil).Body.String()
+ if got := waitingPresses(named); strings.Join(got, ",") != "4" {
+ t.Errorf("?slide=1&step=3 has presses %v waiting, want 4", got)
+ }
+ fragment := mustGet(t, a, "/s/"+share+"?follow=1&slide=1&step=1&fragment=1", http.StatusOK, nil).Body.String()
+ if got := waitingPresses(fragment); strings.Join(got, ",") != "2,3,4" {
+ t.Errorf("the fragment at step 1 has presses %v waiting, want 2,3,4", got)
+ }
+ // A step past the slide's presses is the finished slide, still
+ // marked with its presses so a step back can apply in place.
+ over := mustGet(t, a, "/s/"+share+"?follow=1&slide=1&step=99", http.StatusOK, nil).Body.String()
+ if got := waitingPresses(over); len(got) != 0 || len(pressedBox.FindAllString(over, -1)) != 4 {
+ t.Errorf("step 99 has %v waiting and %d marked presses, want none waiting and 4 marked", got, len(pressedBox.FindAllString(over, -1)))
+ }
+}
+
+// TestRemoteSaysWhichStep: the phone says which step under where the
+// talk is, on a slide with presses only; its picture stays the
+// finished slide (P3).
+func TestRemoteSaysWhichStep(t *testing.T) {
+ a := newApp(t)
+ cookies := signedIn(t, a, allowedAddress)
+ session, token := startPresenting(t, a, stepsDeck(t, a, cookies), cookies)
+ remote := "/p/" + session + "/remote?t=" + url.QueryEscape(token)
+
+ press(t, a, session, token, op(t, "next"), nil)
+ press(t, a, session, token, op(t, "next"), nil)
+ page := mustGet(t, a, remote, http.StatusOK, nil).Body.String()
+ if !strings.Contains(page, "step 2 of 4") {
+ t.Errorf("the remote at step 2 of the steps slide does not say step 2 of 4:\n%s", page)
+ }
+ if !strings.Contains(page, `slides-op="next">Next<`) || !strings.Contains(page, `slides-op="prev">Back<`) {
+ t.Errorf("the remote's press buttons are not called Next and Back:\n%s", page)
+ }
+
+ for range 3 {
+ press(t, a, session, token, op(t, "next"), nil)
+ }
+ page = mustGet(t, a, remote, http.StatusOK, nil).Body.String()
+ if !strings.Contains(page, `data-slide="2"`) {
+ t.Fatalf("five presses did not reach the plain slide:\n%s", page)
+ }
+ if strings.Contains(page, "step ") {
+ t.Errorf("the remote names a step on a slide with no presses:\n%s", page)
+ }
+}
diff --git a/internal/slidestest/present_test.go b/internal/slidestest/present_test.go
index 44ab895..c69115f 100644
--- a/internal/slidestest/present_test.go
+++ b/internal/slidestest/present_test.go
@@ -233,14 +233,16 @@ func TestRemoteCommandAdvancesSlideAndPublishes(t *testing.T) {
t.Errorf("after next the event is %q, want slide 2", data)
}
- // A browser form submission goes back where it came from.
+ // A browser form submission goes back where it came from, saying
+ // the slide and step the press reached (Task 6).
back := testOrigin + "/p/" + session + "/remote?t=" + token
rec = command(t, a, session, "next", token, back, nil)
if rec.Code != http.StatusSeeOther {
t.Fatalf("POST command from a page: status %d, want 303\n%s", rec.Code, rec.Body)
}
- if loc := rec.Header().Get("Location"); loc != back {
- t.Errorf("the command redirected to %q, want %q", loc, back)
+ want := testOrigin + "/p/" + session + "/remote?slide=3&step=0&t=" + token
+ if loc := rec.Header().Get("Location"); loc != want {
+ t.Errorf("the command redirected to %q, want %q", loc, want)
}
if data := nextSlideEvent(t, events); !strings.Contains(data, `"slide":3`) {
t.Errorf("after a second next the event is %q, want slide 3", data)