diff options
| author | Paul Buetow <paul@buetow.org> | 2026-02-24 08:32:39 +0200 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-02-24 08:32:39 +0200 |
| commit | 9c400937d9e32f3ce85c668d9ca52c351f8b5d13 (patch) | |
| tree | 90170eedda64c59a063c0010d1452f6b3e5d71f5 /internal/tui/dashboard/model_test.go | |
| parent | ba7af922d289a9d0fff1c4ef33764b1852c774f6 (diff) | |
tui: add dashboard tab framework model
Diffstat (limited to 'internal/tui/dashboard/model_test.go')
| -rw-r--r-- | internal/tui/dashboard/model_test.go | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/internal/tui/dashboard/model_test.go b/internal/tui/dashboard/model_test.go new file mode 100644 index 0000000..ddb457a --- /dev/null +++ b/internal/tui/dashboard/model_test.go @@ -0,0 +1,99 @@ +package dashboard + +import ( + "strings" + "testing" + + "ior/internal/statsengine" + "ior/internal/tui" + "ior/internal/tui/messages" + + tea "github.com/charmbracelet/bubbletea" +) + +type fakeSnapshotSource struct { + snapshots int + snap *statsengine.Snapshot +} + +func (f *fakeSnapshotSource) Snapshot() *statsengine.Snapshot { + f.snapshots++ + return f.snap +} + +func TestKeySwitchingChangesActiveTab(t *testing.T) { + m := NewModelWithConfig(nil, 250, tui.DefaultKeyMap()) + + next, _ := m.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{'2'}}) + model := next.(Model) + if model.activeTab != TabSyscalls { + t.Fatalf("expected syscalls tab, got %v", model.activeTab) + } + + next, _ = model.Update(tea.KeyMsg{Type: tea.KeyTab}) + model = next.(Model) + if model.activeTab != TabFiles { + t.Fatalf("expected next tab to be files, got %v", model.activeTab) + } + + next, _ = model.Update(tea.KeyMsg{Type: tea.KeyShiftTab}) + model = next.(Model) + if model.activeTab != TabSyscalls { + t.Fatalf("expected previous tab to be syscalls, got %v", model.activeTab) + } +} + +func TestRefreshTickEmitsStatsTickMsg(t *testing.T) { + snap := &statsengine.Snapshot{TotalSyscalls: 9} + engine := &fakeSnapshotSource{snap: snap} + m := NewModelWithConfig(engine, 100, tui.DefaultKeyMap()) + + next, cmd := m.Update(refreshTickMsg{}) + if cmd == nil { + t.Fatalf("expected tick command batch") + } + if engine.snapshots != 1 { + t.Fatalf("expected one snapshot call, got %d", engine.snapshots) + } + + msg := cmd() + switch v := msg.(type) { + case tea.BatchMsg: + var sawStats bool + for _, c := range v { + out := c() + if stats, ok := out.(messages.StatsTickMsg); ok && stats.Snap == snap { + sawStats = true + } + } + if !sawStats { + t.Fatalf("expected StatsTickMsg in batch output") + } + default: + t.Fatalf("expected batch message, got %T", msg) + } + + _ = next +} + +func TestStatsTickMsgUpdatesLatestSnapshot(t *testing.T) { + snap := &statsengine.Snapshot{TotalSyscalls: 11} + m := NewModel(nil) + + next, _ := m.Update(messages.StatsTickMsg{Snap: snap}) + model := next.(Model) + if model.latest != snap { + t.Fatalf("expected latest snapshot to be updated") + } +} + +func TestViewRendersTabBarAndHelp(t *testing.T) { + m := NewModelWithConfig(nil, 1000, tui.DefaultKeyMap()) + out := m.View() + if !strings.Contains(out, "Overview") { + t.Fatalf("expected overview label in view") + } + if !strings.Contains(out, "tab next tab") { + t.Fatalf("expected help bar text in view") + } +} |
