test(tui): add mouse navigation and card rendering tests

app_mouse_test.go:
- TestTabAtXMatchesTabWidths: Verifies that tabAtX() correctly maps
  X coordinates to tab indices for all active tab states
- Uses tabWidthForTest() helper that mirrors TabVisualWidth() logic
- Catches regressions where tab hit detection drifts from rendering

card_fix_test.go:
- TestCardRowBackgroundFill: Verifies that CardRow() properly equalizes
  card heights and fills backgrounds on shorter cards
- Forces TrueColor profile in init() to ensure ANSI codes generate
- Validates that padding lines contain ANSI escape sequences,
  confirming background styling isn't stripped

These tests guard against visual regressions that are hard to catch
in manual testing, particularly the subtle issue where short cards
in a row would have "punched out" gaps where their backgrounds
didn't extend to match taller neighbors.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
teernisse
2026-02-28 00:05:57 -05:00
parent 0416d029b1
commit 302f34ff85
2 changed files with 117 additions and 0 deletions

View File

@@ -0,0 +1,38 @@
package tui
import "testing"
func TestTabAtXMatchesTabWidths(t *testing.T) {
for active := 0; active < 5; active++ {
a := App{activeTab: active}
pos := 0
for i := 0; i < 5; i++ {
w := tabWidthForTest(i, active)
x := pos + w/2 // midpoint inside this tab
if got := a.tabAtX(x); got != i {
t.Fatalf("active=%d x=%d -> tab=%d, want %d", active, x, got, i)
}
pos += w
if i < 4 {
pos++ // separator
}
}
}
}
func tabWidthForTest(tabIdx, activeIdx int) int {
nameWidths := []int{
len("Overview"),
len("Costs"),
len("Sessions"),
len("Breakdown"),
len("Settings"),
}
w := nameWidths[tabIdx] + 2 // horizontal padding in tab renderer
if tabIdx != activeIdx && tabIdx == 4 {
w += 3 // inactive Settings adds "[x]"
}
return w
}