feat(cli): default to bubbles TUI, add find/play subcmds + JSON favorites
- implement internal/ui with bubbles list + ★ fav markers, filter, enter stub
- add data/favorites (JSON roundtrip, Add/Remove, XDG), config tests
- wire subcommands: `find -j`, `play [url|search]`
- gate legacy wmenu behind --legacy; keep old flags for seeding
- fix inverted -short guards, format string, go.mod deps
- add unit tests for radio prune, player IsInstalled, ui keys, etc.
2026-06-05 20:23:11 +00:00
|
|
|
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)")
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-06-05 20:36:49 +00:00
|
|
|
|
|
|
|
|
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
|
|
|
|
|
}
|