Files
member-console/internal/server/operator_template_smoke_test.go
T
cgalo5758 8e3c68c6be Make UI surfaces honestly reflect system state
- Add deployment-name branding to titles, mastheads, and OG tags
- Share one grant delivery-state query with lineage across grants
  surfaces
- Show pool status/usage, org owners, and config readiness
- Make billing views projection-aware with recency and sync vocabulary
- Guard FedWiki creation without domains and render route-aware 404s
2026-08-23 01:45:52 -05:00

184 lines
6.3 KiB
Go

package server
import (
"bytes"
"html/template"
"io/fs"
"strings"
"testing"
"git.coopcloud.tech/wiki-cafe/member-console/internal/config"
"git.coopcloud.tech/wiki-cafe/member-console/internal/embeds"
"git.coopcloud.tech/wiki-cafe/member-console/internal/web"
)
// TestOperatorTemplateRendersBothBranches parses operator.html and renders
// both dispatch branches (curated landing surface and the MPA BodyTemplate
// dispatch) to catch Go-template syntax errors that would otherwise only
// surface at request time. The legacy tabstrip branch was retired in slice
// 8 of operator-mpa-conversion §5.
func TestOperatorTemplateRendersBothBranches(t *testing.T) {
sub, err := fs.Sub(embeds.Templates, "templates")
if err != nil {
t.Fatalf("fs.Sub: %v", err)
}
partialsSub, err := fs.Sub(embeds.Templates, "templates/partials")
if err != nil {
t.Fatalf("fs.Sub partials: %v", err)
}
// operator.html references the `renderBody` and `routeURL` template
// funcs and includes partials like operator_lookup_result.html via
// `{{ template "..." . }}`. Mirror NewOperatorPartialsHandler: load
// partials first, then the shell.
tmpl := template.New("operator").Funcs(template.FuncMap{
"renderBody": func(string, any) (template.HTML, error) { return "", nil },
"routeURL": web.RouteURL,
"fieldErr": func(_, _, _, _ string, _, _ any) string { return "" },
"stripeEntityURL": func(string, string) string { return "" },
"deploymentName": config.DeploymentName,
})
tmpl, err = tmpl.ParseFS(partialsSub, "operator_*.html")
if err != nil {
t.Fatalf("ParseFS partials: %v", err)
}
tmpl, err = tmpl.ParseFS(sub, "operator.html")
if err != nil {
t.Fatalf("ParseFS operator.html: %v", err)
}
cases := []struct {
name string
data OperatorPageData
want string
}{
{
name: "landing",
data: OperatorPageData{
CSRFToken: "csrf",
IAPosition: "runtime:landing",
},
want: "Find a person or organization",
},
{
// BodyTemplate dispatch branch must short-circuit the landing
// surface; the stub renderBody returns "" so the assertion is
// that the shell still renders (no landing markup leaks in).
name: "body-template-dispatch",
data: OperatorPageData{
CSRFToken: "csrf",
IAPosition: "runtime:organizations",
ActiveCapability: "organizations",
BodyTemplate: "operator_organizations.html",
BodyData: nil,
},
want: `id="operator-main"`,
},
{
// Registry-driven Integration nav: the sidebar enumerates
// provisioning providers rather than a hardcoded <li>. A provider
// with a surface path renders a link labeled by its display name.
name: "integration-nav-from-registry",
data: OperatorPageData{
CSRFToken: "csrf",
IAPosition: "integration:example-sites",
CurrentPath: "/operator/example-sites",
IntegrationProviders: []IntegrationProviderNav{
{Slug: "example", DisplayName: "Example", SurfacePath: "/operator/example-sites"},
},
},
want: `href="/operator/example-sites">Example</a>`,
},
{
// Dedicated Integrations section: the sidebar renders a labeled
// "Integrations" home link to /operator/integrations, above the
// registry-driven provider links.
name: "integration-section-home",
data: OperatorPageData{
CSRFToken: "csrf",
ActiveCapability: "integrations",
CurrentPath: "/operator/integrations",
IntegrationProviders: []IntegrationProviderNav{
{Slug: "example", DisplayName: "Example", SurfacePath: "/operator/example-sites"},
},
},
want: `href="/operator/integrations">Integrations</a>`,
},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
var buf bytes.Buffer
if err := tmpl.ExecuteTemplate(&buf, "operator.html", tc.data); err != nil {
t.Fatalf("ExecuteTemplate: %v", err)
}
out := buf.String()
if !strings.Contains(out, tc.want) {
t.Errorf("rendered output missing %q", tc.want)
}
if !strings.Contains(out, `hx-boost="true"`) {
t.Errorf("rendered output missing hx-boost on body")
}
if !strings.Contains(out, `id="operator-main"`) {
t.Errorf("rendered output missing main#operator-main swap target")
}
// Slice 8 guard: legacy tabstrip markup must not reappear.
if strings.Contains(out, `id="operatorTabs"`) {
t.Errorf("legacy tabstrip leaked back into operator.html — re-check §5 retirement")
}
})
}
}
// TestOperatorIntegrationsTemplate renders the Integrations landing body
// partial directly (the operator.html smoke test stubs renderBody, so the body
// markup is not exercised there). Covers a populated provider row and the
// empty state.
func TestOperatorIntegrationsTemplate(t *testing.T) {
partialsSub, err := fs.Sub(embeds.Templates, "templates/partials")
if err != nil {
t.Fatalf("fs.Sub partials: %v", err)
}
tmpl := template.New("integrations").Funcs(template.FuncMap{
"renderBody": func(string, any) (template.HTML, error) { return "", nil },
"routeURL": web.RouteURL,
"fieldErr": func(_, _, _, _ string, _, _ any) string { return "" },
"stripeEntityURL": func(string, string) string { return "" },
})
tmpl, err = tmpl.ParseFS(partialsSub, "operator_*.html")
if err != nil {
t.Fatalf("ParseFS partials: %v", err)
}
t.Run("populated", func(t *testing.T) {
var buf bytes.Buffer
data := IntegrationsData{Integrations: []IntegrationRow{{
Slug: "example",
DisplayName: "Example",
Kind: "provisioning",
Status: "active",
SurfacePath: "/operator/example-sites",
Operations: []string{"create", "delete", "set_status"},
ResourceKeys: []string{"example_sites"},
}}}
if err := tmpl.ExecuteTemplate(&buf, "operator_integrations.html", data); err != nil {
t.Fatalf("ExecuteTemplate: %v", err)
}
out := buf.String()
for _, want := range []string{"Example", "example_sites", "set_status", `href="/operator/example-sites"`, "Active"} {
if !strings.Contains(out, want) {
t.Errorf("integrations landing missing %q", want)
}
}
})
t.Run("empty", func(t *testing.T) {
var buf bytes.Buffer
if err := tmpl.ExecuteTemplate(&buf, "operator_integrations.html", IntegrationsData{}); err != nil {
t.Fatalf("ExecuteTemplate empty: %v", err)
}
if !strings.Contains(buf.String(), "No integrations registered") {
t.Errorf("empty state not rendered")
}
})
}