package slidestest import ( "net/http" "net/http/httptest" "net/url" "regexp" "strings" "testing" ) // bundleLink finds the editor bundle's script tag on a page: the one // committed file under internal/slides/static, served through the // fingerprinted asset handler. var bundleLink = regexp.MustCompile(`/static/editor\.[0-9a-f]{16}(\.[0-9a-f]{16})?\.js`) // TestEditorPageLinksTheCommittedBundle: GET /d/{sqid}/edit is the one // screen that needs the bundle (spec §8), and the page carries // everything the bundle reads back — the deck, the seq, the current // slide, the person — as data rather than as script. The strip and the // stage are server-rendered too, so the first paint is right before a // byte of JS has run. func TestEditorPageLinksTheCommittedBundle(t *testing.T) { a := newApp(t) cookies := signedIn(t, a, allowedAddress) path := sampleDeck(t, a, cookies) sqid := strings.TrimPrefix(path, "/d/") page := mustGet(t, a, path+"/edit", http.StatusOK, cookies).Body.String() src := bundleLink.FindString(page) if src == "" { t.Fatalf("the editor page links no committed bundle:\n%s", page) } if !strings.Contains(page, `type="module"`) { t.Errorf("the bundle is an ES module and must be loaded as one:\n%s", page) } js := mustGet(t, a, src, http.StatusOK, nil) if ct := js.Header().Get("Content-Type"); !strings.HasPrefix(ct, "text/javascript") { t.Errorf("GET %s: Content-Type = %q, want text/javascript", src, ct) } if !strings.Contains(js.Header().Get("Cache-Control"), "immutable") { t.Errorf("GET %s: Cache-Control = %q, want immutable", src, js.Header().Get("Cache-Control")) } for _, css := range []string{"editor", "slides"} { if !regexp.MustCompile(`/static/` + css + `\.[0-9a-f]{16}\.css`).MatchString(page) { t.Errorf("the editor page links no fingerprinted %s.css:\n%s", css, page) } } for _, attr := range []string{ `data-deck="` + sqid + `"`, `data-seq="`, `data-slide="`, `data-client-name="`, `data-client-colour="`, } { if !strings.Contains(page, attr) { t.Errorf("the editor page carries no %s:\n%s", attr, page) } } if strings.Contains(page, `data-slide=""`) { t.Errorf("the sample deck has slides, so data-slide must name the first one:\n%s", page) } // The strip: one
  • per slide, each an of the server's SVG // of it (thumbs.go), the current one saying so in words. // The