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 renderOrganizationsPageBody(t *testing.T, data OrganizationsData) 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 = tmpl.ParseFS(partialsSub, "operator_*.html") if err != nil { t.Fatalf("ParseFS: %v", err) } var buf bytes.Buffer if err := tmpl.ExecuteTemplate(&buf, "operator_organizations.html", data); err != nil { t.Fatalf("ExecuteTemplate: %v", err) } return buf.String() } // TestOrganizationsListShowsOwnerAndNeutralStatus covers UX-16 // (ux-honest-surfaces 5.5): every organization row must show its owner so // no row reads as unowned, and the unread status column must not render as // a colored state badge. func TestOrganizationsListShowsOwnerAndNeutralStatus(t *testing.T) { body := renderOrganizationsPageBody(t, OrganizationsData{ Organizations: []OrganizationViewModel{ {OrgID: "org-1", Name: "Acme Co-op", Slug: "acme", OrgType: "team", Status: "active", MemberCount: 3, OwnerName: "Jamie Rivera"}, }, }) if !strings.Contains(body, "Jamie Rivera") { t.Errorf("expected the organization row to show its owner, got: %s", body) } if strings.Contains(body, `class="badge bg-success">active`) || strings.Contains(body, `class="badge bg-secondary">active`) { t.Errorf("status must not render as a colored badge, got: %s", body) } } // TestOrganizationsListMarksSystemTenant covers UX-16: the reserved System // organization must carry a visible synthetic marker and must not offer the // ordinary Enrollment action other rows get. func TestOrganizationsListMarksSystemTenant(t *testing.T) { body := renderOrganizationsPageBody(t, OrganizationsData{ Organizations: []OrganizationViewModel{ {OrgID: "org-sys", Name: "System", Slug: "system", OrgType: "system", Status: "active", OwnerName: "System", IsSystemOrg: true}, }, }) if !strings.Contains(body, "System tenant") { t.Errorf("expected a visible system-tenant marker, got: %s", body) } if strings.Contains(body, "Enrollment") { t.Errorf("the system tenant row must not offer the ordinary Enrollment action, got: %s", body) } }