diff options
| author | Paul Buetow <paul@buetow.org> | 2026-03-06 08:18:51 +0200 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-03-06 08:18:51 +0200 |
| commit | 4445eefb69a50d178d4c6bd02fd534312d774542 (patch) | |
| tree | c70efee49a5ce574bf472bd9cce1b5170234efd2 /internal/tui/flamegraph/model_test.go | |
| parent | c6ec3b3ee34c9e77daa7159e8c164e413c2101b5 (diff) | |
Keep flame selection visible and improve arrow-key fallback
Diffstat (limited to 'internal/tui/flamegraph/model_test.go')
| -rw-r--r-- | internal/tui/flamegraph/model_test.go | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/internal/tui/flamegraph/model_test.go b/internal/tui/flamegraph/model_test.go index ccb5c94..0301b93 100644 --- a/internal/tui/flamegraph/model_test.go +++ b/internal/tui/flamegraph/model_test.go @@ -128,6 +128,20 @@ func TestKeyboardNavigationSingleNodeClamped(t *testing.T) { } } +func TestArrowDownFallsBackToVisibleDepthFromRoot(t *testing.T) { + m := NewModel(nil) + m.frames = []tuiFrame{ + {Name: "root", Depth: 0, Col: 0, Path: "root"}, + {Name: "child", Depth: 1, Col: 0, Path: "root" + pathSeparator + "child"}, + } + m.selectedIdx = 0 + + m = pressFlameKey(t, m, tea.KeyPressMsg{Code: tea.KeyDown}) + if m.selectedIdx != 1 { + t.Fatalf("expected down arrow to move selection to child when root has no shallower row, got %d", m.selectedIdx) + } +} + func TestZoomInUndoResetAndNestedZoom(t *testing.T) { m := newZoomModel() @@ -399,6 +413,37 @@ func TestDataRefreshAnimationConvergesOverTicks(t *testing.T) { } } +func TestRebuildKeepsSelectionOnVisibleRowsWhenTruncated(t *testing.T) { + m := NewModel(nil) + m.width = 80 + m.height = 4 // only 2 render rows remain after toolbar+status + m.snapshot = &snapshotNode{ + Name: "root", + Children: []*snapshotNode{ + { + Name: "a", + Children: []*snapshotNode{ + { + Name: "b", + Children: []*snapshotNode{ + {Name: "c", Total: 5}, + }, + }, + }, + }, + }, + } + + m.rebuildFrames(false) + if len(m.frames) == 0 { + t.Fatalf("expected rebuilt frames") + } + rowOffset := m.visibleRowOffset() + if m.frames[m.selectedIdx].Row < rowOffset { + t.Fatalf("expected selected frame row %d to be visible (offset=%d)", m.frames[m.selectedIdx].Row, rowOffset) + } +} + func TestResizeRecalculatesLayoutAndCullsNarrowFrames(t *testing.T) { m := NewModel(nil) m.width = 120 |
