Guard shared error pages and estilo tokens
4 files changed,
+135
−3
internal/slides/static/editor.css+1 −1internal/slides/templates/present_notes.html+2 −2internal/slidestest/index_test.go+76 −0internal/slidestest/vendored_test.go+56 −0
CI passed — run details
diff --git a/internal/slides/static/editor.css b/internal/slides/static/editor.css| index 190f142..9fde166 100644 |
| --- a/internal/slides/static/editor.css |
| +++ b/internal/slides/static/editor.css |
| @@ -332,7 +332,7 @@ |
| margin: var(--rst-sp-1) 0 0; |
| } |
| [slides-asset-status][data-state="error"] { |
| - color: var(--rst-danger, var(--rst-text)); |
| + color: var(--rst-tone-negative-fg); |
| } |
| [slides-unused-assets] { |
| border: 0; |
diff --git a/internal/slides/templates/present_notes.html b/internal/slides/templates/present_notes.html| index b1517ce..8c7b1b8 100644 |
| --- a/internal/slides/templates/present_notes.html |
| +++ b/internal/slides/templates/present_notes.html |
| @@ -46,7 +46,7 @@ |
| gap: var(--rst-sp-3); |
| } |
| [slides-clock-now] { |
| - font-size: var(--rst-text-2xl); |
| + font-size: var(--rst-fs-lg); |
| font-variant-numeric: tabular-nums; |
| margin: 0; |
| } |
| @@ -71,7 +71,7 @@ |
| gap: var(--rst-sp-2); |
| } |
| [slides-code] { |
| - font-size: var(--rst-text-2xl); |
| + font-size: var(--rst-fs-lg); |
| letter-spacing: 0.25em; |
| margin: 0; |
| } |
diff --git a/internal/slidestest/index_test.go b/internal/slidestest/index_test.go| index 0ce1a20..7391c4f 100644 |
| --- a/internal/slidestest/index_test.go |
| +++ b/internal/slidestest/index_test.go |
| @@ -3,6 +3,8 @@ package slidestest |
| import ( |
| "net/http" |
| "net/http/httptest" |
| + "os" |
| + "path/filepath" |
| "regexp" |
| "strings" |
| "testing" |
| @@ -82,3 +84,77 @@ func TestErrorPageRendersFrameworkPartial(t *testing.T) { |
| t.Errorf("ErrorPage body missing the ref:\n%s", body) |
| } |
| } |
| + |
| +// Every page failure a browser can navigate to is rendered inside Slides' |
| +// layout and bar. A fetch that did not ask for HTML remains plain text; the |
| +// split is by Accept rather than by an accident of which route failed. |
| +func TestNavigableErrorsUseTheSharedErrorPage(t *testing.T) { |
| + a := newApp(t) |
| + signedIn := signedIn(t, a, allowedAddress) |
| + // The user row is created on the first guarded request; optional chrome |
| + // deliberately will not create it while merely resolving an error page. |
| + mustGet(t, a, "/", http.StatusOK, signedIn) |
| + type errorCase struct { |
| + name, path, title string |
| + cookies []*http.Cookie |
| + } |
| + for _, tc := range []errorCase{ |
| + {"unknown route, signed out", "/no/such/page", "Page not found · Slides", nil}, |
| + {"unknown route, signed in", "/no/such/page", "Page not found · Slides", signedIn}, |
| + {"post-only route, signed out", "/signout", "Page not found · Slides", nil}, |
| + {"post-only route, signed in", "/signout", "Page not found · Slides", signedIn}, |
| + {"missing deck", "/d/23456789ab", "Deck not available · Slides", signedIn}, |
| + {"missing share link", "/s/doesnotexist", "Deck not available · Slides", nil}, |
| + } { |
| + t.Run(tc.name, func(t *testing.T) { |
| + req := httptest.NewRequest(http.MethodGet, tc.path, nil) |
| + req.Header.Set("Accept", "text/html,application/xhtml+xml") |
| + for _, c := range tc.cookies { |
| + req.AddCookie(c) |
| + } |
| + rec := httptest.NewRecorder() |
| + a.ServeHTTP(rec, req) |
| + body := rec.Body.String() |
| + if rec.Code != http.StatusNotFound || !strings.HasPrefix(rec.Header().Get("Content-Type"), "text/html") { |
| + t.Fatalf("status %d, Content-Type %q; want HTML 404", rec.Code, rec.Header().Get("Content-Type")) |
| + } |
| + if title := regexp.MustCompile(`<title>([^<]*)</title>`).FindStringSubmatch(body); title == nil || title[1] != tc.title { |
| + t.Fatalf("title %v, want %q", title, tc.title) |
| + } |
| + if !strings.Contains(body, "<header estilo-bar") || !strings.Contains(body, "<div rst-error>") { |
| + t.Fatal("error is outside the shared layout and bar") |
| + } |
| + if account := strings.Contains(body, "<details estilo-account"); account != (tc.cookies != nil) { |
| + t.Fatalf("account menu present = %v, want %v", account, tc.cookies != nil) |
| + } |
| + }) |
| + } |
| + plain := get(t, a, "/no/such/page", signedIn...) |
| + if plain.Code != http.StatusNotFound || strings.HasPrefix(plain.Header().Get("Content-Type"), "text/html") || strings.Contains(plain.Body.String(), "<html") { |
| + t.Fatalf("non-HTML failure = %d %q, want plain 404", plain.Code, plain.Header().Get("Content-Type")) |
| + } |
| +} |
| + |
| +// The only callout vocabulary is estilo's real tones. A valued rst-callout |
| +// or the old rst-notice spelling looks plausible but receives no callout |
| +// treatment, so scan every authored template rather than waiting for a path |
| +// to happen to render one. |
| +func TestTemplatesUseOnlyCalloutTones(t *testing.T) { |
| + files, err := filepath.Glob(filepath.Join("..", "slides", "templates", "*.html")) |
| + if err != nil || len(files) == 0 { |
| + t.Fatal("find templates", err) |
| + } |
| + stripComments := regexp.MustCompile(`(?s)\{\{/\*.*?\*/\}\}`) |
| + for _, file := range files { |
| + body, err := os.ReadFile(file) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + source := stripComments.ReplaceAllString(string(body), "") |
| + for _, bad := range []string{"rst-notice", `rst-callout="`, `rst-tone="warn"`} { |
| + if strings.Contains(source, bad) { |
| + t.Errorf("%s uses %q", file, bad) |
| + } |
| + } |
| + } |
| +} |
diff --git a/internal/slidestest/vendored_test.go b/internal/slidestest/vendored_test.go| index d08acbd..2fdf046 100644 |
| --- a/internal/slidestest/vendored_test.go |
| +++ b/internal/slidestest/vendored_test.go |
| @@ -2,10 +2,14 @@ package slidestest |
| import ( |
| "bytes" |
| + "fmt" |
| "os" |
| "path/filepath" |
| + "regexp" |
| + "sort" |
| "testing" |
| + "amadan.net/oficina/estilo.git/theme" |
| "amadan.net/rastrillo/rastrillo/ui" |
| ) |
| @@ -52,3 +56,55 @@ func TestVendoredAssetsMatchTheLibrary(t *testing.T) { |
| } |
| } |
| } |
| + |
| +// TestEveryRastrilloTokenSlidesUsesExists makes a misspelled design token a |
| +// test failure instead of a browser falling back silently. The vocabulary is |
| +// the committed tokens.css; usages include both authored templates and CSS. |
| +func TestEveryRastrilloTokenSlidesUsesExists(t *testing.T) { |
| + declared := map[string]bool{} |
| + definitions := append(append([]byte{}, ui.TokensCSS()...), theme.CSS()...) |
| + for _, match := range regexp.MustCompile(`--(rst-[a-z0-9-]+)\s*:`).FindAllSubmatch(definitions, -1) { |
| + declared[string(match[1])] = true |
| + } |
| + if len(declared) == 0 { |
| + t.Fatal("tokens.css declares no --rst-* tokens") |
| + } |
| + files, err := filepath.Glob(filepath.Join("..", "slides", "templates", "*.html")) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + css, err := filepath.Glob(filepath.Join("..", "slides", "static", "*.css")) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + for _, file := range css { |
| + // tokens.css is rastrillo's vendored component implementation; |
| + // TestVendoredAssetsMatchTheLibrary pins it. This gate is for |
| + // Slides-authored CSS and inline template styles. |
| + if filepath.Base(file) != "tokens.css" { |
| + files = append(files, file) |
| + } |
| + } |
| + used := map[string]bool{} |
| + pattern := regexp.MustCompile(`var\(--(rst-[a-z0-9-]+)`) |
| + comments := regexp.MustCompile(`(?s)/\*.*?\*/`) |
| + for _, file := range files { |
| + body, err := os.ReadFile(file) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + for _, match := range pattern.FindAllSubmatch(comments.ReplaceAll(body, nil), -1) { |
| + used[string(match[1])] = true |
| + } |
| + } |
| + var missing []string |
| + for token := range used { |
| + if !declared[token] { |
| + missing = append(missing, token) |
| + } |
| + } |
| + sort.Strings(missing) |
| + for _, token := range missing { |
| + t.Error(fmt.Sprintf("Slides uses --%s, but tokens.css does not declare it", token)) |
| + } |
| +} |