Series drill-down: season posters

The drill-down reads the series with includeSeasonImages=true (Sonarr
only sends season posters when asked, as TheTVDB links). A selected
season or episode shows its season's poster; without one, or when it
cannot be loaded, the series poster.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-23 23:42:49 +02:00
co-authored by Claude Opus 5.5
parent 73efe279d4
commit ca28a3c9bb
7 changed files with 92 additions and 2 deletions
+37
View File
@@ -1,6 +1,9 @@
package ui
import (
"context"
"net/http"
"net/http/httptest"
"slices"
"strings"
"testing"
@@ -308,3 +311,37 @@ func TestCutToWidth(t *testing.T) {
}
}
}
func TestSeasonPoster(t *testing.T) {
seasonSrv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path == "/broken.jpg" {
http.NotFound(w, r)
return
}
w.Write([]byte("SEASON"))
}))
defer seasonSrv.Close()
series := coverRef{key: "series", fetch: func(context.Context, bool) ([]byte, error) { return []byte("SERIES"), nil }}
v := &seriesView{cover: series, series: sonarr.Series{Seasons: []sonarr.Season{
{SeasonNumber: 1, Images: []arr.Image{{CoverType: "poster", RemoteURL: seasonSrv.URL + "/s1.jpg"}}},
{SeasonNumber: 2},
{SeasonNumber: 3, Images: []arr.Image{{CoverType: "poster", RemoteURL: seasonSrv.URL + "/broken.jpg"}}},
}}}
fetch := func(season int) string {
data, err := v.seasonCover(season).fetch(t.Context(), false)
if err != nil {
t.Fatal(err)
}
return string(data)
}
if got := fetch(1); got != "SEASON" || v.seasonCover(1).key == series.key {
t.Errorf("season 1: %q", got)
}
if v.seasonCover(2).key != series.key {
t.Error("a season without a poster shows the series poster")
}
if got := fetch(3); got != "SERIES" {
t.Errorf("a season poster that cannot be loaded falls back to the series poster: %q", got)
}
}