oficina / sheets Public

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

Plain git — no account needed to clone.

Download

Download this file

1package sheets
2
3import (
4 "html"
5 "net/http"
6 "net/http/httptest"
7 "regexp"
8 "strings"
9 "testing"
10)
11
12// The sign-in page is the Oficina door (estilo chrome): a card on the
13// suite sky with this app's mark and name, its sky layers served signed
14// out by estilo's handler rather than shadowed by the app's /static/.
15func TestSignInPageIsTheDoor(t *testing.T) {
16 app := New(Config{})
17 GET := func(p string) *httptest.ResponseRecorder {
18 return do(t, app, httptest.NewRequest(http.MethodGet, p, nil))
19 }
20 rec := GET("/signin")
21 body := rec.Body.String()
22 for _, want := range []string{"estilo-door", "<span>Sheets</span>", `name="address"`, " autofocus"} {
23 if !strings.Contains(body, want) {
24 t.Errorf("sign-in page lacks %q", want)
25 }
26 }
27 if !regexp.MustCompile(`<img estilo-sky-layer="placeholder"[^>]*src="data:image/png;base64,`).MatchString(body) {
28 t.Error("sign-in page has no inline sky placeholder")
29 }
30 layer := regexp.MustCompile(`<img estilo-sky-layer="[a-z]+"[^>]*src="(/static/estilo/sky/v1/[^"]+)"`).FindStringSubmatch(body)
31 if layer == nil {
32 t.Fatal("sign-in page links no served sky layer")
33 }
34 if got := GET(layer[1]); got.Code != http.StatusOK || got.Header().Get("Content-Type") != "image/svg+xml" {
35 t.Errorf("GET %s signed out: %d %q, want 200 image/svg+xml", layer[1], got.Code, got.Header().Get("Content-Type"))
36 }
37 if !regexp.MustCompile(`/static/estilo/sky\.[0-9a-f]{16}\.css`).MatchString(body) {
38 t.Error("sign-in page does not link sky.css")
39 }
40}
41
42// The page between the door and Keymail is the door's notice, and still
43// carries Home's refresh to the destination.
44func TestKeymailContinuationIsTheDoor(t *testing.T) {
45 app := New(Config{})
46 const dest = "https://keymail.example.test/oauth/authorize?state=s"
47 rec := httptest.NewRecorder()
48 app.renderHomeOAuth(rec, httptest.NewRequest(http.MethodPost, "/signin", nil), dest)
49 body := html.UnescapeString(rec.Body.String())
50 for _, want := range []string{
51 `http-equiv="refresh"`, `content="0;url=` + dest + `"`, `href="` + dest + `"`,
52 "estilo-door", "estilo-sky-layer", "<span>Sheets</span>", "Taking you to Keymail",
53 } {
54 if !strings.Contains(body, want) {
55 t.Errorf("continuation lacks %q", want)
56 }
57 }
58}
59
60// The door's words are estilo's, not this app's (Paul, 2026-10-01: the
61// submit reads "Sign in", never "Email me a link"; 2026-09-23: the hub is
62// never named). Every state is pinned: the form, the sent state, and the
63// signed-out page in both modes, with their exact tab titles.
64func TestTheDoorSpeaksTheSuiteCopy(t *testing.T) {
65 app := New(Config{})
66 f := newHomeFixture(t)
67 for _, c := range []struct {
68 name, title string
69 body string
70 want []string
71 }{
72 {"form", "Sign in · Sheets", page(t, app, nil, "/signin").Body.String(), []string{
73 "<h1>Sign in</h1>", "Email address",
74 "We’ll email you a link that signs you in. It works once and expires in 15 minutes.",
75 `<button rst-btn="primary" type="submit">Sign in</button>`,
76 }},
77 {"sent", "Check your email · Sheets", page(t, app, nil, "/signin?sent=1").Body.String(), []string{
78 "<h1>Check your email</h1>",
79 "If that address can sign in here, we’ve sent it a link. It works once and expires in 15 minutes.",
80 `<a href="/signin">Use a different address</a>`,
81 }},
82 {"signed out", "Signed out · Sheets", page(t, app, nil, "/signed-out").Body.String(), []string{
83 "<h1>You’re signed out</h1>", "You’ve signed out of Sheets on this device.",
84 `<a rst-btn="primary" href="/signin">Sign in</a>`,
85 }},
86 {"signed out, Home configured", "Signed out · Sheets", f.request(t, "GET", "/signed-out", nil, false).Body.String(), []string{
87 "<h1>You’re signed out</h1>", "You’ve signed out of Sheets on this device.",
88 `<a rst-btn="primary" href="/signin">Sign in</a>`,
89 }},
90 } {
91 if got := titleOf(t, c.body); got != c.title {
92 t.Errorf("%s: <title> %q, want %q", c.name, got, c.title)
93 }
94 for _, want := range c.want {
95 if !strings.Contains(c.body, want) {
96 t.Errorf("%s lacks %s", c.name, want)
97 }
98 }
99 for _, never := range []string{"Email me a link", "with Home", "Home account"} {
100 if strings.Contains(c.body, never) {
101 t.Errorf("%s says %q", c.name, never)
102 }
103 }
104 }
105}
106