43 lines
1.3 KiB
Go
43 lines
1.3 KiB
Go
package cli
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/steipete/spogo/internal/output"
|
|
"github.com/steipete/spogo/internal/spotify"
|
|
"github.com/steipete/spogo/internal/testutil"
|
|
)
|
|
|
|
func TestRenderItemsHuman(t *testing.T) {
|
|
ctx, out, _ := testutil.NewTestContext(t, output.FormatHuman)
|
|
items := []spotify.Item{{ID: "t1", Name: "Song", Type: "track", Artists: []string{"Artist"}, Album: "Album"}}
|
|
plain, human := renderItems(ctx.Output, items)
|
|
if len(plain) == 0 || len(human) == 0 {
|
|
t.Fatalf("expected lines")
|
|
}
|
|
_ = ctx.Output.Emit(items, plain, human)
|
|
if out.String() == "" {
|
|
t.Fatalf("expected output")
|
|
}
|
|
}
|
|
|
|
func TestPlaybackFormatting(t *testing.T) {
|
|
ctx, _, _ := testutil.NewTestContext(t, output.FormatHuman)
|
|
status := spotify.PlaybackStatus{IsPlaying: true, ProgressMS: 120000, Device: spotify.Device{Name: "Desk"}, Item: &spotify.Item{Name: "Song", Artists: []string{"Artist"}}}
|
|
if playbackPlain(status) == "" {
|
|
t.Fatalf("expected plain")
|
|
}
|
|
if playbackHuman(ctx.Output, status) == "" {
|
|
t.Fatalf("expected human")
|
|
}
|
|
}
|
|
|
|
func TestPlaylistRenderOmitsZeroTracks(t *testing.T) {
|
|
ctx, _, _ := testutil.NewTestContext(t, output.FormatHuman)
|
|
line := itemHuman(ctx.Output, spotify.Item{Type: "playlist", Name: "List", Owner: "Peter"})
|
|
if strings.Contains(line, "0 tracks") {
|
|
t.Fatalf("unexpected track count: %s", line)
|
|
}
|
|
}
|