Files
member-console/internal/server/operator_person_detail_render_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

79 lines
3.1 KiB
Go

package server
import (
"bytes"
"html/template"
"io/fs"
"strings"
"testing"
"git.coopcloud.tech/wiki-cafe/member-console/internal/embeds"
"git.coopcloud.tech/wiki-cafe/member-console/internal/web"
)
func renderPersonDetailBody(t *testing.T, data PersonDetailData) string {
t.Helper()
partialsSub, err := fs.Sub(embeds.Templates, "templates/partials")
if err != nil {
t.Fatalf("fs.Sub partials: %v", err)
}
tmpl := template.New("operator").Funcs(template.FuncMap{
"renderBody": func(string, any) (template.HTML, error) { return "", nil },
"routeURL": web.RouteURL,
"fieldErr": func(activeForm, expectedForm, activeScope, expectedScope string, errs web.FieldErrors, field string) string {
return ""
},
"stripeEntityURL": func(string, string) string { return "" },
})
tmpl, err = web.ParseUIPartials(template.Must(tmpl.ParseFS(partialsSub, "operator_*.html")))
if err != nil {
t.Fatalf("ParseFS: %v", err)
}
var buf bytes.Buffer
if err := tmpl.ExecuteTemplate(&buf, "operator_person_detail.html", data); err != nil {
t.Fatalf("ExecuteTemplate: %v", err)
}
return buf.String()
}
// TestPersonDetailDropsConstantActiveBadgeAndCaptionsRole covers UX-16
// (ux-honest-surfaces 5.5): the person page must not badge account-enablement
// knowledge the console does not evaluate (persons.status is written once at
// creation and never updated -- see internal/identity/queries/persons.sql),
// and the membership role badge must be captioned as an organizational fact
// rather than left to imply console authorization.
func TestPersonDetailDropsConstantActiveBadgeAndCaptionsRole(t *testing.T) {
body := renderPersonDetailBody(t, PersonDetailData{
Person: PersonViewModel{PersonID: "p-1", DisplayName: "Jamie Rivera", Email: "jamie@example.com", Status: "active"},
Memberships: []PersonMembershipViewModel{
{OrgID: "org-1", OrgName: "Acme Co-op", RoleName: "owner", JoinedAt: "Jan 2, 2026"},
},
})
if strings.Contains(body, `class="badge bg-success">active`) {
t.Errorf("person page must not badge the constant persons.status column, got: %s", body)
}
if !strings.Contains(body, "not a console permission") {
t.Errorf("expected the role badge to be captioned as an organizational fact, got: %s", body)
}
}
// TestPersonDetailRendersNoDerivedOrgIdentifier covers entity-keys: a
// person's membership rows render the organization's name linked to its
// composite, never an identifier derived from that name.
func TestPersonDetailRendersNoDerivedOrgIdentifier(t *testing.T) {
body := renderPersonDetailBody(t, PersonDetailData{
Person: PersonViewModel{PersonID: "p-1", DisplayName: "Jamie Rivera", Email: "jamie@example.com", Status: "active"},
Memberships: []PersonMembershipViewModel{
{OrgID: "org-1", OrgName: "Acme Co-op", RoleName: "owner", JoinedAt: "Jan 2, 2026"},
},
})
if strings.Contains(body, "acme") {
t.Errorf("expected no derived organization identifier in the body, got: %s", body)
}
if !strings.Contains(body, `href="/operator/organizations/org-1"`) {
t.Errorf("expected the membership row to link to the organization composite, got: %s", body)
}
}