Files
bjarneo--cliamp/ui/model/notifier_attach_test.go
wehub-resource-sync ead81af521
Deploy to GitHub Pages / deploy (push) Failing after 0s
CI / go (push) Has been cancelled
CI / build (darwin, macos-14) (push) Has been cancelled
CI / build (windows, windows-2025) (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:31:13 +08:00

62 lines
1.3 KiB
Go

package model
import (
"testing"
"time"
"github.com/bjarneo/cliamp/internal/playback"
"github.com/bjarneo/cliamp/playlist"
)
type fakeNotifier struct {
updates []playback.State
seeked []time.Duration
}
func (f *fakeNotifier) Update(state playback.State) {
f.updates = append(f.updates, state)
}
func (f *fakeNotifier) Seeked(position time.Duration) {
f.seeked = append(f.seeked, position)
}
func TestAttachNotifierPublishesCurrentPlaybackState(t *testing.T) {
pl := playlist.New()
pl.Add(playlist.Track{
Title: "Song",
Artist: "Artist",
Album: "Album",
Path: "/tmp/song.mp3",
})
notifier := &fakeNotifier{}
m := Model{
player: &fakeEngine{},
playlist: pl,
}
next, _ := m.Update(AttachNotifier(notifier))
nextModel := next.(Model)
if nextModel.notifier != notifier {
t.Fatal("notifier was not attached to model")
}
if len(notifier.updates) != 1 {
t.Fatalf("notifier update count = %d, want 1", len(notifier.updates))
}
want := playback.State{
Status: playback.StatusPlaying,
Track: playback.Track{
Title: "Song",
Artist: "Artist",
Album: "Album",
URL: "/tmp/song.mp3",
Duration: time.Hour,
},
}
if got := notifier.updates[0]; got != want {
t.Fatalf("notifier update = %#v, want %#v", got, want)
}
}