package handlers_test import ( "slices" "testing" "github.com/StevanFreeborn/term-tier/internal/core" "github.com/StevanFreeborn/term-tier/internal/handlers" "github.com/StevanFreeborn/term-tier/internal/state" tea "github.com/charmbracelet/bubbletea" ) func TestNewRightNavigationHandler(t *testing.T) { h := handlers.NewRightNavigationHandler() if h.Description() != "Move right" { t.Errorf("Expected description 'Move right', got %q", h.Description()) } keys := h.KeysHandled() if !slices.Contains(keys, "right") || !slices.Contains(keys, "l") { t.Errorf("Expected keys ['right', 'l'], got %v", keys) } } func TestRightNavigationHandler_Match(t *testing.T) { h := handlers.NewRightNavigationHandler() tests := []struct { name string mode state.Mode key string expected bool }{ { name: "Matches 'right' in Navigation Mode", mode: state.NavigationMode, key: "right", expected: true, }, { name: "Matches 'l' in Navigation Mode", mode: state.NavigationMode, key: "l", expected: true, }, { name: "Ignores 'right' in Input Mode", mode: state.InputMode, key: "right", expected: false, }, { name: "Ignores 'l' in Input Mode", mode: state.InputMode, key: "l", expected: false, }, { name: "Ignores other keys in Navigation Mode", mode: state.NavigationMode, key: "left", expected: false, }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { s := state.New(state.WithMode(tt.mode)) msg := tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune(tt.key)} if tt.key == "right" { msg = tea.KeyMsg{Type: tea.KeyRight} } if got := h.Match(s, msg); got != tt.expected { t.Errorf("Match() = %v, want %v", got, tt.expected) } }) } } func TestRightNavigationHandler_Handle(t *testing.T) { h := handlers.NewRightNavigationHandler() tiers := make([]core.Tier, 6) tiers[0] = core.Tier{Name: "S", Items: []core.Item{"A", "B"}} s := state.New( state.WithTiers(tiers), state.WithCursor(0, 0), state.WithMode(state.NavigationMode), ) msg := tea.KeyMsg{Type: tea.KeyRight} cmd := h.Handle(s, msg) if s.CursorCol() != 1 { t.Errorf("Expected cursor to move to Col 1, got %d", s.CursorCol()) } if cmd != nil { t.Error("Expected Handle to return nil, got a command") } }