mirror of
https://git.sr.ht/~joren/streamrip-go
synced 2026-06-17 15:05:39 +02:00
improve search menu preview and artist release details
This commit is contained in:
87
cmd/rip/search_test.go
Normal file
87
cmd/rip/search_test.go
Normal file
@@ -0,0 +1,87 @@
|
||||
package main
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestFormatSearchDetailsAlbum(t *testing.T) {
|
||||
r := searchResult{ID: "9399700017915", Date: "1994-02-01", TrackCount: 18}
|
||||
got := formatSearchDetails("album", r)
|
||||
want := "Date released:\n1994-02-01\n\n18 Tracks\n\nID: 9399700017915"
|
||||
if got != want {
|
||||
t.Fatalf("unexpected album details:\n%s", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFormatSearchDetailsTrackDefaultsDate(t *testing.T) {
|
||||
r := searchResult{ID: "3083287"}
|
||||
got := formatSearchDetails("track", r)
|
||||
want := "Released on:\nUnknown\n\nID: 3083287"
|
||||
if got != want {
|
||||
t.Fatalf("unexpected track details:\n%s", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFormatSearchDetailsArtistWithReleases(t *testing.T) {
|
||||
r := searchResult{ID: "1863897", Title: "Lost Frequencies", Releases: 23}
|
||||
got := formatSearchDetails("artist", r)
|
||||
want := "Lost Frequencies\n\n23 Releases\n\nID: 1863897"
|
||||
if got != want {
|
||||
t.Fatalf("unexpected artist details:\n%s", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNormalizeSearchResultsQobuzExtractsDate(t *testing.T) {
|
||||
pages := []map[string]any{
|
||||
{"albums": map[string]any{"items": []any{
|
||||
map[string]any{
|
||||
"id": "1",
|
||||
"title": "Master of Reality",
|
||||
"release_date_original": "1971-07-21",
|
||||
"artist": map[string]any{"name": "Black Sabbath"},
|
||||
},
|
||||
}}},
|
||||
}
|
||||
results := normalizeSearchResults("qobuz", "album", pages)
|
||||
if len(results) != 1 {
|
||||
t.Fatalf("len(results)=%d want 1", len(results))
|
||||
}
|
||||
if results[0].Date != "1971-07-21" {
|
||||
t.Fatalf("date=%q want 1971-07-21", results[0].Date)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFormatSearchOptionLabelArtistNoUnknownArtistSuffix(t *testing.T) {
|
||||
r := searchResult{Title: "Lost Frequencies"}
|
||||
got := formatSearchOptionLabel(1, "artist", r)
|
||||
want := "1. Lost Frequencies"
|
||||
if got != want {
|
||||
t.Fatalf("label=%q want %q", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFormatSearchOptionLabelTrackWithArtist(t *testing.T) {
|
||||
r := searchResult{Title: "Dreams", Artist: "Fleetwood Mac"}
|
||||
got := formatSearchOptionLabel(2, "track", r)
|
||||
want := "2. Dreams by Fleetwood Mac"
|
||||
if got != want {
|
||||
t.Fatalf("label=%q want %q", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNormalizeSearchResultsQobuzArtistExtractsReleases(t *testing.T) {
|
||||
pages := []map[string]any{
|
||||
{"artists": map[string]any{"items": []any{
|
||||
map[string]any{
|
||||
"id": "1863897",
|
||||
"name": "Lost Frequencies",
|
||||
"albums_count": 23,
|
||||
},
|
||||
}}},
|
||||
}
|
||||
results := normalizeSearchResults("qobuz", "artist", pages)
|
||||
if len(results) != 1 {
|
||||
t.Fatalf("len(results)=%d want 1", len(results))
|
||||
}
|
||||
if results[0].Releases != 23 {
|
||||
t.Fatalf("releases=%d want 23", results[0].Releases)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user