| 1 | package slidestest |
| 2 | |
| 3 | import ( |
| 4 | "net/http" |
| 5 | "net/url" |
| 6 | "regexp" |
| 7 | "strings" |
| 8 | "testing" |
| 9 | ) |
| 10 | |
| 11 | var ( |
| 12 | presenterBundle = regexp.MustCompile(`<script type="module" src="/static/presenter\.[0-9a-f]{16}(\.[0-9a-f]{16})?\.js"></script>`) |
| 13 | presentScript = regexp.MustCompile(`src="/static/present\.([0-9a-f]{16}\.)?js"`) |
| 14 | ) |
| 15 | |
| 16 | // TestTheWindowsThatDriveHoldTheTalk: the presenter window and the |
| 17 | // slide window of a session with a position, for whoever may drive it, |
| 18 | // load the presenter bundle with the talk's address and every sentence |
| 19 | // it draws from the catalog (Task 10). The follow link, a watcher, and a |
| 20 | // session begun before positions keep static/present.js. |
| 21 | func TestTheWindowsThatDriveHoldTheTalk(t *testing.T) { |
| 22 | a := newApp(t) |
| 23 | cookies := signedIn(t, a, allowedAddress) |
| 24 | deck := stepsDeck(t, a, cookies) |
| 25 | session, token := startPresenting(t, a, deck, cookies) |
| 26 | talk := `data-talk="/p/` + session + `/talk` |
| 27 | |
| 28 | window := mustGet(t, a, "/p/"+session+"/notes?t="+url.QueryEscape(token), http.StatusOK, nil).Body.String() |
| 29 | for _, want := range []string{ |
| 30 | talk + `?t=`, |
| 31 | `data-stream="/p/` + session + `/stream"`, |
| 32 | `data-command="/p/` + session + `/command"`, |
| 33 | `data-text-loading="Getting the talk ready: {n} of {total}"`, |
| 34 | `data-text-loading-failed="{n} slides did not load. They will show when the network allows."`, |
| 35 | `data-text-offline="Offline. This window still moves."`, |
| 36 | `data-text-step="step {n} of {total}"`, |
| 37 | `<span presenter-status role="status"></span>`, |
| 38 | } { |
| 39 | if !strings.Contains(window, want) { |
| 40 | t.Errorf("the presenter window lacks %s", want) |
| 41 | } |
| 42 | } |
| 43 | if !presenterBundle.MatchString(window) || presentScript.MatchString(window) { |
| 44 | t.Error("the presenter window does not load the presenter bundle in place of present.js") |
| 45 | } |
| 46 | |
| 47 | for _, c := range []struct { |
| 48 | name string |
| 49 | path string |
| 50 | cookies []*http.Cookie |
| 51 | bundle bool |
| 52 | }{ |
| 53 | {"the slide window with the token", "/p/" + session + "?t=" + url.QueryEscape(token), nil, true}, |
| 54 | {"the slide window of the presenter signed in", "/p/" + session, cookies, true}, |
| 55 | {"a watcher", "/p/" + session, nil, false}, |
| 56 | } { |
| 57 | page := mustGet(t, a, c.path, http.StatusOK, c.cookies).Body.String() |
| 58 | if got := presenterBundle.MatchString(page); got != c.bundle { |
| 59 | t.Errorf("%s: loads the presenter bundle %v, want %v", c.name, got, c.bundle) |
| 60 | } |
| 61 | if got := presentScript.MatchString(page); got == c.bundle { |
| 62 | t.Errorf("%s: loads present.js %v", c.name, got) |
| 63 | } |
| 64 | if !c.bundle { |
| 65 | if strings.Contains(page, "data-talk=") || strings.Contains(page, `slides-op="next"`) { |
| 66 | t.Errorf("%s: may not drive, and holds the talk or a Next button", c.name) |
| 67 | } |
| 68 | continue |
| 69 | } |
| 70 | for _, want := range []string{talk, `data-text-waiting="Waiting for the network"`, `slides-op="next"`, `<p slides-waiting role="status" hidden></p>`} { |
| 71 | if !strings.Contains(page, want) { |
| 72 | t.Errorf("%s: lacks %s", c.name, want) |
| 73 | } |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | share := mintShareLink(t, a, deck, cookies) |
| 78 | if follow := mustGet(t, a, "/s/"+share+"?follow=1", http.StatusOK, nil).Body.String(); presenterBundle.MatchString(follow) { |
| 79 | t.Error("the follow link loads the presenter bundle; it keeps present.js") |
| 80 | } |
| 81 | |
| 82 | preDeploy(t, a, session) |
| 83 | if old := mustGet(t, a, "/p/"+session+"?t="+url.QueryEscape(token), http.StatusOK, nil).Body.String(); presenterBundle.MatchString(old) { |
| 84 | t.Error("a session begun before positions loads the presenter bundle; it keeps present.js") |
| 85 | } |
| 86 | } |
| 87 | |