oficina / slides Public

Clone
git clone https://amadan.net/oficina/slides

Plain git — no account needed to clone.

Download

Download this file

1package slidestest
2
3import (
4 "encoding/json"
5 "net/http"
6 "net/http/httptest"
7 "strings"
8 "testing"
9)
10
11// The Fonts page shows each family set in its own font (final review,
12// minor; the spec's "a sample line"): the family's own name, in a face
13// the page loads from a route that serves a library file to its owner
14// alone.
15func TestTheFontsPageShowsEachFamilyInItsOwnFont(t *testing.T) {
16 a, _ := newFontsApp(t)
17 mine := signedIn(t, a, allowedAddress)
18 theirs := signedIn(t, a, otherAddress)
19 regular := brandFont(t, "LiberationSerif-Regular.ttf", "Brand")
20 uploadFonts(t, a, mine, upFile{"brand.ttf", regular})
21
22 page := mustGet(t, a, "/fonts", http.StatusOK, mine).Body.String()
23 if !strings.Contains(page, "url(/fonts/files/"+sha(regular)+")") {
24 t.Errorf("the page loads no face of Brand from its library route")
25 }
26 if !strings.Contains(page, `slides-font-sample="1">Brand</span>`) {
27 t.Errorf("the page shows no sample of Brand set in it")
28 }
29
30 served(t, a, "/fonts/files/"+sha(regular), mine, regular)
31 refused(t, a, "/fonts/files/"+sha(regular), theirs)
32 refused(t, a, "/fonts/files/"+strings.Repeat("0", 64), mine)
33 refused(t, a, "/fonts/files/not-a-ref", mine)
34 if rec := get(t, a, "/fonts/files/"+sha(regular)); rec.Code == http.StatusOK {
35 t.Error("a library file was served to nobody in particular")
36 }
37}
38
39// Deck settings asks for the person's families again when the editor's
40// window comes back (final review, minor): GET /fonts as JSON, the same
41// list the fields were drawn with.
42func TestTheLibraryAnswersItsFamiliesAsJSON(t *testing.T) {
43 a, _ := newFontsApp(t)
44 mine := signedIn(t, a, allowedAddress)
45 theirs := signedIn(t, a, otherAddress)
46 uploadFonts(t, a, mine, upFile{"brand.ttf", brandFont(t, "LiberationSerif-Regular.ttf", "Brand")})
47 list := func(cookies []*http.Cookie) string {
48 req := httptest.NewRequest(http.MethodGet, "/fonts", nil)
49 req.Header.Set("Accept", "application/json")
50 for _, c := range cookies {
51 req.AddCookie(c)
52 }
53 rec := httptest.NewRecorder()
54 a.ServeHTTP(rec, req)
55 if rec.Code != http.StatusOK || !strings.HasPrefix(rec.Header().Get("Content-Type"), "application/json") {
56 t.Fatalf("GET /fonts as JSON: %d %q\n%s", rec.Code, rec.Header().Get("Content-Type"), rec.Body)
57 }
58 var v any
59 if err := json.Unmarshal(rec.Body.Bytes(), &v); err != nil {
60 t.Fatalf("not JSON: %v", err)
61 }
62 return strings.TrimSpace(rec.Body.String())
63 }
64 if got := list(mine); got != `[{"value":"Brand","label":"Brand"}]` {
65 t.Errorf("my families: %s", got)
66 }
67 if got := list(theirs); got != `[]` {
68 t.Errorf("someone with none: %s", got)
69 }
70}
71