summaryrefslogtreecommitdiff
path: root/internal/tui/flamegraph/frame_animator_test.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-05-26 22:48:54 +0300
committerPaul Buetow <paul@buetow.org>2026-05-26 22:48:54 +0300
commitff8ef868472dd3b359c03e4ff9163bf2d113e0bf (patch)
tree26690368120ad431956f9a1803b90829e78786e3 /internal/tui/flamegraph/frame_animator_test.go
parentfb5a9c1f5c99559cb013a6ff396eb56a7d1f7be6 (diff)
vo: fix flamegraph click mapping for expanded leaf rows
Diffstat (limited to 'internal/tui/flamegraph/frame_animator_test.go')
-rw-r--r--internal/tui/flamegraph/frame_animator_test.go48
1 files changed, 48 insertions, 0 deletions
diff --git a/internal/tui/flamegraph/frame_animator_test.go b/internal/tui/flamegraph/frame_animator_test.go
new file mode 100644
index 0000000..6b4d4f7
--- /dev/null
+++ b/internal/tui/flamegraph/frame_animator_test.go
@@ -0,0 +1,48 @@
+package flamegraph
+
+import "testing"
+
+func TestFrameCoordToTargetRowKeepsUniformBarMapping(t *testing.T) {
+ frames := []tuiFrame{
+ {Name: "root", Row: 0, Col: 0, Width: 20, Path: "root"},
+ {Name: "a", Row: 1, Col: 0, Width: 20, Path: "root" + pathSeparator + "a"},
+ {Name: "b", Row: 2, Col: 0, Width: 20, Path: "root" + pathSeparator + "a" + pathSeparator + "b"},
+ {Name: "leaf", Row: 3, Col: 0, Width: 20, Path: "root" + pathSeparator + "a" + pathSeparator + "b" + pathSeparator + "leaf"},
+ }
+ availableRows := 8
+ want := []int{3, 3, 2, 2, 1, 1, 0, 0}
+ for dataRow, expected := range want {
+ if got := frameCoordToTargetRow(frames, dataRow, availableRows, false); got != expected {
+ t.Fatalf("dataRow=%d: got row=%d want=%d", dataRow, got, expected)
+ }
+ }
+}
+
+func TestFrameCoordToTargetRowHeightMetricMapsExpandedLeafBand(t *testing.T) {
+ frames := []tuiFrame{
+ {Name: "root", Row: 0, Col: 0, Width: 20, Path: "root"},
+ {Name: "leaf", Row: 1, Col: 0, Width: 20, Path: "root" + pathSeparator + "leaf", HeightTotal: 100},
+ }
+ availableRows := 6
+ want := []int{1, 1, 1, 1, 1, 0}
+ for dataRow, expected := range want {
+ if got := frameCoordToTargetRow(frames, dataRow, availableRows, true); got != expected {
+ t.Fatalf("dataRow=%d: got row=%d want=%d", dataRow, got, expected)
+ }
+ }
+}
+
+func TestFrameIndexAtHeightMetricMapsClicksInExpandedLeafBand(t *testing.T) {
+ frames := []tuiFrame{
+ {Name: "root", Row: 0, Col: 0, Width: 20, Path: "root"},
+ {Name: "leaf", Row: 1, Col: 0, Width: 20, Path: "root" + pathSeparator + "leaf", HeightTotal: 100},
+ }
+ for y := 1; y <= 5; y++ {
+ if got := frameIndexAt(frames, 10, y, 20, 9, false, true); got != 1 {
+ t.Fatalf("y=%d: expected leaf frame index 1, got %d", y, got)
+ }
+ }
+ if got := frameIndexAt(frames, 10, 6, 20, 9, false, true); got != 0 {
+ t.Fatalf("y=6: expected root frame index 0, got %d", got)
+ }
+}