| 1 | package slidestest |
| 2 | |
| 3 | import ( |
| 4 | "encoding/json" |
| 5 | "testing" |
| 6 | ) |
| 7 | |
| 8 | // The talk carries the deck's uploaded fonts as the font manifest does, |
| 9 | // under the session, so a presenter or slide window that holds it learns |
| 10 | // a font the deck took on after it opened (final review, I6). |
| 11 | func TestTheTalkCarriesTheDecksUploadedFonts(t *testing.T) { |
| 12 | a, _ := newFontsApp(t) |
| 13 | cookies := signedIn(t, a, allowedAddress) |
| 14 | token := mintAgent(t, a, cookies, "claude") |
| 15 | sqid := apiDeck(t, a, token, "Talk") |
| 16 | brand := brandFont(t, "LiberationSerif-Regular.ttf", "Brand") |
| 17 | uploadFonts(t, a, cookies, upFile{"brand.ttf", brand}) |
| 18 | session, _ := startPresenting(t, a, "/d/"+sqid, cookies) |
| 19 | |
| 20 | var before struct { |
| 21 | Uploaded map[string]any `json:"uploaded"` |
| 22 | } |
| 23 | json.Unmarshal(talkRequest(a, session, "", "", cookies).Body.Bytes(), &before) |
| 24 | if before.Uploaded != nil { |
| 25 | t.Errorf("a deck with no fonts of its own: uploaded %v", before.Uploaded) |
| 26 | } |
| 27 | |
| 28 | useFamily(t, a, token, sqid, pickedFamily(t, a, sqid, "Brand", cookies)) |
| 29 | var after struct { |
| 30 | Uploaded map[string]struct { |
| 31 | CSS string `json:"css"` |
| 32 | Faces []struct { |
| 33 | URL string `json:"url"` |
| 34 | Format string `json:"format"` |
| 35 | Weight any `json:"weight"` |
| 36 | Style string `json:"style"` |
| 37 | } `json:"faces"` |
| 38 | } `json:"uploaded"` |
| 39 | } |
| 40 | rec := talkRequest(a, session, "", "", cookies) |
| 41 | if err := json.Unmarshal(rec.Body.Bytes(), &after); err != nil { |
| 42 | t.Fatal(err) |
| 43 | } |
| 44 | fam, ok := after.Uploaded["u:Brand"] |
| 45 | if !ok || fam.CSS != "Brand" || len(fam.Faces) != 1 { |
| 46 | t.Fatalf("the talk's uploaded fonts: %s", rec.Body.String()[:min(400, rec.Body.Len())]) |
| 47 | } |
| 48 | if f := fam.Faces[0]; f.URL != "/p/"+session+"/fonts/"+sha(brand) || f.Format != "truetype" || f.Style != "normal" { |
| 49 | t.Errorf("the face is %+v", f) |
| 50 | } |
| 51 | } |
| 52 | |