package slidestest
import (
"net/http"
"os"
"path/filepath"
"regexp"
"strings"
"testing"
)
// The editor, tidied (docs/superpowers/specs/2026-11-16-editor-tidy-design.md).
// deskLink is estilo's desk part as the layout links it: fingerprinted,
// under static/estilo/.
var deskLink = regexp.MustCompile(`/static/estilo/desk\.[0-9a-f]{16}\.css`)
// TestEditorTidyServesEstiloDesk: estilo's desk part is served beside
// its chrome, and the editor and the deck list both link it, so the
// grey under a deck is estilo's token and not a copy of it.
func TestEditorTidyServesEstiloDesk(t *testing.T) {
a := newApp(t)
css := mustGet(t, a, "/static/estilo/desk.css", http.StatusOK, nil).Body.String()
if !strings.Contains(css, "--estilo-desk:") {
t.Errorf("/static/estilo/desk.css defines no --estilo-desk:\n%s", css)
}
cookies := signedIn(t, a, allowedAddress)
path := sampleDeck(t, a, cookies)
for _, page := range []string{"/", path + "/edit"} {
body := mustGet(t, a, page, http.StatusOK, cookies).Body.String()
link := deskLink.FindString(body)
if link == "" {
t.Errorf("GET %s links no estilo desk.css:\n%s", page, body)
continue
}
if got := mustGet(t, a, link, http.StatusOK, nil).Body.String(); got != css {
t.Errorf("GET %s: %s is not the desk.css served unfingerprinted", page, link)
}
chrome := regexp.MustCompile(`/static/estilo/chrome\.[0-9a-f]{16}\.css`).FindStringIndex(body)
if chrome == nil || strings.Index(body, link) < chrome[1] {
t.Errorf("GET %s: desk.css is not linked after chrome.css", page)
}
}
}
// TestEditorTidyDeskIsEstilos: Slides' desk is estilo's grey, Docs'
// own, not Slides' warm grey; and the deck list sits on that same desk,
// with no wash of colour over it.
func TestEditorTidyDeskIsEstilos(t *testing.T) {
desk := readStatic(t, "desk.css")
if !strings.Contains(desk, "var(--estilo-desk)") {
t.Error("static/desk.css does not read var(--estilo-desk)")
}
if strings.Contains(desk, "#ebe7e2") {
t.Error("static/desk.css still carries Slides' warm grey #ebe7e2")
}
decks := readStatic(t, "decks.css")
rule := regexp.MustCompile(`body:has\(\[slides-decks\]\)\s*\{[^}]*\}`).FindString(decks)
if rule == "" {
t.Fatal("static/decks.css has no body:has([slides-decks]) rule")
}
if strings.Contains(rule, "gradient") {
t.Errorf("the deck list's ground still has a gradient:\n%s", rule)
}
if !strings.Contains(rule, "var(--slides-desk)") {
t.Errorf("the deck list's ground does not read var(--slides-desk):\n%s", rule)
}
}
func readStatic(t *testing.T, name string) string {
t.Helper()
b, err := os.ReadFile(filepath.Join("..", "slides", "static", name))
if err != nil {
t.Fatal(err)
}
return string(b)
}
// TestEditorTidyViewSwitchIsThreeIconRadios (spec §3): the view switch
// is still three radios named slides-view, each inside an estilo-seg
// item label with an accessible name, a tooltip and an icon.
func TestEditorTidyViewSwitchIsThreeIconRadios(t *testing.T) {
a := newApp(t)
cookies := signedIn(t, a, allowedAddress)
page := mustGet(t, a, deckWithSlides(t, a, cookies, 2), http.StatusOK, cookies).Body.String()
if n := strings.Count(page, `name="slides-view"`); n != 3 {
t.Fatalf("the editor has %d name=\"slides-view\" radios, want 3", n)
}
set := regexp.MustCompile(`(?s)