When shuffling the playing queue, the currently playing song will always stay at the first position.
So that we don't end up at the end of the queue after we shuffle it. - The queue controller will also scroll the queue up to the first element so the user notices the playing song stayed first
This commit is contained in:
parent
9fbd7bcf8e
commit
86eaea4b0e
4 changed files with 37 additions and 6 deletions
|
@ -101,7 +101,13 @@ angular.module('jamstash.player.service', ['jamstash.settings.service', 'angular
|
||||||
},
|
},
|
||||||
|
|
||||||
shuffleQueue: function () {
|
shuffleQueue: function () {
|
||||||
player.queue = _(player.queue).shuffle();
|
var shuffled = _(player.queue).without(player._playingSong);
|
||||||
|
shuffled = _(shuffled).shuffle();
|
||||||
|
if(player._playingSong !== undefined) {
|
||||||
|
shuffled.unshift(player._playingSong);
|
||||||
|
player._playingIndex = 0;
|
||||||
|
}
|
||||||
|
player.queue = shuffled;
|
||||||
return player;
|
return player;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -138,6 +138,25 @@ describe("Player service -", function() {
|
||||||
expect(player.queue).toEqual([]);
|
expect(player.queue).toEqual([]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("and given the third song was playing, when I shuffle the playing queue, then the third song will be at the first position and the rest of the queue will be shuffled", function() {
|
||||||
|
player._playingSong = thirdSong;
|
||||||
|
|
||||||
|
player.shuffleQueue();
|
||||||
|
|
||||||
|
expect(player.queue[0]).toBe(thirdSong);
|
||||||
|
expect(player.queue).toContain(firstSong);
|
||||||
|
expect(player.queue).toContain(secondSong);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("and given no song was playing, when I shuffle the playing queue, then the whole queue will be shuffled", function() {
|
||||||
|
player.shuffleQueue();
|
||||||
|
|
||||||
|
expect(player.queue).toContain(firstSong);
|
||||||
|
expect(player.queue).toContain(secondSong);
|
||||||
|
expect(player.queue).toContain(thirdSong);
|
||||||
|
expect(player.queue).not.toContain(undefined);
|
||||||
|
});
|
||||||
|
|
||||||
it("when I get the index of the first song, it returns 0", function() {
|
it("when I get the index of the first song, it returns 0", function() {
|
||||||
expect(player.indexOfSong(firstSong)).toBe(0);
|
expect(player.indexOfSong(firstSong)).toBe(0);
|
||||||
});
|
});
|
||||||
|
|
|
@ -16,21 +16,23 @@ angular.module('jamstash.queue.controller', ['jamstash.player.service'])
|
||||||
player.play(song);
|
player.play(song);
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.emptyQueue = function() {
|
$scope.emptyQueue = function () {
|
||||||
player.emptyQueue();
|
player.emptyQueue();
|
||||||
//TODO: Hyz: Shouldn't it be in a directive ?
|
//TODO: Hyz: Shouldn't it be in a directive ?
|
||||||
$.fancybox.close();
|
$.fancybox.close();
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.shuffleQueue = function() {
|
$scope.shuffleQueue = function () {
|
||||||
player.shuffleQueue();
|
player.shuffleQueue();
|
||||||
|
//TODO: Hyz: Shouldn't it be in a directive ?
|
||||||
|
$('#SideBar').stop().scrollTo('.header', 400);
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.addSongToQueue = function(song) {
|
$scope.addSongToQueue = function (song) {
|
||||||
player.addSong(song);
|
player.addSong(song);
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.removeSongFromQueue = function(song) {
|
$scope.removeSongFromQueue = function (song) {
|
||||||
player.removeSong(song);
|
player.removeSong(song);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -36,10 +36,14 @@ describe("Queue controller", function() {
|
||||||
expect($.fancybox.close).toHaveBeenCalled();
|
expect($.fancybox.close).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("When I shuffle the queue, it calls shuffleQueue in the player service", function() {
|
it("When I shuffle the queue, then the player's shuffleQueue will be called and the queue will be scrolled back to the first element", function() {
|
||||||
spyOn(player, "shuffleQueue");
|
spyOn(player, "shuffleQueue");
|
||||||
|
spyOn($.fn, 'scrollTo');
|
||||||
|
|
||||||
scope.shuffleQueue();
|
scope.shuffleQueue();
|
||||||
|
|
||||||
expect(player.shuffleQueue).toHaveBeenCalled();
|
expect(player.shuffleQueue).toHaveBeenCalled();
|
||||||
|
expect($.fn.scrollTo).toHaveBeenCalledWith('.header', jasmine.any(Number));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("When I add one song to the queue, it calls addSong in the player service", function() {
|
it("When I add one song to the queue, it calls addSong in the player service", function() {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue