Announce finished and failed downloads in the background (M10)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package ui
|
||||
|
||||
import (
|
||||
"git.stinnesbeck.com/nils/arr-tui/internal/sabnzbd"
|
||||
"testing"
|
||||
|
||||
"github.com/rivo/tview"
|
||||
@@ -39,3 +40,39 @@ func TestOnlyFullOverlays(t *testing.T) {
|
||||
t.Error("a dialog must block view shortcuts")
|
||||
}
|
||||
}
|
||||
|
||||
func TestDiffHistory(t *testing.T) {
|
||||
slot := func(id, name, status string) sabnzbd.HistorySlot {
|
||||
return sabnzbd.HistorySlot{ID: id, Name: name, Status: status, FailMessage: map[bool]string{true: "disk full"}[status == "Failed"]}
|
||||
}
|
||||
seen := map[string]string{}
|
||||
|
||||
// The first poll only records what is already there.
|
||||
if ev := diffHistory(seen, []sabnzbd.HistorySlot{slot("1", "old", "Completed"), slot("2", "old fail", "Failed")}, true); len(ev) != 0 {
|
||||
t.Fatalf("baseline produced %v", ev)
|
||||
}
|
||||
// Nothing new.
|
||||
if ev := diffHistory(seen, []sabnzbd.HistorySlot{slot("1", "old", "Completed")}, false); len(ev) != 0 {
|
||||
t.Fatalf("unchanged history produced %v", ev)
|
||||
}
|
||||
// A new job that is still being processed is not final yet.
|
||||
if ev := diffHistory(seen, []sabnzbd.HistorySlot{slot("3", "movie", "Extracting")}, false); len(ev) != 0 {
|
||||
t.Fatalf("extracting produced %v", ev)
|
||||
}
|
||||
// It completes, a second one fails, a third appears already completed.
|
||||
ev := diffHistory(seen, []sabnzbd.HistorySlot{
|
||||
slot("3", "movie", "Completed"), slot("4", "show", "Failed"), slot("5", "quick", "Completed"), slot("1", "old", "Completed"),
|
||||
}, false)
|
||||
if len(ev) != 3 || ev[0].name != "movie" || ev[0].failed || ev[1].name != "show" || !ev[1].failed || ev[1].message != "disk full" || ev[2].name != "quick" {
|
||||
t.Fatalf("events = %+v", ev)
|
||||
}
|
||||
// Reported once only.
|
||||
if ev := diffHistory(seen, []sabnzbd.HistorySlot{slot("3", "movie", "Completed"), slot("4", "show", "Failed")}, false); len(ev) != 0 {
|
||||
t.Errorf("repeated: %+v", ev)
|
||||
}
|
||||
// A retried job that completes later is reported again.
|
||||
diffHistory(seen, []sabnzbd.HistorySlot{slot("4", "show", "Queued")}, false)
|
||||
if ev := diffHistory(seen, []sabnzbd.HistorySlot{slot("4", "show", "Completed")}, false); len(ev) != 1 {
|
||||
t.Errorf("retry: %+v", ev)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user