summaryrefslogtreecommitdiff
path: root/internal/tui/dashboard/model_test.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-02-24 10:35:13 +0200
committerPaul Buetow <paul@buetow.org>2026-02-24 10:35:13 +0200
commita403ca152b6268eacf2804c2d857ead16af37ef3 (patch)
tree6df1ebaa0e2a68f2dfc6c17b9987ae8fbff3129c /internal/tui/dashboard/model_test.go
parent791c7aa9e573e80e90ba37e07c8791f280e74d9a (diff)
tui: address review feedback for dashboard and export
Diffstat (limited to 'internal/tui/dashboard/model_test.go')
-rw-r--r--internal/tui/dashboard/model_test.go40
1 files changed, 40 insertions, 0 deletions
diff --git a/internal/tui/dashboard/model_test.go b/internal/tui/dashboard/model_test.go
index 11cfc2b..f1e6f35 100644
--- a/internal/tui/dashboard/model_test.go
+++ b/internal/tui/dashboard/model_test.go
@@ -46,6 +46,8 @@ func TestKeySwitchingChangesActiveTab(t *testing.T) {
func TestSyscallsTabScrollsWithJK(t *testing.T) {
m := NewModelWithConfig(nil, 250, common.DefaultKeyMap())
m.activeTab = TabSyscalls
+ snap := statsengine.NewSnapshot(nil, nil, nil, []statsengine.SyscallSnapshot{{Name: "read", Count: 1}, {Name: "write", Count: 1}}, nil, nil, statsengine.HistogramSnapshot{}, statsengine.HistogramSnapshot{})
+ m.latest = &snap
next, _ := m.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{'j'}})
model := next.(Model)
@@ -63,6 +65,8 @@ func TestSyscallsTabScrollsWithJK(t *testing.T) {
func TestProcessesTabScrollsWithJK(t *testing.T) {
m := NewModelWithConfig(nil, 250, common.DefaultKeyMap())
m.activeTab = TabProcesses
+ snap := statsengine.NewSnapshot(nil, nil, nil, nil, nil, []statsengine.ProcessSnapshot{{PID: 1}, {PID: 2}}, statsengine.HistogramSnapshot{}, statsengine.HistogramSnapshot{})
+ m.latest = &snap
next, _ := m.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{'j'}})
model := next.(Model)
@@ -80,6 +84,8 @@ func TestProcessesTabScrollsWithJK(t *testing.T) {
func TestFilesTabScrollsWithJK(t *testing.T) {
m := NewModelWithConfig(nil, 250, common.DefaultKeyMap())
m.activeTab = TabFiles
+ snap := statsengine.NewSnapshot(nil, nil, nil, nil, []statsengine.FileSnapshot{{Path: "/a"}, {Path: "/b"}}, nil, statsengine.HistogramSnapshot{}, statsengine.HistogramSnapshot{})
+ m.latest = &snap
next, _ := m.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{'j'}})
model := next.(Model)
@@ -94,6 +100,40 @@ func TestFilesTabScrollsWithJK(t *testing.T) {
}
}
+func TestScrollOffsetDoesNotGrowUnbounded(t *testing.T) {
+ m := NewModelWithConfig(nil, 250, common.DefaultKeyMap())
+ m.activeTab = TabSyscalls
+ snap := statsengine.NewSnapshot(nil, nil, nil, []statsengine.SyscallSnapshot{{Name: "read", Count: 1}, {Name: "write", Count: 1}}, nil, nil, statsengine.HistogramSnapshot{}, statsengine.HistogramSnapshot{})
+ m.latest = &snap
+
+ for i := 0; i < 50; i++ {
+ next, _ := m.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{'j'}})
+ m = next.(Model)
+ }
+ if m.syscallsOffset != 1 {
+ t.Fatalf("expected bounded offset 1, got %d", m.syscallsOffset)
+ }
+}
+
+func TestRefreshKeyEmitsRefreshTick(t *testing.T) {
+ snap := &statsengine.Snapshot{TotalSyscalls: 13}
+ engine := &fakeSnapshotSource{snap: snap}
+ m := NewModelWithConfig(engine, 250, common.DefaultKeyMap())
+ next, cmd := m.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{'r'}})
+ _ = next
+ if cmd == nil {
+ t.Fatalf("expected refresh command")
+ }
+ msg := cmd()
+ stats, ok := msg.(messages.StatsTickMsg)
+ if !ok {
+ t.Fatalf("expected StatsTickMsg from refresh key command, got %T", msg)
+ }
+ if stats.Snap != snap {
+ t.Fatalf("expected refreshed snapshot from engine")
+ }
+}
+
func TestRefreshTickEmitsStatsTickMsg(t *testing.T) {
snap := &statsengine.Snapshot{TotalSyscalls: 9}
engine := &fakeSnapshotSource{snap: snap}