diff options
| author | Paul Buetow <paul@buetow.org> | 2026-02-24 09:12:27 +0200 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-02-24 09:12:27 +0200 |
| commit | ceb5c392d363f9f6afccd310b0a7a7efb14bb4e3 (patch) | |
| tree | 6aec30553232197d40fdc58521c8b499585ff309 /internal/tui/tui_test.go | |
| parent | c774072685c4768ec796c5f61a8140f9f673db8c (diff) | |
tui: add export modal with csv snapshot export
Diffstat (limited to 'internal/tui/tui_test.go')
| -rw-r--r-- | internal/tui/tui_test.go | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/internal/tui/tui_test.go b/internal/tui/tui_test.go index 40ea67b..d66ec84 100644 --- a/internal/tui/tui_test.go +++ b/internal/tui/tui_test.go @@ -4,6 +4,9 @@ import ( "context" "errors" "ior/internal/statsengine" + tuiexport "ior/internal/tui/export" + "os" + "path/filepath" "strings" "testing" "time" @@ -189,3 +192,40 @@ func TestDashboardRefreshPicksLateBoundSource(t *testing.T) { t.Fatalf("expected dashboard refresh to bind and use latest global source") } } + +func TestExportKeyOpensModalOnDashboard(t *testing.T) { + m := NewModel(-1, func(context.Context) error { return nil }) + m.screen = ScreenDashboard + m.attaching = false + + next, _ := m.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{'e'}}) + updated := next.(Model) + if !updated.exporter.Visible() { + t.Fatalf("expected export modal to open on e key") + } +} + +func TestRunExportCmdCSVWritesFile(t *testing.T) { + dir := t.TempDir() + prev, err := os.Getwd() + if err != nil { + t.Fatalf("getwd: %v", err) + } + if err := os.Chdir(dir); err != nil { + t.Fatalf("chdir temp dir: %v", err) + } + t.Cleanup(func() { _ = os.Chdir(prev) }) + + snap := &statsengine.Snapshot{TotalSyscalls: 1} + msg := runExportCmd(tuiexport.OptionCSV, snap)() + done, ok := msg.(tuiexport.CompletedMsg) + if !ok { + t.Fatalf("expected CompletedMsg, got %T", msg) + } + if done.Path == "" { + t.Fatalf("expected export path") + } + if _, err := os.Stat(filepath.Join(dir, done.Path)); err != nil { + t.Fatalf("expected CSV file to exist: %v", err) + } +} |
