summaryrefslogtreecommitdiff
path: root/internal/ui/table_test.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-06-25 11:18:54 +0300
committerPaul Buetow <paul@buetow.org>2026-06-25 11:18:54 +0300
commit51a875e4d665c51e031259d48c9e6c723dafbcef (patch)
treeb82246cfbbcfbf2a0892562fda0e8c4c4f2809f6 /internal/ui/table_test.go
parent541fe26ddb20e00112d0bcbda9249625dfe5d245 (diff)
Refactor ultra visibility offset handling (3r0)
Diffstat (limited to 'internal/ui/table_test.go')
-rw-r--r--internal/ui/table_test.go80
1 files changed, 80 insertions, 0 deletions
diff --git a/internal/ui/table_test.go b/internal/ui/table_test.go
index 7a8a186..3c7cbd7 100644
--- a/internal/ui/table_test.go
+++ b/internal/ui/table_test.go
@@ -2898,6 +2898,86 @@ func TestUltraEntryResizeAndNavigationBindings(t *testing.T) {
}
}
+func TestUltraEnsureVisibleOffsets(t *testing.T) {
+ tasks := []task.Task{
+ {ID: 1, UUID: "1", Description: "alpha", Status: "pending"},
+ {ID: 2, UUID: "2", Description: "beta bravo", Status: "pending"},
+ {ID: 3, UUID: "3", Description: "charlie delta", Status: "pending"},
+ }
+
+ tests := []struct {
+ name string
+ tasks []task.Task
+ height int
+ cursor int
+ offset int
+ wantCursor int
+ wantOffset int
+ }{
+ {
+ name: "empty list clamps cursor and offset",
+ height: 7,
+ cursor: 2,
+ offset: 2,
+ wantCursor: 0,
+ wantOffset: 0,
+ },
+ {
+ name: "cursor above offset scrolls to cursor",
+ tasks: tasks,
+ height: 7,
+ cursor: 0,
+ offset: 2,
+ wantCursor: 0,
+ wantOffset: 0,
+ },
+ {
+ name: "cursor below visible window scrolls down",
+ tasks: tasks,
+ height: 7,
+ cursor: 2,
+ offset: 0,
+ wantCursor: 2,
+ wantOffset: 1,
+ },
+ {
+ name: "cursor card taller than viewport scrolls directly to cursor",
+ tasks: []task.Task{
+ {ID: 1, UUID: "1", Description: "alpha", Status: "pending"},
+ {ID: 2, UUID: "2", Description: strings.Repeat("long description ", 30), Status: "pending"},
+ {ID: 3, UUID: "3", Description: "charlie", Status: "pending"},
+ },
+ height: 5,
+ cursor: 1,
+ offset: 0,
+ wantCursor: 1,
+ wantOffset: 1,
+ },
+ }
+
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ m, err := NewWithTaskwarrior(nil, "firefox", &fakeTaskwarrior{tasks: tt.tasks})
+ if err != nil {
+ t.Fatalf("NewWithTaskwarrior: %v", err)
+ }
+ m.tbl.SetWidth(60)
+ m.windowHeight = tt.height
+ m.ultraCursor = tt.cursor
+ m.ultraOffset = tt.offset
+
+ m.ultraEnsureVisible()
+
+ if got := m.ultraCursor; got != tt.wantCursor {
+ t.Fatalf("cursor = %d, want %d", got, tt.wantCursor)
+ }
+ if got := m.ultraOffset; got != tt.wantOffset {
+ t.Fatalf("offset = %d, want %d", got, tt.wantOffset)
+ }
+ })
+ }
+}
+
func TestUltraBlinkUsesVisibleSelectionAndRendersBlink(t *testing.T) {
tmp := t.TempDir()
taskPath := setupUltraTaskSet(t, tmp)