package theme import ( "os" "os/exec" "path/filepath" "strings" "testing" ) const allSections = `--- title: Everything description: Every section type. sections: - type: hero eyebrow: New title: "One **bill** for everything" subhead: The apps your team needs. ctas: - { label: Start, url: /start/, style: primary } - { label: Learn, url: "#more", style: ghost } log: - { tag: App, text: Read 14 tickets } - { think: true, text: Checking } - { done: true } - type: text kicker: Why headline: Because body: "It's **simple**." - type: features headline: Features items: [{ label: Fast, body: Very }, { label: Private, body: Yours }] - type: cards columns: 2 items: [{ label: A, title: Card one, body: Text, link: /a/, linktext: Read }, { title: Card two, body: More, visual: true }] - type: steps items: [{ title: Sign up, body: Two minutes }, { title: Move in, body: We help }] - type: checklist items: ["Email", "Files"] - type: split columns: [{ title: Before, items: [Bills] }, { title: After, items: [One bill] }] - type: stats items: [{ value: "80%", label: saved }, { value: "24/7", label: support }] - type: table headers: [Them, Us] rows: [{ label: Price, cells: ["$50", "$5"] }] - type: faq items: [{ q: Is it safe?, a: "Yes." }] - type: callout text: A note. - type: form headline: Ask us subject: Contact fields: [{ name: name, label: Name, required: true }, { name: email, label: Email, type: email, required: true }] - type: nonsense title: An unknown type is skipped - type: final-cta headline: Ready? ctas: [{ label: Go, url: /go/ }] --- ` func TestThemeBuilds(t *testing.T) { hugo, err := exec.LookPath("hugo") if err != nil { t.Skip("no hugo") } site := t.TempDir() for p, body := range Files() { full := filepath.Join(site, Dir, p) os.MkdirAll(filepath.Dir(full), 0o755) os.WriteFile(full, []byte(body), 0o644) } cfg := `baseURL = "https://acme.example/" title = "Acme" theme = "supermarket" disableKinds = ["taxonomy", "term", "RSS"] [params] tagline = "Widgets for everyone" [params.brand] primary = "#ff6600" accent = "#0055ff" font = "IBM Plex Sans" [params.header] ctas = [{ label = "Get started", url = "/start/", style = "primary" }] [params.footer] groups = [{ title = "Company", menu = "footer_company" }] [params.leads] action = "https://crm.example/api/v1/LeadCapture/k" [[menu.main]] name = "Pricing" url = "/pricing/" [[menu.footer_company]] name = "About" url = "/about/" ` os.WriteFile(filepath.Join(site, "hugo.toml"), []byte(cfg), 0o644) os.MkdirAll(filepath.Join(site, "content"), 0o755) os.WriteFile(filepath.Join(site, "content", "_index.md"), []byte(allSections), 0o644) os.WriteFile(filepath.Join(site, "content", "plain.md"), []byte("---\ntitle: Plain\n---\nJust **Markdown**.\n"), 0o644) out := filepath.Join(t.TempDir(), "public") cmd := exec.Command(hugo, "--quiet", "--destination", out) cmd.Dir = site if msg, err := cmd.CombinedOutput(); err != nil { t.Fatalf("hugo: %v\n%s", err, msg) } home, _ := os.ReadFile(filepath.Join(out, "index.html")) h := string(home) for _, want := range []string{ "Acme — Widgets for everyone", "--lime: #ff6600", "--violet: #0055ff", `family=IBM%20Plex%20Sans:wght`, `--font: "IBM Plex Sans"`, `Acme`, ">Pricing<", ">Get started<", "One bill for everything", "Read 14 tickets", "section-features", "Card one", "section-steps", "section-checklist", "section-split", "section-stats", "section-table", "section-faq", "section-callout", "section-form", `action="https://crm.example/api/v1/LeadCapture/k"`, "window.leadPost", "supermarket-leads.js", "Ready?", ">About<", "© ", } { if !strings.Contains(h, want) { t.Errorf("home lacks %q", want) } } if strings.Contains(h, "An unknown type is skipped") || strings.Contains(h, "Federated") { t.Error("an unknown section, or Federated's own text, shows") } plain, _ := os.ReadFile(filepath.Join(out, "plain", "index.html")) if !strings.Contains(string(plain), "Just Markdown") { t.Errorf("plain page: %s", plain) } for _, f := range []string{"css/supermarket.css", "js/supermarket-leads.js", "404.html"} { if _, err := os.Stat(filepath.Join(out, f)); err != nil { t.Errorf("%s missing", f) } } } func TestFiles(t *testing.T) { fs := Files() if fs["VERSION"] != "1\n" || !strings.Contains(fs["README.md"], "| `hero` |") || !strings.Contains(LeadScript(), "window.leadPost") { t.Error("files") } for p := range fs { if strings.Contains(fs[p], "federated.computer") { t.Errorf("%s mentions federated.computer", p) } } }