Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions internal/anisearch/anisearch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"testing"
"time"

"github.com/calmcacil/CalmsToolkit/internal/colors"
"github.com/calmcacil/CalmsToolkit/internal/config"
"github.com/calmcacil/CalmsToolkit/internal/core"
"github.com/klauspost/compress/zstd"
Expand Down Expand Up @@ -702,6 +703,34 @@ func TestTruncateVis(t *testing.T) {
}
}

func TestRenderSearchResultsLayout(t *testing.T) {
title := "Frieren: Beyond Journey’s End"
episodes := 28
score := 91
result := &SearchResult{
Media: []Show{{
Title: Title{English: &title},
Format: "TV",
Episodes: &episodes,
AverageRank: &score,
Status: "FINISHED",
}},
PageInfo: PageInfo{CurrentPage: 1, HasNextPage: true},
}

output := renderSearchResults("Frieren", result, -1, nil, ToolConfig{CommonConfig: core.CommonConfig{NoColor: true}})
if !strings.Contains(output, "[TV] 28 eps · 91% [Finished]") {
t.Fatalf("search result metadata is not spaced correctly:\n%s", output)
}

const wantWidth = 80
for i, line := range strings.Split(strings.TrimSuffix(output, "\n"), "\n") {
if got := colors.VisibleLen(line); got != wantWidth {
t.Errorf("line %d width = %d, want %d: %q", i+1, got, wantWidth, line)
}
}
}

func TestFormatEpisodes(t *testing.T) {
tests := []struct {
name string
Expand Down
6 changes: 3 additions & 3 deletions internal/anisearch/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ func innerWidth() int {
if w < 40 {
w = 40
}
if w > 100 {
w = 100
if w > 80 {
w = 80
}
return w - 2 // subtract box borders
}
Expand Down Expand Up @@ -123,7 +123,7 @@ func formatSearchLine(num int, show Show, highlighted bool, mapping *AnibridgeMa
scoreLabel = fmt.Sprintf(" · %s%d%%%s", clr(p.Accent), *show.AverageRank, clr(p.Reset))
}

meta := fmt.Sprintf(" %s% s%s%s", clr(p.Subdued), fmtBadge, epLabel, scoreLabel)
meta := fmt.Sprintf(" %s%s %s%s", clr(p.Subdued), fmtBadge, epLabel, scoreLabel)

// Status indicator
statusLabel := ""
Expand Down