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/v[0-9]+/[^"]+)"`).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, with this app's English catalog wired the way
48// cmd/docs/main.go wires it. The door itself is rastrillo's sign-in screen
49// (the smart door, Home spec 2026-11-19-smart-door.md), in its approved
50// copy: the email field's submit is "Continue", the tab title says what
51// the heading says, and Sent keeps "Use a different email". The signed-out
52// page is estilo's, with "Forget me on this device" under Sign in.
53func TestSignInDoorCopyIsTheSuites(t *testing.T) {
54 app, err := NewForTest(t)
55 if err != nil {
56 t.Fatal(err)
57 }
58 loc, err := rastrillo.NewLocales(Locales, DefaultLocale, Catalog, nil)
59 if err != nil {
60 t.Fatal(err)
61 }
62 h := loc.Middleware(app.Handler())
63 GET := func(p string) string {
64 req := httptest.NewRequest(http.MethodGet, DefaultOrigin+p, nil)
65 req.Header.Set("Accept", "text/html")
66 rec := httptest.NewRecorder()
67 h.ServeHTTP(rec, req)
68 if rec.Code != http.StatusOK {
69 t.Fatalf("GET %s: %d", p, rec.Code)
70 }
71 return rec.Body.String()
72 }
73 title := func(body string) string {
74 m := regexp.MustCompile(`<title>([^<]*)</title>`).FindStringSubmatch(body)
75 if m == nil {
76 return ""
77 }
78 return html.UnescapeString(m[1])
79 }
80 cases := []struct {
81 path, title string
82 want []string
83 }{
84 {"/signin", "Sign in to Docs", []string{
85 `<h1 id="rst-signin-heading">Sign in to Docs</h1>`,
86 `>Email</label>`,
87 `>Continue</button>`,
88 }},
89 {"/signin?sent=1", "Check your email to sign in to Docs", []string{
90 "We sent a link to your inbox. The link works once and expires soon.",
91 "<span>Use a different email</span>",
92 }},
93 {"/signed-out", "Signed out · Docs", []string{
94 "You’re signed out",
95 "You’ve signed out of Docs on this device.",
96 `href="/signin">Sign in</a>`,
97 `action="/signin/forget"`,
98 ">Forget me on this device</button>",
99 }},
100 }
101 // The refusal, in the app-problem slot (copy review #3, Paul).
102 if got, want := Catalog["docs.signin.error.refused"], "That email can’t sign in to Docs. Use a different email, or ask whoever runs this team to add it."; got != want {
103 t.Errorf("refusal = %q, want %q", got, want)
104 }
105 for _, c := range cases {
106 body := GET(c.path)
107 if got := title(body); got != c.title {
108 t.Errorf("%s: <title> = %q, want %q", c.path, got, c.title)
109 }
110 if strings.Contains(body, "Email me a link") {
111 t.Errorf("%s still says \"Email me a link\"", c.path)
112 }
113 for _, want := range c.want {
114 if !strings.Contains(html.UnescapeString(body), want) {
115 t.Errorf("%s lacks %q", c.path, want)
116 }
117 }
118 }
119}
120