Files
member-console/internal/server/compose_test.go
T
cgalo5758 408fa6f5a6 Add page anatomy parts and UI quality gate
- Add shared ui_*.html parts (pageHeader, sectionHeader, statusBadge,
  emptyState) parsed into every template set
- Add anatomy lint rules with a shrinking allowlist and screen-coverage
  check
- Add make screens capture harness with contact sheets and baseline diff
- Compose member and FedWiki regions server-side so pages arrive
  complete
- Rebuild Domains and Integrations on the parts as pilots
2026-08-30 04:05:31 -05:00

50 lines
1.8 KiB
Go

package server
import (
"net/http"
"net/http/httptest"
"strings"
"testing"
)
// TestIncludeComposesInProcess pins page-anatomy "A page arrives complete":
// an Include dispatches through the router with the caller's context and
// an HX-Request header, returns the fragment on 200, and errors otherwise;
// IncludeOr turns the error into an inline notice, never a blank region.
func TestIncludeComposesInProcess(t *testing.T) {
mux := http.NewServeMux()
var seenHX, seenMethod string
mux.HandleFunc("GET /partials/ok", func(w http.ResponseWriter, r *http.Request) {
seenHX = r.Header.Get("HX-Request")
seenMethod = r.Method
_, _ = w.Write([]byte("<p>ok</p>"))
})
mux.HandleFunc("GET /partials/bad", func(w http.ResponseWriter, r *http.Request) {
http.Error(w, "boom", http.StatusInternalServerError)
})
inc := NewInclude(mux)
r := httptest.NewRequest(http.MethodPost, "/products", strings.NewReader("x=1"))
out, err := inc(r, "/partials/ok")
if err != nil || string(out) != "<p>ok</p>" {
t.Fatalf("include ok = %q, %v", out, err)
}
if seenHX != "true" || seenMethod != http.MethodGet {
t.Errorf("include must GET with HX-Request: true, got %s %q", seenMethod, seenHX)
}
if _, err := inc(r, "/partials/bad"); err == nil {
t.Error("a non-200 include must error")
}
if _, err := inc(r, "/partials/missing"); err == nil {
t.Error("an unregistered include must error")
}
notice := IncludeOr(inc, nil, r, "/partials/bad", "your <plans>")
if !strings.Contains(string(notice), `alert alert-danger`) || !strings.Contains(string(notice), "Could not load your &lt;plans&gt;.") {
t.Errorf("IncludeOr must render an escaped inline notice, got %q", notice)
}
if IncludeOr(nil, nil, r, "/partials/ok", "x") != "" {
t.Error("a nil Include renders nothing")
}
}