Sonarr client with lookup, add series (monitor modes) and search. Refactor the movie view into a generic search view driven by a backend interface so Movies and Series share one implementation. Add F1-F4 / Alt+1-4 view switching that works while typing. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
89 lines
3.0 KiB
Go
89 lines
3.0 KiB
Go
package ui
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
|
|
"git.stinnesbeck.com/nils/arr-tui/internal/arr"
|
|
"git.stinnesbeck.com/nils/arr-tui/internal/radarr"
|
|
"git.stinnesbeck.com/nils/arr-tui/internal/sonarr"
|
|
)
|
|
|
|
func TestMovieLabel(t *testing.T) {
|
|
if got := movieLabel(radarr.Movie{Title: "Alien", Year: 1979}); got != "Alien (1979)" {
|
|
t.Errorf("got %q", got)
|
|
}
|
|
if got := movieLabel(radarr.Movie{ID: 3, Title: "Alien", Year: 1979}); !strings.Contains(got, "✓") {
|
|
t.Errorf("in-library marker missing: %q", got)
|
|
}
|
|
// tview color tags in titles must be escaped
|
|
if got := movieLabel(radarr.Movie{Title: "[red]x"}); strings.Contains(got, "[red]x") {
|
|
t.Errorf("title not escaped: %q", got)
|
|
}
|
|
}
|
|
|
|
func TestMovieDetails(t *testing.T) {
|
|
got := movieDetails(radarr.Movie{
|
|
ID: 1, Title: "Alien", Year: 1979, Runtime: 117, Genres: []string{"Horror", "Sci-Fi"},
|
|
Overview: "In space...", Ratings: radarr.Ratings{IMDB: &radarr.Rating{Value: 8.5}},
|
|
})
|
|
for _, want := range []string{"Alien (1979)", "★ 8.5", "1h57m", "Horror, Sci-Fi", "In library, not downloaded", "In space..."} {
|
|
if !strings.Contains(got, want) {
|
|
t.Errorf("details missing %q:\n%s", want, got)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestDefaultIndexes(t *testing.T) {
|
|
profiles := []arr.QualityProfile{{Name: "Any"}, {Name: "HD-1080p"}}
|
|
if profileIndex(profiles, "hd-1080p") != 1 || profileIndex(profiles, "nope") != 0 {
|
|
t.Error("profileIndex")
|
|
}
|
|
folders := []arr.RootFolder{{Path: "/a"}, {Path: "/movies/"}}
|
|
if folderIndex(folders, "/movies") != 1 || folderIndex(folders, "") != 0 {
|
|
t.Error("folderIndex")
|
|
}
|
|
}
|
|
|
|
func TestSeriesLabelAndDetails(t *testing.T) {
|
|
s := sonarr.Series{
|
|
Title: "Breaking Bad", Year: 2008, Network: "AMC", Status: "ended", Runtime: 47,
|
|
Genres: []string{"Crime"},
|
|
Ratings: sonarr.Rating{Value: 9.3},
|
|
Seasons: []sonarr.Season{{SeasonNumber: 0}, {SeasonNumber: 1}},
|
|
}
|
|
if got := seriesLabel(s); got != "Breaking Bad (2008)" {
|
|
t.Errorf("label = %q", got)
|
|
}
|
|
got := seriesDetails(s)
|
|
for _, want := range []string{"Breaking Bad (2008)", "★ 9.3", "1 season ·", "47 min", "Network: AMC", "Status: ended"} {
|
|
if !strings.Contains(got, want) {
|
|
t.Errorf("details missing %q:\n%s", want, got)
|
|
}
|
|
}
|
|
|
|
s.ID = 1
|
|
s.Statistics = sonarr.Statistics{EpisodeCount: 10, EpisodeFileCount: 4}
|
|
if got := seriesDetails(s); !strings.Contains(got, "4/10 episodes") {
|
|
t.Errorf("progress missing:\n%s", got)
|
|
}
|
|
s.Statistics.EpisodeFileCount = 10
|
|
if got := seriesDetails(s); !strings.Contains(got, "all episodes downloaded") {
|
|
t.Errorf("complete marker missing:\n%s", got)
|
|
}
|
|
}
|
|
|
|
func TestResultKeysAndWithID(t *testing.T) {
|
|
var r result = movieResult{radarr.Movie{TMDBID: 603, Title: "x"}}
|
|
if r.key() != "tmdb:603" || r.inLibrary() {
|
|
t.Fatalf("movie key/inLibrary: %q %v", r.key(), r.inLibrary())
|
|
}
|
|
if added := r.withID(5); !added.inLibrary() || r.inLibrary() {
|
|
t.Error("withID must return a flagged copy and leave the original alone")
|
|
}
|
|
r = seriesResult{sonarr.Series{TVDBID: 81189}}
|
|
if r.key() != "tvdb:81189" {
|
|
t.Errorf("series key = %q", r.key())
|
|
}
|
|
}
|