1
0
mirror of https://github.com/danbee/mpd-client synced 2025-03-04 08:39:09 +00:00

WIP: More spec stuff.

This commit is contained in:
Dan Barber 2014-04-08 16:43:02 +01:00
parent fadb576d76
commit 9e890265fa
4 changed files with 62 additions and 4 deletions

View File

@ -1,10 +1,6 @@
mpdClient.controller('transport', function ($scope, api, serverEvents) {
$scope.status = {}
api.getStatus().success(function (data, status, headers, config) {
$scope.updateStatus(data)
})
$scope.updateStatus = function(data) {
$scope.status = data
if (data.time) { $scope.updateTime(data.time) }
@ -29,6 +25,10 @@ mpdClient.controller('transport', function ($scope, api, serverEvents) {
return ($scope.elapsedTime / $scope.totalTime) * 100
}
api.getStatus().success(function (data, status, headers, config) {
$scope.updateStatus(data)
})
$scope.$on('update:status', function (evt, data) { $scope.updateStatus(data) })
$scope.$on('update:time', function (evt, data) { $scope.updateTime(data) })
})

View File

@ -16,6 +16,7 @@ describe('queue controller', function() {
it('sets the currently playing song', function () {
scope.updatePlaying(scope.queueSongs[1].id)
expect(scope.queueSongs[0].playing).toBe(false)
expect(scope.queueSongs[1].playing).toBe(true)
})
});

View File

@ -0,0 +1,32 @@
describe('transport controller', function() {
var TransportController, scope
beforeEach(module('mpdClient'))
beforeEach(inject(function ($controller, $rootScope) {
scope = $rootScope.$new()
TransportController = $controller('transport', { $scope: scope, api: mockApi })
}))
it('gets the status from the API', function () {
expect(scope.status.volume).toBe(100)
})
it('gets the playing status', function () {
expect(scope.playing()).toBe(true)
status = scope.status
status.state = 'stop'
scope.updateStatus(status)
expect(scope.playing()).toBe(false)
})
it('gets the stopped status', function () {
expect(scope.stopped()).toBe(false)
})
it('reports the correct marker position', function () {
expect(scope.markerPosition()).toBe(50)
})
});

View File

@ -22,5 +22,30 @@ var mockApi = {
]
}
}
},
getStatus: function () {
return {
success: function (callback) {
callback({
"volume": 100,
"repeat": true,
"random": false,
"single": false,
"consume": false,
"playlist": 237,
"playlistlength": 15,
"xfade": 0,
"mixrampdb": 0,
"mixrampdelay": 0,
"state": "play",
"time": [80, 160],
"song": 8,
"songid": 124,
"nextsong": 9,
"nextsongid": 125
}, null, {}, {})
}
}
}
}