2020-11-04 23:56:12 -08:00
|
|
|
// +build darwin
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
type spotifyArgs struct {
|
2020-11-12 00:43:32 -08:00
|
|
|
running string
|
|
|
|
status string
|
|
|
|
artist string
|
|
|
|
track string
|
|
|
|
runError error
|
2020-11-04 23:56:12 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
func bootStrapSpotifyDarwinTest(args *spotifyArgs) *spotify {
|
|
|
|
env := new(MockedEnvironment)
|
2020-11-12 00:43:32 -08:00
|
|
|
env.On("runCommand", "osascript", []string{"-e", "application \"Spotify\" is running"}).Return(args.running, args.runError)
|
|
|
|
env.On("runCommand", "osascript", []string{"-e", "tell application \"Spotify\" to player state as string"}).Return(args.status, nil)
|
|
|
|
env.On("runCommand", "osascript", []string{"-e", "tell application \"Spotify\" to artist of current track as string"}).Return(args.artist, nil)
|
|
|
|
env.On("runCommand", "osascript", []string{"-e", "tell application \"Spotify\" to name of current track as string"}).Return(args.track, nil)
|
2020-11-04 23:56:12 -08:00
|
|
|
props := &properties{}
|
|
|
|
s := &spotify{
|
|
|
|
env: env,
|
|
|
|
props: props,
|
|
|
|
}
|
|
|
|
return s
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestSpotifyDarwinEnabledAndSpotifyNotRunning(t *testing.T) {
|
|
|
|
args := &spotifyArgs{
|
2020-11-12 00:43:32 -08:00
|
|
|
running: "false",
|
2020-11-04 23:56:12 -08:00
|
|
|
}
|
|
|
|
s := bootStrapSpotifyDarwinTest(args)
|
|
|
|
assert.Equal(t, false, s.enabled())
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestSpotifyDarwinEnabledAndSpotifyPlaying(t *testing.T) {
|
|
|
|
args := &spotifyArgs{
|
2020-11-12 00:43:32 -08:00
|
|
|
running: "true",
|
|
|
|
status: "playing",
|
|
|
|
artist: "Candlemass",
|
|
|
|
track: "Spellbreaker",
|
2020-11-04 23:56:12 -08:00
|
|
|
}
|
|
|
|
s := bootStrapSpotifyDarwinTest(args)
|
|
|
|
assert.Equal(t, true, s.enabled())
|
|
|
|
assert.Equal(t, "\ue602 Candlemass - Spellbreaker", s.string())
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestSpotifyDarwinEnabledAndSpotifyPaused(t *testing.T) {
|
|
|
|
args := &spotifyArgs{
|
2020-11-12 00:43:32 -08:00
|
|
|
running: "true",
|
|
|
|
status: "paused",
|
|
|
|
artist: "Candlemass",
|
|
|
|
track: "Spellbreaker",
|
2020-11-04 23:56:12 -08:00
|
|
|
}
|
|
|
|
s := bootStrapSpotifyDarwinTest(args)
|
|
|
|
assert.Equal(t, true, s.enabled())
|
|
|
|
assert.Equal(t, "\uF8E3 Candlemass - Spellbreaker", s.string())
|
|
|
|
}
|