The owner's "1" (2026-10-17), the two shown side by side; design 9aebe1e.
overviewHead writes "Mail is flowing. Nothing needs attention." when every
card is fine, "Mail is flowing. One thing needs attention." (or "N things
need") for warnings, and "Mail may not be flowing. ..." when a card fails;
the lead names each card that is not fine, linked, with its value inside
the sentence ("TLS certificate: expires in 12 days."), separated by
semicolons. lowerFirst lowers a value's first letter unless it is an
abbreviation ("CPU 98 %"); every value the cards write is a phrase.
Tests: TestOverviewHeadSentences (the three states, two cards, an
abbreviation), the Overview page and fragment, TestFilterDownIsAMissingSocket.
go vet + go test (26 packages) and make e2e on the test server for this
tree.
Docs: guide § Overview, CHANGELOG [Unreleased].
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
39 lines
1.6 KiB
Go
39 lines
1.6 KiB
Go
package view
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
// The head says whether mail flows and how many things need attention, and
|
|
// the lead names each with its value inside the sentence (mockup
|
|
// overview.html; the owner's "1", 2026-10-17).
|
|
func TestOverviewHeadSentences(t *testing.T) {
|
|
ok := HealthCard{Name: "Processes", Value: "5 of 5 running", Href: "/server/health"}
|
|
cert := HealthCard{Name: "TLS certificate", Value: "Expires in 12 days", Href: "/server/health", Level: LevelWarn}
|
|
cpu := HealthCard{Name: "Machine", Value: "CPU 98 %", Href: "/server/health", Level: LevelWarn}
|
|
postfix := HealthCard{Name: "Processes", Value: "4 of 5 running", Href: "/server/health", Level: LevelFail}
|
|
for _, c := range []struct {
|
|
name string
|
|
cards []HealthCard
|
|
title, lead string
|
|
}{
|
|
{"all fine", []HealthCard{ok}, "Mail is flowing. Nothing needs attention.", ""},
|
|
{"one warning", []HealthCard{ok, cert}, "Mail is flowing. One thing needs attention.", "TLS certificate: expires in 12 days."},
|
|
{"two warnings", []HealthCard{cert, cpu}, "Mail is flowing. 2 things need attention.", "TLS certificate: expires in 12 days; Machine: CPU 98 %."},
|
|
{"a failure", []HealthCard{postfix, cert}, "Mail may not be flowing. 2 things need attention.", "Processes: 4 of 5 running; TLS certificate: expires in 12 days."},
|
|
} {
|
|
h := overviewHead("mail.example.org", c.cards, time.Now())
|
|
if h.Title != c.title {
|
|
t.Errorf("%s: title %q, want %q", c.name, h.Title, c.title)
|
|
}
|
|
var lead string
|
|
for _, in := range h.Lead {
|
|
lead += in.Text
|
|
}
|
|
if lead != c.lead {
|
|
t.Errorf("%s: lead %q, want %q", c.name, lead, c.lead)
|
|
}
|
|
}
|
|
}
|