summaryrefslogtreecommitdiff
path: root/internal/tui/dashboard/sparkline_test.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-02-24 08:34:00 +0200
committerPaul Buetow <paul@buetow.org>2026-02-24 08:34:00 +0200
commit89ba8287d490a0fef15a80a34ea4efe0c5ecf2e8 (patch)
treed164744464c7997a23be60200eebf710015d8fed /internal/tui/dashboard/sparkline_test.go
parent9c400937d9e32f3ce85c668d9ca52c351f8b5d13 (diff)
tui: add dashboard sparkline renderer
Diffstat (limited to 'internal/tui/dashboard/sparkline_test.go')
-rw-r--r--internal/tui/dashboard/sparkline_test.go43
1 files changed, 43 insertions, 0 deletions
diff --git a/internal/tui/dashboard/sparkline_test.go b/internal/tui/dashboard/sparkline_test.go
new file mode 100644
index 0000000..d39d145
--- /dev/null
+++ b/internal/tui/dashboard/sparkline_test.go
@@ -0,0 +1,43 @@
+package dashboard
+
+import (
+ "strings"
+ "testing"
+)
+
+func TestRenderSparklineEmptyOrInvalidWidth(t *testing.T) {
+ if got := renderSparkline(nil, 5); got != "" {
+ t.Fatalf("expected empty sparkline for nil data, got %q", got)
+ }
+ if got := renderSparkline([]float64{1, 2, 3}, 0); got != "" {
+ t.Fatalf("expected empty sparkline for width 0, got %q", got)
+ }
+}
+
+func TestRenderSparklineSingleValue(t *testing.T) {
+ got := renderSparkline([]float64{10}, 8)
+ if got != "▄" {
+ t.Fatalf("expected single mid-bar rune, got %q", got)
+ }
+}
+
+func TestRenderSparklineAllEqualValues(t *testing.T) {
+ got := renderSparkline([]float64{5, 5, 5, 5}, 4)
+ if got != "▄▄▄▄" {
+ t.Fatalf("expected flat sparkline, got %q", got)
+ }
+}
+
+func TestRenderSparklineRespectsWidthTruncation(t *testing.T) {
+ got := renderSparkline([]float64{1, 2, 3, 4, 5, 6, 7, 8}, 4)
+ if len([]rune(got)) != 4 {
+ t.Fatalf("expected 4 runes, got %q", got)
+ }
+}
+
+func TestRenderSparklineSpansLowToHigh(t *testing.T) {
+ got := renderSparkline([]float64{0, 10}, 2)
+ if !strings.Contains(got, "▁") || !strings.Contains(got, "█") {
+ t.Fatalf("expected low/high bars, got %q", got)
+ }
+}