diff --git a/hub/internal/web/render_test.go b/hub/internal/web/render_test.go index 1da7fb7..ae2c36d 100644 --- a/hub/internal/web/render_test.go +++ b/hub/internal/web/render_test.go @@ -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) + } +}