| 1 | package sheets |
| 2 | |
| 3 | import ( |
| 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/. |
| 15 | func TestSignInPageIsTheDoor(t *testing.T) { |
| 16 | app, _ := appWithRecorder(t) |
| 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>", "<div estilo-signin-screen>", `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/v[0-9]+/[^"]+)"`).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 door's words are rastrillo's approved sign-in copy, and the |
| 43 | // signed-out page's estilo's (Paul, 2026-09-23: the hub is never named). |
| 44 | // Every state is pinned with its exact tab title: the door, the sent state, |
| 45 | // and the signed-out page in both modes, now with "Forget me on this |
| 46 | // device". |
| 47 | func TestTheDoorSpeaksTheSuiteCopy(t *testing.T) { |
| 48 | app, _ := appWithRecorder(t) |
| 49 | f := newHomeFixture(t) |
| 50 | for _, c := range []struct { |
| 51 | name, title string |
| 52 | body string |
| 53 | want []string |
| 54 | }{ |
| 55 | {"door", "Sign in to Sheets", page(t, app, nil, "/signin").Body.String(), []string{ |
| 56 | `<h1 id="rst-signin-heading">Sign in to Sheets</h1>`, ">Email</label>", ">Continue</button>", |
| 57 | }}, |
| 58 | {"sent", "Check your email to sign in to Sheets", page(t, app, nil, "/signin?sent=1").Body.String(), []string{ |
| 59 | "Check your email</h1>", "We sent a link to your inbox.", "The link works once and expires soon.", "Use a different email", |
| 60 | }}, |
| 61 | {"signed out", "Signed out · Sheets", page(t, app, nil, "/signed-out").Body.String(), []string{ |
| 62 | "<h1>You’re signed out</h1>", "You’ve signed out of Sheets on this device.", |
| 63 | `href="/signin">Sign in</a>`, ">Forget me on this device</button>", |
| 64 | }}, |
| 65 | {"signed out, Home configured", "Signed out · Sheets", f.request(t, "GET", "/signed-out", nil, false).Body.String(), []string{ |
| 66 | "<h1>You’re signed out</h1>", "You’ve signed out of Sheets on this device.", |
| 67 | `href="/signin">Sign in</a>`, ">Forget me on this device</button>", |
| 68 | }}, |
| 69 | } { |
| 70 | if got := html.UnescapeString(titleOf(t, c.body)); got != c.title { |
| 71 | t.Errorf("%s: <title> %q, want %q", c.name, got, c.title) |
| 72 | } |
| 73 | body := html.UnescapeString(c.body) |
| 74 | for _, want := range c.want { |
| 75 | if !strings.Contains(body, want) { |
| 76 | t.Errorf("%s lacks %s", c.name, want) |
| 77 | } |
| 78 | } |
| 79 | for _, never := range []string{"Email me a link", "with Home", "Home account", "We’ll email you a link"} { |
| 80 | if strings.Contains(body, never) { |
| 81 | t.Errorf("%s says %q", c.name, never) |
| 82 | } |
| 83 | } |
| 84 | } |
| 85 | } |
| 86 | |