▍ humdrum codex / sportsball v0.1.0
license AGPL-3.0
1.1 KB raw
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package ui

import (
	"testing"
	"time"

	"github.com/humdrum-tiv/sportsball/internal/model"
)

// Up/Down must move by visual grid row (keeping column), not ±1 through the
// flat list. With 3 cards in a 2-wide grid the rows are [[0,1],[2]].
func TestMoveCursorVertical(t *testing.T) {
	now := time.Now()
	a := App{
		width:   80, // columns() => 80/(cardWidth+3) = 2
		leagues: model.Leagues,
		filter:  model.MLB,
		games: map[model.LeagueID][]model.Game{
			model.MLB: {
				{ID: "g0", League: model.MLB, State: model.StatePre, Start: now},
				{ID: "g1", League: model.MLB, State: model.StatePre, Start: now},
				{ID: "g2", League: model.MLB, State: model.StatePre, Start: now},
			},
		},
	}
	if c := a.columns(); c != 2 {
		t.Fatalf("expected 2 columns at width 80, got %d", c)
	}

	a.cursor = 1 // top-right (row0,col1)
	a.moveCursorVert(1)
	if a.cursor != 2 { // down → row1 only has col0, clamps to g2
		t.Errorf("down from 1 = %d, want 2", a.cursor)
	}
	a.moveCursorVert(-1) // back up → row0 col0
	if a.cursor != 0 {
		t.Errorf("up from 2 = %d, want 0", a.cursor)
	}
}