- 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
50 lines
1.8 KiB
Go
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 <plans>.") {
|
|
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")
|
|
}
|
|
}
|