oficina / docs Public

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

Plain git — no account needed to clone.

Download

Download this file

1package docs_test
2
3// Help → Fonts and Help → Colophon (Paul, 2026-10-26: "put that under
4// 'Help' ... and then link out to e.g. 'Colophon' where we list all of the
5// open source stuff we use, attribute it, and link out to attribution").
6// A direct App.Handler() call installs no locale middleware, so every
7// label below is its catalog key.
8
9import (
10 "html"
11 "net/http"
12 "strings"
13 "testing"
14
15 "github.com/carlosframework/docs/internal/docs"
16 "github.com/carlosframework/docs/internal/fonts"
17)
18
19func TestHelpOffersFontsAndTheColophon(t *testing.T) {
20 app, _ := docs.NewForTest(t)
21 alice := signInCookies(t, app, "alice@example.com")
22 body := getAccept(t, app, alice, "/").Body.String()
23 help := strings.Index(body, "docs.chrome.help")
24 signout := strings.LastIndex(body, "docs.signout.label")
25 if help < 0 || signout < help {
26 t.Fatal("the account menu has no Help group before Sign out")
27 }
28 group := body[help:signout]
29 fontsAt := strings.Index(group, `href="/help/fonts"`)
30 colophonAt := strings.Index(group, `href="/help/colophon"`)
31 if fontsAt < 0 || colophonAt < fontsAt || !strings.Contains(group, "docs.help.fonts") || !strings.Contains(group, "docs.help.colophon") {
32 t.Fatalf("Help does not offer Fonts, then Colophon:\n%s", group)
33 }
34 // The sign-in door does not link it (Paul, 2026-11-19: a Colophon
35 // link on the door "makes no sense at all"); it lives under Help.
36 door := getAccept(t, app, nil, "/signin").Body.String()
37 if strings.Contains(door, `href="/help/colophon"`) {
38 t.Error("the sign-in door links the Colophon")
39 }
40}
41
42// Every project Docs ships is on the page, under its section, with its
43// licence one link away; the list is the one internal/shipped generated.
44func TestTheColophonListsEverythingDocsShips(t *testing.T) {
45 app, _ := docs.NewForTest(t)
46 c := docs.Colophon()
47 n := c.Count()
48 if n["typefaces"] != 17 || n["go"] < 15 || n["javascript"] < 5 || n["rust"] < 20 || n["tools"] < 5 || n["icons"] != 1 {
49 t.Fatalf("the Colophon's sections are %v", n)
50 }
51 for _, who := range []struct {
52 name string
53 cookies func() []*http.Cookie
54 }{{"signed out", func() []*http.Cookie { return nil }}, {"signed in", func() []*http.Cookie { return signInCookies(t, app, "alice@example.com") }}} {
55 rec := getAccept(t, app, who.cookies(), "/help/colophon")
56 if rec.Code != http.StatusOK {
57 t.Fatalf("%s: GET /help/colophon = %d", who.name, rec.Code)
58 }
59 if rec.Header().Get("Cache-Control") != "no-store" || rec.Header().Get("Referrer-Policy") != "strict-origin" {
60 t.Errorf("%s: headers %v", who.name, rec.Header())
61 }
62 body := rec.Body.String()
63 for _, want := range []string{"<title>docs.colophon.title · docs.app.name</title>", "<h1>docs.colophon.title</h1>", "docs.colophon.intro", `/static/estilo/colophon`} {
64 if !strings.Contains(body, want) {
65 t.Errorf("%s: the page lost %q", who.name, want)
66 }
67 }
68 if strings.Contains(body, "estilo-colophon") == false || strings.Count(body, "estilo-colophon-entry") != n["total"] {
69 t.Errorf("%s: %d entries on the page, %d in the Colophon", who.name, strings.Count(body, "estilo-colophon-entry"), n["total"])
70 }
71 for _, s := range c.Sections {
72 for _, e := range s.Entries {
73 if !strings.Contains(body, `id="colophon-`+e.ID+`"`) || !strings.Contains(body, `href="/help/colophon/`+e.ID+`"`) || !strings.Contains(body, html.EscapeString(e.Usage)) {
74 t.Errorf("%s: %s is missing, or its licence link or usage note is", who.name, e.ID)
75 }
76 }
77 }
78 }
79 // The twins are in their blurbs.
80 for id, twin := range map[string]string{"carlito": "Calibri", "caladea": "Cambria", "liberation-sans": "Arial", "liberation-serif": "Times New Roman"} {
81 e, ok := c.Entry(id)
82 if !ok || !strings.Contains(e.Blurb+e.Usage, twin) {
83 t.Errorf("%s's entry does not say it matches %s", id, twin)
84 }
85 }
86}
87
88func TestEveryLicencePageCarriesItsText(t *testing.T) {
89 app, _ := docs.NewForTest(t)
90 c := docs.Colophon()
91 for _, s := range c.Sections {
92 for _, e := range s.Entries {
93 rec := getAccept(t, app, nil, "/help/colophon/"+e.ID)
94 if rec.Code != http.StatusOK {
95 t.Fatalf("GET /help/colophon/%s = %d", e.ID, rec.Code)
96 }
97 body := rec.Body.String()
98 if !strings.Contains(body, `href="/help/colophon#colophon-`+e.ID+`"`) {
99 t.Errorf("%s: no way back to its entry", e.ID)
100 }
101 for _, p := range e.Packages {
102 for _, notice := range p.Notices {
103 first := strings.TrimSpace(strings.SplitN(strings.TrimSpace(notice.Text), "\n", 2)[0])
104 if !strings.Contains(body, html.EscapeString(first)) {
105 t.Errorf("%s: %s's %s is not on its licence page", e.ID, p.Name, notice.Name)
106 }
107 }
108 }
109 }
110 }
111 for _, path := range []string{"/help/colophon/nothing-here", "/help/colophon/YJS", "/help/colophon/yjs/more"} {
112 if rec := getAccept(t, app, nil, path); rec.Code != http.StatusNotFound {
113 t.Errorf("GET %s = %d, want the 404 page", path, rec.Code)
114 }
115 }
116}
117
118// Help → Fonts explains the fonts that stand in for Word's, from the
119// manifest itself, so it cannot name a pair the font menu does not have.
120func TestTheFontsPageExplainsTheTwins(t *testing.T) {
121 app, _ := docs.NewForTest(t)
122 rec := getAccept(t, app, nil, "/help/fonts")
123 if rec.Code != http.StatusOK {
124 t.Fatalf("GET /help/fonts = %d", rec.Code)
125 }
126 body := rec.Body.String()
127 twins := 0
128 for _, f := range fonts.Families {
129 if f.Twin == "" {
130 continue
131 }
132 twins++
133 if f.Docx.Name != f.Twin {
134 t.Errorf("%s matches %s but Word export names it %s; the page says export uses the twin's name", f.Name, f.Twin, f.Docx.Name)
135 }
136 if !strings.Contains(body, "<th scope=\"row\">"+html.EscapeString(f.Name)+"</th><td>"+html.EscapeString(f.Twin)+"</td>") {
137 t.Errorf("the fonts page does not pair %s with %s", f.Name, f.Twin)
138 }
139 }
140 if twins < 2 {
141 t.Fatal("the manifest has fewer than two twins; the check is vacuous")
142 }
143 for _, want := range []string{"<h1>docs.help.fonts.title</h1>", "docs.help.fonts.word", "docs.help.fonts.default", "docs.help.fonts.export", `<th scope="col">docs.help.fonts.col.font</th>`, `<th scope="col">docs.help.fonts.col.twin</th>`, `href="/help/colophon#colophon-typefaces"`} {
144 if !strings.Contains(body, want) {
145 t.Errorf("the fonts page lost %q", want)
146 }
147 }
148}
149
150// The words a person reads on the fonts page, in English.
151func TestTheFontsPageCopy(t *testing.T) {
152 for key, want := range map[string]string{
153 "docs.help.fonts.title": "Fonts",
154 "docs.help.fonts.word": "Some of Docs’ fonts are drawn to the same measurements as fonts Microsoft ships with Office and Windows. Every letter takes the same space, so a document breaks its lines and pages in the same places in both.",
155 "docs.help.fonts.more": "Who made each font, and its license, is listed under",
156 "docs.help.fonts.colophon": "Typefaces in the colophon",
157 // Tools are what Docs is built with, not what it ships.
158 "docs.colophon.intro.exhaustive": "The list is made from what Docs is actually built from, so nothing is missing from it and nothing in it is out of date.",
159 "docs.help.fonts.col.font": "In Docs",
160 "docs.help.fonts.col.twin": "Same measurements as",
161 "docs.help.fonts.default": "New documents are in {font}, so they lay out as they would in Word in {twin}.",
162 // Docs has no Word export yet (internal/docx), so the page says
163 // what it will do rather than claiming it.
164 "docs.help.fonts.export": "Docs can’t export to Word yet. When it can, it will give each of these fonts the name of the one it matches, so Word sets the text in its own font and the layout holds.",
165 } {
166 if got := docs.Catalog[key]; got != want {
167 t.Errorf("%s = %q, want %q", key, got, want)
168 }
169 }
170}
171