layout_test.go
| 1 | package views |
| 2 | |
| 3 | import ( |
| 4 | "net/http/httptest" |
| 5 | "strings" |
| 6 | "testing" |
| 7 | |
| 8 | "hearthforge/internal/config" |
| 9 | |
| 10 | g "maragu.dev/gomponents" |
| 11 | ) |
| 12 | |
| 13 | func TestLayoutAnonymous(t *testing.T) { |
| 14 | cfg := &config.Config{OwnerDisplayName: "Admin"} |
| 15 | rec := httptest.NewRecorder() |
| 16 | Render(rec, 200, Layout(Page{Title: "Sign in", Cfg: cfg}, g.Text("body"))) |
| 17 | |
| 18 | body := rec.Body.String() |
| 19 | for _, want := range []string{ |
| 20 | "<!doctype html>", |
| 21 | "<title>Sign in — Hearthforge</title>", |
| 22 | `<link rel="stylesheet" href="/assets/code-theme.css?v=`, |
| 23 | `<a href="/login" class="btn btn-sm">Sign in</a>`, |
| 24 | } { |
| 25 | if !strings.Contains(body, want) { |
| 26 | t.Errorf("rendered page misses %q", want) |
| 27 | } |
| 28 | } |
| 29 | if ct := rec.Header().Get("Content-Type"); ct != "text/html; charset=utf-8" { |
| 30 | t.Errorf("content type = %q", ct) |
| 31 | } |
| 32 | } |
| 33 |