Files
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

59 lines
1.7 KiB
Go

package model
import "testing"
func TestSaveStateActivityTextTracksPendingDownloads(t *testing.T) {
var save saveState
if got := save.activityText(); got != "" {
t.Fatalf("activityText() = %q, want empty", got)
}
save.startDownload()
if got := save.activityText(); got != "Downloading..." {
t.Fatalf("activityText() after first start = %q, want %q", got, "Downloading...")
}
save.startDownload()
if got := save.activityText(); got != "Downloading... (2)" {
t.Fatalf("activityText() after second start = %q, want %q", got, "Downloading... (2)")
}
save.finishDownload()
if got := save.activityText(); got != "Downloading..." {
t.Fatalf("activityText() after first finish = %q, want %q", got, "Downloading...")
}
save.finishDownload()
if got := save.activityText(); got != "" {
t.Fatalf("activityText() after second finish = %q, want empty", got)
}
}
func TestYTDLSavedMsgKeepsSaveActivityWhileDownloadsRemain(t *testing.T) {
m := Model{
save: saveState{
pendingDownloads: 2,
},
}
nextModel, cmd := m.Update(ytdlSavedMsg{path: "/tmp/song.mp3"})
if cmd != nil {
t.Fatalf("Update() cmd = %v, want nil", cmd)
}
next, ok := nextModel.(Model)
if !ok {
t.Fatalf("Update() model = %T, want ui.Model", nextModel)
}
if next.save.pendingDownloads != 1 {
t.Fatalf("pendingDownloads after ytdlSavedMsg = %d, want 1", next.save.pendingDownloads)
}
if got := next.save.activityText(); got != "Downloading..." {
t.Fatalf("activityText() after ytdlSavedMsg = %q, want %q", got, "Downloading...")
}
if got := next.status.text; got != "Saved to /tmp/song.mp3" {
t.Fatalf("status.text after ytdlSavedMsg = %q, want %q", got, "Saved to /tmp/song.mp3")
}
}