2022-01-26 06:54:36 -08:00
|
|
|
package segments
|
2020-11-19 19:12:20 -08:00
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
2022-01-26 01:23:18 -08:00
|
|
|
"oh-my-posh/mock"
|
2022-01-26 04:53:35 -08:00
|
|
|
"oh-my-posh/properties"
|
2020-11-19 19:12:20 -08:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
2022-01-26 05:10:18 -08:00
|
|
|
func bootstrapYTMDATest(json string, err error) *Ytm {
|
2021-04-20 12:35:22 -07:00
|
|
|
url := "http://127.0.0.1:9863"
|
2022-01-26 01:23:18 -08:00
|
|
|
env := new(mock.MockedEnvironment)
|
2022-01-07 10:41:58 -08:00
|
|
|
env.On("HTTPRequest", url+"/query").Return([]byte(json), err)
|
2022-01-26 05:10:18 -08:00
|
|
|
ytm := &Ytm{
|
2021-11-26 01:37:33 -08:00
|
|
|
env: env,
|
2022-01-26 04:53:35 -08:00
|
|
|
props: properties.Map{
|
2020-11-19 19:12:20 -08:00
|
|
|
APIURL: url,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
return ytm
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestYTMDAPlaying(t *testing.T) {
|
|
|
|
json := `{ "player": { "hasSong": true, "isPaused": false }, "track": { "author": "Candlemass", "title": "Spellbreaker" } }`
|
|
|
|
ytm := bootstrapYTMDATest(json, nil)
|
|
|
|
err := ytm.setStatus()
|
|
|
|
assert.NoError(t, err)
|
2022-01-22 10:46:56 -08:00
|
|
|
assert.Equal(t, "playing", ytm.Status)
|
|
|
|
assert.Equal(t, "Candlemass", ytm.Artist)
|
|
|
|
assert.Equal(t, "Spellbreaker", ytm.Track)
|
2020-11-19 19:12:20 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestYTMDAPaused(t *testing.T) {
|
|
|
|
json := `{ "player": { "hasSong": true, "isPaused": true }, "track": { "author": "Candlemass", "title": "Spellbreaker" } }`
|
|
|
|
ytm := bootstrapYTMDATest(json, nil)
|
|
|
|
err := ytm.setStatus()
|
|
|
|
assert.NoError(t, err)
|
2022-01-22 10:46:56 -08:00
|
|
|
assert.Equal(t, "paused", ytm.Status)
|
|
|
|
assert.Equal(t, "Candlemass", ytm.Artist)
|
|
|
|
assert.Equal(t, "Spellbreaker", ytm.Track)
|
2020-11-19 19:12:20 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestYTMDAStopped(t *testing.T) {
|
|
|
|
json := `{ "player": { "hasSong": false }, "track": { "author": "", "title": "" } }`
|
|
|
|
ytm := bootstrapYTMDATest(json, nil)
|
|
|
|
err := ytm.setStatus()
|
|
|
|
assert.NoError(t, err)
|
2022-01-22 10:46:56 -08:00
|
|
|
assert.Equal(t, "stopped", ytm.Status)
|
|
|
|
assert.Equal(t, "", ytm.Artist)
|
|
|
|
assert.Equal(t, "", ytm.Track)
|
2020-11-19 19:12:20 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestYTMDAError(t *testing.T) {
|
|
|
|
json := `{ "player": { "hasSong": false }, "track": { "author": "", "title": "" } }`
|
|
|
|
ytm := bootstrapYTMDATest(json, errors.New("Oh noes"))
|
2022-01-26 05:26:56 -08:00
|
|
|
enabled := ytm.Enabled()
|
2020-11-19 19:12:20 -08:00
|
|
|
assert.False(t, enabled)
|
|
|
|
}
|