internal/selection_labels_test.go
75 lines · 2384 bytes
5 symbols in this file
1package internal
2
3import (
4 "strings"
5 "testing"
6
7 "github.com/wraient/curd/internal/providers/animepahe"
8)
9
10func TestFormatAnimeSearchLabel(t *testing.T) {
11 if got := FormatAnimeSearchLabel("Frieren", 28); got != "Frieren (28 episodes)" {
12 t.Fatalf("unexpected label: %q", got)
13 }
14 if got := FormatAnimeSearchLabel("Airing Show", 0); got != "Airing Show" {
15 t.Fatalf("unexpected label without episodes: %q", got)
16 }
17}
18
19func TestProviderSearchOptionsForDisplayMarksEpisodeMatch(t *testing.T) {
20 options := []SelectionOption{
21 {Key: "a", Label: "One Piece (1090 episodes) [allanime]", Title: "One Piece"},
22 {Key: "b", Label: "One Pace (300 episodes) [anineko]", Title: "One Pace"},
23 }
24 entry := &Entry{Media: Media{Episodes: 1090}}
25
26 display := ProviderSearchOptionsForDisplay(options, entry)
27 if display[0].Label != "One Piece (1090 episodes) [allanime] ✓" {
28 t.Fatalf("expected match marker on first option, got %q", display[0].Label)
29 }
30 if display[1].Label != "One Pace (300 episodes) [anineko]" {
31 t.Fatalf("expected unchanged second option, got %q", display[1].Label)
32 }
33}
34
35func TestManualProviderSearchHint(t *testing.T) {
36 entry := &Entry{
37 Media: Media{
38 Format: "TV",
39 Episodes: 24,
40 Title: AnimeTitle{
41 Romaji: "Frieren",
42 },
43 },
44 }
45 hint := ManualProviderSearchHint(&CurdConfig{SubOrDub: "sub"}, entry, "frieren", "sub")
46 if !strings.Contains(hint, `Searching for "Frieren"`) {
47 t.Fatalf("unexpected hint: %q", hint)
48 }
49 if !strings.Contains(hint, "TV") || !strings.Contains(hint, "24 episodes") || !strings.Contains(hint, "sub") {
50 t.Fatalf("expected type, episode count, and mode in hint: %q", hint)
51 }
52}
53
54func TestManualProviderSearchEnabled(t *testing.T) {
55 if ManualProviderSearchEnabled(&CurdConfig{ManualProviderSearch: true}) != true {
56 t.Fatal("expected manual provider search to be enabled")
57 }
58 if ManualProviderSearchEnabled(&CurdConfig{}) != false {
59 t.Fatal("expected manual provider search to be disabled by default")
60 }
61}
62
63func TestEnsureEpisodeCountInLabelUsesExtraData(t *testing.T) {
64 option := SelectionOption{
65 Key: "session",
66 Label: "Frieren [animepahe]",
67 Title: "Frieren",
68 ExtraData: animepahe.SearchItem{Title: "Frieren", Episodes: 28},
69 }
70
71 display := ensureEpisodeCountInLabel(option)
72 if display.Label != "Frieren (28 episodes) [animepahe]" {
73 t.Fatalf("unexpected label: %q", display.Label)
74 }
75}