package slidestest import ( "net/http" "net/url" "regexp" "strings" "testing" ) var ( presenterBundle = regexp.MustCompile(``) presentScript = regexp.MustCompile(`src="/static/present\.([0-9a-f]{16}\.)?js"`) ) // TestTheWindowsThatDriveHoldTheTalk: the presenter window and the // slide window of a session with a position, for whoever may drive it, // load the presenter bundle with the talk's address and every sentence // it draws from the catalog (Task 10). The follow link, a watcher, and a // session begun before positions keep static/present.js. func TestTheWindowsThatDriveHoldTheTalk(t *testing.T) { a := newApp(t) cookies := signedIn(t, a, allowedAddress) deck := stepsDeck(t, a, cookies) session, token := startPresenting(t, a, deck, cookies) talk := `data-talk="/p/` + session + `/talk` window := mustGet(t, a, "/p/"+session+"/notes?t="+url.QueryEscape(token), http.StatusOK, nil).Body.String() for _, want := range []string{ talk + `?t=`, `data-stream="/p/` + session + `/stream"`, `data-command="/p/` + session + `/command"`, `data-text-loading="Getting the talk ready: {n} of {total}"`, `data-text-loading-failed="{n} slides did not load. They will show when the network allows."`, `data-text-offline="Offline. This window still moves."`, `data-text-step="step {n} of {total}"`, ``, } { if !strings.Contains(window, want) { t.Errorf("the presenter window lacks %s", want) } } if !presenterBundle.MatchString(window) || presentScript.MatchString(window) { t.Error("the presenter window does not load the presenter bundle in place of present.js") } for _, c := range []struct { name string path string cookies []*http.Cookie bundle bool }{ {"the slide window with the token", "/p/" + session + "?t=" + url.QueryEscape(token), nil, true}, {"the slide window of the presenter signed in", "/p/" + session, cookies, true}, {"a watcher", "/p/" + session, nil, false}, } { page := mustGet(t, a, c.path, http.StatusOK, c.cookies).Body.String() if got := presenterBundle.MatchString(page); got != c.bundle { t.Errorf("%s: loads the presenter bundle %v, want %v", c.name, got, c.bundle) } if got := presentScript.MatchString(page); got == c.bundle { t.Errorf("%s: loads present.js %v", c.name, got) } if !c.bundle { if strings.Contains(page, "data-talk=") || strings.Contains(page, `slides-op="next"`) { t.Errorf("%s: may not drive, and holds the talk or a Next button", c.name) } continue } for _, want := range []string{talk, `data-text-waiting="Waiting for the network"`, `slides-op="next"`, `
`} { if !strings.Contains(page, want) { t.Errorf("%s: lacks %s", c.name, want) } } } share := mintShareLink(t, a, deck, cookies) if follow := mustGet(t, a, "/s/"+share+"?follow=1", http.StatusOK, nil).Body.String(); presenterBundle.MatchString(follow) { t.Error("the follow link loads the presenter bundle; it keeps present.js") } preDeploy(t, a, session) if old := mustGet(t, a, "/p/"+session+"?t="+url.QueryEscape(token), http.StatusOK, nil).Body.String(); presenterBundle.MatchString(old) { t.Error("a session begun before positions loads the presenter bundle; it keeps present.js") } }