history plot
This commit is contained in:
1 parent
8ade787421
commit
624ff1da42
3 files changed
+141
-7
No files matched your search
@@ -81,3 +81,31 @@ func TestLoadConfig(t *testing.T) {
|
||||
t.Fatalf("addr = %q, want %q", cfg.Addr, ":9090")
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuildHistoryChartEmpty(t *testing.T) {
|
||||
chart := buildHistoryChart(nil)
|
||||
if !strings.Contains(string(chart), "No power history yet") {
|
||||
t.Fatalf("empty chart did not contain fallback text: %s", string(chart))
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuildHistoryChartRendersPolyline(t *testing.T) {
|
||||
history := []sample{
|
||||
{at: time.Date(2026, 4, 20, 0, 0, 0, 0, time.UTC), value: 100},
|
||||
{at: time.Date(2026, 4, 20, 6, 0, 0, 0, time.UTC), value: 200},
|
||||
{at: time.Date(2026, 4, 20, 12, 0, 0, 0, time.UTC), value: 150},
|
||||
}
|
||||
|
||||
chart := buildHistoryChart(history)
|
||||
if !strings.Contains(string(chart), "<polyline") {
|
||||
t.Fatalf("chart did not contain polyline: %s", string(chart))
|
||||
}
|
||||
for _, want := range []string{"W", "00:00", "06:00", "12:00"} {
|
||||
if !strings.Contains(string(chart), want) {
|
||||
t.Fatalf("chart did not include %q: %s", want, string(chart))
|
||||
}
|
||||
}
|
||||
if !strings.Contains(string(chart), "0 W") {
|
||||
t.Fatalf("chart did not include zero baseline: %s", string(chart))
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user