| 1 | package slidestest |
| 2 | |
| 3 | import ( |
| 4 | "bytes" |
| 5 | "net/http" |
| 6 | "regexp" |
| 7 | "strings" |
| 8 | "testing" |
| 9 | |
| 10 | "amadan.net/oficina/estilo.git/savestatus" |
| 11 | ) |
| 12 | |
| 13 | // TestEditorUsesEstiloSaveStatus: the editor's save line is estilo's |
| 14 | // savestatus — its markup with every state's words from this app's |
| 15 | // catalog, its CSS and its module served as fingerprinted assets — and |
| 16 | // the slide-load error keeps a line of its own, because savestatus has |
| 17 | // no state for it. The editor's own [slides-status] is gone. |
| 18 | func TestEditorUsesEstiloSaveStatus(t *testing.T) { |
| 19 | a := newApp(t) |
| 20 | cookies := signedIn(t, a, allowedAddress) |
| 21 | path := sampleDeck(t, a, cookies) |
| 22 | page := mustGet(t, a, path+"/edit", http.StatusOK, cookies).Body.String() |
| 23 | for _, want := range []string{ |
| 24 | `estilo-save-status="inline"`, |
| 25 | `data-state="saved"`, |
| 26 | `role="status"`, |
| 27 | `data-text-saved="Saved"`, |
| 28 | `data-text-saving="Saving…"`, |
| 29 | `data-text-retrying="Offline, retrying"`, |
| 30 | `data-text-failed="Some changes could not be saved. Reload to continue."`, |
| 31 | `<span slides-load-error role="status"`, |
| 32 | `data-text-error="`, |
| 33 | } { |
| 34 | if !strings.Contains(page, want) { |
| 35 | t.Errorf("the editor page lacks %s", want) |
| 36 | } |
| 37 | } |
| 38 | if strings.Contains(page, "slides-status") { |
| 39 | t.Error("the editor still carries its own [slides-status] line beside estilo's") |
| 40 | } |
| 41 | for _, asset := range []struct { |
| 42 | ext, contentType string |
| 43 | body []byte |
| 44 | }{{"css", "text/css", savestatus.CSS()}, {"mjs", "javascript", savestatus.JS()}} { |
| 45 | url := regexp.MustCompile(`/static/estilo/save-status\.[0-9a-f]{16}\.` + asset.ext).FindString(page) |
| 46 | if url == "" { |
| 47 | t.Errorf("the editor page links no fingerprinted save-status.%s", asset.ext) |
| 48 | continue |
| 49 | } |
| 50 | res := mustGet(t, a, url, http.StatusOK, nil) |
| 51 | if !bytes.Equal(res.Body.Bytes(), asset.body) { |
| 52 | t.Errorf("%s is not estilo's bytes", url) |
| 53 | } |
| 54 | if ct := res.Header().Get("Content-Type"); !strings.Contains(ct, asset.contentType) { |
| 55 | t.Errorf("%s answers Content-Type %q, want %s", url, ct, asset.contentType) |
| 56 | } |
| 57 | if !strings.Contains(res.Header().Get("Cache-Control"), "immutable") { |
| 58 | t.Errorf("%s is not served immutable", url) |
| 59 | } |
| 60 | } |
| 61 | } |
| 62 | |