package ui import ( "testing" tea "github.com/charmbracelet/bubbletea" "github.com/gmgauthier/gostations/internal/radio" ) func TestApp_BasicKeyHandling(t *testing.T) { app := NewApp([]radio.Station{ {Name: "Test1", Url: "http://a", Codec: "MP3", Bitrate: "128"}, }) // Send q model, cmd := app.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{'q'}}) if !model.(*App).quitting { t.Error("q did not set quitting") } _ = cmd // Send window size model, _ = app.Update(tea.WindowSizeMsg{Width: 80, Height: 24}) a := model.(*App) if a.list.Width() == 0 { t.Log("list size not updated (may be ok in test)") } } func TestApp_AutoFilterOnTyping(t *testing.T) { app := NewApp([]radio.Station{ {Name: "WFMT 98.7", Url: "http://wfmt", Codec: "MP3", Bitrate: "128", Tags: "chicago,classical"}, {Name: "Other Station", Url: "http://other", Codec: "AAC", Bitrate: "64", Tags: "news"}, }) // Simulate typing 'W' (should auto enter filter and filter to WFMT) model, _ := app.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{'W'}}) a := model.(*App) // After auto filter start + 'W', the filter value should be "W" and state Filtering or applied fv := a.list.FilterValue() if fv != "W" { t.Errorf("expected filter value 'W' after typing W, got %q", fv) } // The visible items should be filtered (at least the WFMT one should match) visible := a.list.VisibleItems() if len(visible) == 0 { t.Error("expected some visible items after filter 'W'") } // Check that 'Other' is not the only one, or better, since fuzzy, 'W' may match others weakly, but at least not empty }