oficina / docs Public

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

Plain git — no account needed to clone.

Download

Download this file

1package docs
2
3import (
4 "html"
5 "net/http"
6 "net/http/httptest"
7 "regexp"
8 "strings"
9 "testing"
10
11 "amadan.net/rastrillo/rastrillo"
12)
13
14// The sign-in page is the Oficina door (estilo chrome): a card on the
15// suite sky with this app's mark and name, its sky layers served signed
16// out by estilo's handler rather than shadowed by the app's /static/.
17func TestSignInPageIsTheDoor(t *testing.T) {
18 app, err := NewForTest(t)
19 if err != nil {
20 t.Fatal(err)
21 }
22 GET := func(p string) *httptest.ResponseRecorder {
23 return serve(app, httptest.NewRequest(http.MethodGet, p, nil))
24 }
25 rec := GET("/signin")
26 body := rec.Body.String()
27 for _, want := range []string{"estilo-door", "<span>Docs</span>", `name="address"`, " autofocus"} {
28 if !strings.Contains(body, want) {
29 t.Errorf("sign-in page lacks %q", want)
30 }
31 }
32 if !regexp.MustCompile(`<img estilo-sky-layer="placeholder"[^>]*src="data:image/png;base64,`).MatchString(body) {
33 t.Error("sign-in page has no inline sky placeholder")
34 }
35 layer := regexp.MustCompile(`<img estilo-sky-layer="[a-z]+"[^>]*src="(/static/estilo/sky/v1/[^"]+)"`).FindStringSubmatch(body)
36 if layer == nil {
37 t.Fatal("sign-in page links no served sky layer")
38 }
39 if got := GET(layer[1]); got.Code != http.StatusOK || got.Header().Get("Content-Type") != "image/svg+xml" {
40 t.Errorf("GET %s signed out: %d %q, want 200 image/svg+xml", layer[1], got.Code, got.Header().Get("Content-Type"))
41 }
42 if !regexp.MustCompile(`/static/estilo/sky\.[0-9a-f]{16}\.css`).MatchString(body) {
43 t.Error("sign-in page does not link sky.css")
44 }
45}
46
47// The door's words are the suite's, with this app's English catalog
48// wired the way cmd/docs/main.go wires it: the submit reads "Sign in"
49// (Paul, 2026-10-01, never "Email me a link"), the help and sent copy are
50// the door's one set, and the three tab titles are "<Page> · Docs".
51func TestSignInDoorCopyIsTheSuites(t *testing.T) {
52 app, err := NewForTest(t)
53 if err != nil {
54 t.Fatal(err)
55 }
56 loc, err := rastrillo.NewLocales(Locales, DefaultLocale, Catalog, nil)
57 if err != nil {
58 t.Fatal(err)
59 }
60 h := loc.Middleware(app.Handler())
61 GET := func(p string) string {
62 req := httptest.NewRequest(http.MethodGet, DefaultOrigin+p, nil)
63 req.Header.Set("Accept", "text/html")
64 rec := httptest.NewRecorder()
65 h.ServeHTTP(rec, req)
66 if rec.Code != http.StatusOK {
67 t.Fatalf("GET %s: %d", p, rec.Code)
68 }
69 return rec.Body.String()
70 }
71 title := func(body string) string {
72 m := regexp.MustCompile(`<title>([^<]*)</title>`).FindStringSubmatch(body)
73 if m == nil {
74 return ""
75 }
76 return html.UnescapeString(m[1])
77 }
78 cases := []struct {
79 path, title string
80 want []string
81 }{
82 {"/signin", "Sign in · Docs", []string{
83 `>Sign in</button>`,
84 "We’ll email you a link that signs you in. It works once and expires in 15 minutes.",
85 }},
86 {"/signin?sent=1", "Check your email · Docs", []string{
87 "If that address can sign in here, we’ve sent it a link. It works once and expires in 15 minutes.",
88 `>Use a different address</a>`,
89 }},
90 {"/signed-out", "Signed out · Docs", []string{
91 "You’re signed out",
92 "You’ve signed out of Docs on this device.",
93 `href="/signin">Sign in</a>`,
94 }},
95 }
96 for _, c := range cases {
97 body := GET(c.path)
98 if got := title(body); got != c.title {
99 t.Errorf("%s: <title> = %q, want %q", c.path, got, c.title)
100 }
101 if strings.Contains(body, "Email me a link") {
102 t.Errorf("%s still says \"Email me a link\"", c.path)
103 }
104 for _, want := range c.want {
105 if !strings.Contains(html.UnescapeString(body), want) {
106 t.Errorf("%s lacks %q", c.path, want)
107 }
108 }
109 }
110}
111