| 1 | package slidestest |
| 2 | |
| 3 | import ( |
| 4 | "net/http" |
| 5 | "net/http/httptest" |
| 6 | "regexp" |
| 7 | "strings" |
| 8 | "testing" |
| 9 | ) |
| 10 | |
| 11 | // The sign-in page is the Oficina door (estilo chrome): a card on the |
| 12 | // suite sky with this app's mark and name, its sky layers served signed |
| 13 | // out by estilo's handler rather than shadowed by the app's /static/. |
| 14 | func TestSignInPageIsTheDoor(t *testing.T) { |
| 15 | h := newApp(t) |
| 16 | GET := func(p string) *httptest.ResponseRecorder { return get(t, h, p) } |
| 17 | rec := GET("/signin") |
| 18 | body := rec.Body.String() |
| 19 | for _, want := range []string{"estilo-door", "<span>Slides</span>", `name="address"`, " autofocus"} { |
| 20 | if !strings.Contains(body, want) { |
| 21 | t.Errorf("sign-in page lacks %q", want) |
| 22 | } |
| 23 | } |
| 24 | if !regexp.MustCompile(`<img estilo-sky-layer="placeholder"[^>]*src="data:image/png;base64,`).MatchString(body) { |
| 25 | t.Error("sign-in page has no inline sky placeholder") |
| 26 | } |
| 27 | layer := regexp.MustCompile(`<img estilo-sky-layer="[a-z]+"[^>]*src="(/static/estilo/sky/v1/[^"]+)"`).FindStringSubmatch(body) |
| 28 | if layer == nil { |
| 29 | t.Fatal("sign-in page links no served sky layer") |
| 30 | } |
| 31 | if got := GET(layer[1]); got.Code != http.StatusOK || got.Header().Get("Content-Type") != "image/svg+xml" { |
| 32 | t.Errorf("GET %s signed out: %d %q, want 200 image/svg+xml", layer[1], got.Code, got.Header().Get("Content-Type")) |
| 33 | } |
| 34 | if !regexp.MustCompile(`/static/estilo/sky\.[0-9a-f]{16}\.css`).MatchString(body) { |
| 35 | t.Error("sign-in page does not link sky.css") |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | // TestDoorCopyIsEstilos pins the door's words, which are estilo's, not |
| 40 | // this app's: the submit reads "Sign in" and never "Email me a link" |
| 41 | // (Paul, 2026-10-01), the hub is never named, and the three tab titles |
| 42 | // are "<Page> · Slides". |
| 43 | func TestDoorCopyIsEstilos(t *testing.T) { |
| 44 | h := newApp(t) |
| 45 | title := regexp.MustCompile(`<title>([^<]*)</title>`) |
| 46 | for _, tc := range []struct { |
| 47 | path, title string |
| 48 | want []string |
| 49 | }{ |
| 50 | {"/signin", "Sign in · Slides", []string{ |
| 51 | "Email address", |
| 52 | "We’ll email you a link that signs you in. It works once and expires in 15 minutes.", |
| 53 | ">Sign in</button>", |
| 54 | }}, |
| 55 | {"/signin?sent=1", "Check your email · Slides", []string{ |
| 56 | "Check your email", |
| 57 | "If that address can sign in here, we’ve sent it a link. It works once and expires in 15 minutes.", |
| 58 | ">Use a different address</a>", |
| 59 | }}, |
| 60 | {"/signed-out", "Signed out · Slides", []string{ |
| 61 | "You’re signed out", |
| 62 | "You’ve signed out of Slides on this device.", |
| 63 | `href="/signin"`, |
| 64 | }}, |
| 65 | } { |
| 66 | rec := get(t, h, tc.path) |
| 67 | body := rec.Body.String() |
| 68 | if rec.Code != http.StatusOK { |
| 69 | t.Fatalf("GET %s: %d", tc.path, rec.Code) |
| 70 | } |
| 71 | if m := title.FindStringSubmatch(body); m == nil || m[1] != tc.title { |
| 72 | t.Errorf("GET %s: title %v, want %q", tc.path, m, tc.title) |
| 73 | } |
| 74 | for _, w := range tc.want { |
| 75 | if !strings.Contains(body, w) { |
| 76 | t.Errorf("GET %s lacks %q", tc.path, w) |
| 77 | } |
| 78 | } |
| 79 | for _, bad := range []string{"Email me a link", "Home"} { |
| 80 | if strings.Contains(body, bad) { |
| 81 | t.Errorf("GET %s says %q", tc.path, bad) |
| 82 | } |
| 83 | } |
| 84 | } |
| 85 | } |
| 86 | |