Fix starring songs in the playing queue
This commit is contained in:
parent
fa1dec8e34
commit
9804561ebd
3 changed files with 72 additions and 10 deletions
|
@ -208,7 +208,7 @@ describe("Main controller", function () {
|
||||||
expect(notifications.updateMessage).toHaveBeenCalledWith('Favorite Updated!', true);
|
expect(notifications.updateMessage).toHaveBeenCalledWith('Favorite Updated!', true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Given a song that was starred, when I toggle its star, then subsonic service will be called, the song will be starred and a notification will be displayed", function () {
|
it("Given a song that was starred, when I toggle its star, then subsonic service will be called, the song will no longer be starred and a notification will be displayed", function () {
|
||||||
var song = { id: 784, starred: true };
|
var song = { id: 784, starred: true };
|
||||||
scope.toggleStar(song);
|
scope.toggleStar(song);
|
||||||
deferred.resolve(false);
|
deferred.resolve(false);
|
||||||
|
|
|
@ -7,7 +7,9 @@
|
||||||
angular.module('jamstash.queue.controller', [
|
angular.module('jamstash.queue.controller', [
|
||||||
'ngLodash',
|
'ngLodash',
|
||||||
'jamstash.player.service',
|
'jamstash.player.service',
|
||||||
|
'jamstash.subsonic.service',
|
||||||
'jamstash.selectedsongs',
|
'jamstash.selectedsongs',
|
||||||
|
'jamstash.notifications',
|
||||||
'ui.sortable'
|
'ui.sortable'
|
||||||
])
|
])
|
||||||
|
|
||||||
|
@ -17,28 +19,32 @@ QueueController.$inject = [
|
||||||
'$scope',
|
'$scope',
|
||||||
'lodash',
|
'lodash',
|
||||||
'player',
|
'player',
|
||||||
'SelectedSongs'
|
'SelectedSongs',
|
||||||
|
'subsonic',
|
||||||
|
'notifications'
|
||||||
];
|
];
|
||||||
|
|
||||||
function QueueController(
|
function QueueController(
|
||||||
$scope,
|
$scope,
|
||||||
_,
|
_,
|
||||||
player,
|
player,
|
||||||
SelectedSongs
|
SelectedSongs,
|
||||||
|
subsonic,
|
||||||
|
notifications
|
||||||
) {
|
) {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var self = this;
|
var self = this;
|
||||||
_.extend(self, {
|
_.extend(self, {
|
||||||
player: player,
|
player: player,
|
||||||
addSongToQueue : player.addSong,
|
|
||||||
emptyQueue : emptyQueue,
|
emptyQueue : emptyQueue,
|
||||||
isPlayingSong : isPlayingSong,
|
isPlayingSong : isPlayingSong,
|
||||||
playSong : player.play,
|
playSong : player.play,
|
||||||
removeSelectedSongsFromQueue: removeSelectedSongsFromQueue,
|
removeSelectedSongsFromQueue: removeSelectedSongsFromQueue,
|
||||||
removeSongFromQueue : player.removeSong,
|
removeSongFromQueue : player.removeSong,
|
||||||
shuffleQueue : shuffleQueue,
|
shuffleQueue : shuffleQueue,
|
||||||
toggleSelection : SelectedSongs.toggle
|
toggleSelection : SelectedSongs.toggle,
|
||||||
|
toggleStar : toggleStar
|
||||||
});
|
});
|
||||||
|
|
||||||
function emptyQueue() {
|
function emptyQueue() {
|
||||||
|
@ -61,6 +67,17 @@ function QueueController(
|
||||||
$('#SideBar').stop().scrollTo('.header', 400);
|
$('#SideBar').stop().scrollTo('.header', 400);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Hyz: Duplicate of main-controller's toggleStar.
|
||||||
|
// Refactor in a SubsonicSong service that'll hold all the common operations done on songs.
|
||||||
|
function toggleStar(song) {
|
||||||
|
var promise = subsonic.toggleStar(song).then(function (newState) {
|
||||||
|
song.starred = newState;
|
||||||
|
notifications.updateMessage('Favorite Updated!', true);
|
||||||
|
});
|
||||||
|
|
||||||
|
return promise;
|
||||||
|
}
|
||||||
|
|
||||||
$scope.$watch(function () {
|
$scope.$watch(function () {
|
||||||
return player.getPlayingSong();
|
return player.getPlayingSong();
|
||||||
}, function (newSong) {
|
}, function (newSong) {
|
||||||
|
|
|
@ -2,13 +2,14 @@
|
||||||
describe("Queue controller", function () {
|
describe("Queue controller", function () {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var QueueContoller, $scope, player, SelectedSongs;
|
var QueueContoller, $scope, player, subsonic, SelectedSongs, notifications, $q, deferred, song;
|
||||||
var song;
|
|
||||||
|
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
module('jamstash.queue.controller');
|
module('jamstash.queue.controller');
|
||||||
|
|
||||||
SelectedSongs = jasmine.createSpyObj("SelectedSongs", ["get"]);
|
SelectedSongs = jasmine.createSpyObj("SelectedSongs", [
|
||||||
|
"get"
|
||||||
|
]);
|
||||||
|
|
||||||
player = jasmine.createSpyObj("player", [
|
player = jasmine.createSpyObj("player", [
|
||||||
"emptyQueue",
|
"emptyQueue",
|
||||||
|
@ -18,13 +19,27 @@ describe("Queue controller", function () {
|
||||||
"shuffleQueue"
|
"shuffleQueue"
|
||||||
]);
|
]);
|
||||||
|
|
||||||
inject(function ($controller, $rootScope) {
|
subsonic = jasmine.createSpyObj("subsonic", [
|
||||||
|
"toggleStar"
|
||||||
|
]);
|
||||||
|
|
||||||
|
notifications = jasmine.createSpyObj("notifications", [
|
||||||
|
"updateMessage"
|
||||||
|
]);
|
||||||
|
|
||||||
|
inject(function ($controller, $rootScope, _$q_, lodash) {
|
||||||
|
$q = _$q_;
|
||||||
|
deferred = $q.defer();
|
||||||
|
|
||||||
$scope = $rootScope.$new();
|
$scope = $rootScope.$new();
|
||||||
|
|
||||||
QueueContoller = $controller('QueueController', {
|
QueueContoller = $controller('QueueController', {
|
||||||
$scope : $scope,
|
$scope : $scope,
|
||||||
|
_ : lodash,
|
||||||
player : player,
|
player : player,
|
||||||
SelectedSongs: SelectedSongs
|
SelectedSongs: SelectedSongs,
|
||||||
|
subsonic : subsonic,
|
||||||
|
notifications: notifications
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
player.queue = [];
|
player.queue = [];
|
||||||
|
@ -80,4 +95,34 @@ describe("Queue controller", function () {
|
||||||
|
|
||||||
expect($.fn.scrollTo).toHaveBeenCalled();
|
expect($.fn.scrollTo).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("toggleStar() -", function () {
|
||||||
|
beforeEach(function () {
|
||||||
|
subsonic.toggleStar.and.returnValue(deferred.promise);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("Given a song that was not starred, when I toggle its star, then subsonic service will be called, the song will be starred and a notification will be displayed", function () {
|
||||||
|
song = { id: 4218, starred: false };
|
||||||
|
|
||||||
|
QueueContoller.toggleStar(song);
|
||||||
|
deferred.resolve(true);
|
||||||
|
$scope.$apply();
|
||||||
|
|
||||||
|
expect(subsonic.toggleStar).toHaveBeenCalledWith(song);
|
||||||
|
expect(song.starred).toBeTruthy();
|
||||||
|
expect(notifications.updateMessage).toHaveBeenCalledWith('Favorite Updated!', true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("Given a song that was starred, when I toggle its star, then subsonic service will be called, the song will be starred and a notification will be displayed", function () {
|
||||||
|
song = { id: 784, starred: true };
|
||||||
|
|
||||||
|
QueueContoller.toggleStar(song);
|
||||||
|
deferred.resolve(false);
|
||||||
|
$scope.$apply();
|
||||||
|
|
||||||
|
expect(subsonic.toggleStar).toHaveBeenCalledWith(song);
|
||||||
|
expect(song.starred).toBeFalsy();
|
||||||
|
expect(notifications.updateMessage).toHaveBeenCalledWith('Favorite Updated!', true);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue