package web import ( "html/template" "testing" ) // TASK-D4 §7B: statusColor maps every OverallStatus value the hub emits (server.go // handleDashboard + configs.go + the hosts stale state) to a v2 semantic token consumed // as a class suffix — never an inline color. Exception-color: healthy fleet = blue/neutral. func TestStatusColorTruthTable(t *testing.T) { cases := []struct { status string want string }{ {"ok", "nominal"}, // operating normally — blue {"warn", "warn"}, // degraded / stale report — amber {"stale", "warn"}, // host stale state {"down", "crit"}, // outage — red {"fail", "crit"}, // health=fail — red {"pending", "neutral"}, // not-yet-provisioned customer is a NORMAL fleet state {"disabled", "neutral"}, // deliberately paused — not a deviation {"blocked", "warn"}, // operator cut-off: intentional but attention-worthy {"bogus", "neutral"}, // unknown values stay quiet {"", "neutral"}, } for _, c := range cases { if got := statusColor(c.status); got != c.want { t.Errorf("statusColor(%q) = %q, want %q", c.status, got, c.want) } } } // TestTemplatesParseWithFuncmap parses all hub templates with the production funcmap — // catches a typo'd function name introduced during the D4 sweep (did not exist before). func TestTemplatesParseWithFuncmap(t *testing.T) { s := New(nil, "", "", "test", 0, nil) _ = s // New itself template.Must-parses; reaching here means parse succeeded // belt and braces: parse again explicitly if _, err := template.New("").Funcs(template.FuncMap{ "timeAgo": timeAgo, "timeAgoPtr": func(v interface{}) string { return "" }, "statusColor": statusColor, "formatFloat": func(f float64) string { return "" }, "joinStrings": func(s []string, sep string) string { return "" }, "json": func(v interface{}) template.JS { return "" }, "hubVersion": func() string { return "" }, "add": func(a, b int) int { return 0 }, "mapGet": func(m map[string]int, k string) int { return 0 }, "memoryColor": memoryColor, "accuracyClass": accuracyClass, "gt": func(a, b int) bool { return false }, }).ParseFS(templateFS, "templates/*.html"); err != nil { t.Fatalf("templates failed to parse: %v", err) } }