hub: render-test for the dashboard critical badge (Scenario D — UI verify; operator login gates Chrome)
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PSK5g6qYLknKj8u3QAFEr6
This commit is contained in:
@@ -70,3 +70,46 @@ func TestTemplates_FloorRender(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Scenario D of the v0.31.0 critical-severity fix: a customer with critical events must render a
|
||||
// distinct severity-critical count badge on the dashboard, ordered BEFORE the error badge.
|
||||
// (Pre-fix consumer gap: criticals were accepted but invisible in the 24h summary counts.)
|
||||
func TestTemplates_DashboardCriticalBadge(t *testing.T) {
|
||||
st, err := store.New(filepath.Join(t.TempDir(), "t.db"), log.New(io.Discard, "", 0))
|
||||
if err != nil {
|
||||
t.Fatalf("store.New: %v", err)
|
||||
}
|
||||
t.Cleanup(func() { st.Close() })
|
||||
s := New(st, "", "", "test", time.Hour, log.New(io.Discard, "", 0))
|
||||
|
||||
// Mirrors the anonymous dashboardCustomer struct in handleDashboard.
|
||||
type dashboardCustomer struct {
|
||||
store.CustomerSummary
|
||||
OverallStatus string
|
||||
BackupAge string
|
||||
EventCriticals int
|
||||
EventErrors int
|
||||
EventWarnings int
|
||||
}
|
||||
data := []dashboardCustomer{{
|
||||
CustomerSummary: store.CustomerSummary{CustomerID: "c1", CustomerName: "Acme", ReceivedAt: time.Now()},
|
||||
OverallStatus: "ok", BackupAge: "–",
|
||||
EventCriticals: 2, EventErrors: 1, EventWarnings: 0,
|
||||
}}
|
||||
var buf bytes.Buffer
|
||||
if err := s.templates.ExecuteTemplate(&buf, "dashboard.html", data); err != nil {
|
||||
t.Fatalf("render dashboard.html: %v", err)
|
||||
}
|
||||
body := buf.String()
|
||||
critIdx := strings.Index(body, `severity-badge severity-critical">2<`)
|
||||
errIdx := strings.Index(body, `severity-badge severity-error">1<`)
|
||||
if critIdx < 0 {
|
||||
t.Fatalf("dashboard.html missing the severity-critical count badge")
|
||||
}
|
||||
if errIdx < 0 {
|
||||
t.Fatalf("dashboard.html missing the severity-error count badge")
|
||||
}
|
||||
if critIdx > errIdx {
|
||||
t.Errorf("critical badge renders AFTER the error badge (crit@%d, err@%d) — must be first", critIdx, errIdx)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user