Refactors subsonic-service's getPodcast() to use subsonicRequest()
So we can move closer to consistent error-reporting and protocol usage. - refactors subonic-controller's getPodcast(). - Also sets all the selected things (playlist, album, etc.) to null. - Adds a mapPodcasts() method to model-service.js. Just as mapSongs(), it maps an array of podcast episodes and returns it. - Adds unit-tests.
This commit is contained in:
parent
f4c37bc8dd
commit
ef57aac043
7 changed files with 297 additions and 123 deletions
|
@ -138,4 +138,13 @@ angular.module('jamstash.model', ['jamstash.utils'])
|
||||||
url = globals.BaseURL() + '/stream.view?' + globals.BaseParams() + '&id=' + song.streamId + '&salt=' + salt;
|
url = globals.BaseURL() + '/stream.view?' + globals.BaseParams() + '&id=' + song.streamId + '&salt=' + salt;
|
||||||
return new model.Song(song.streamId, song.parent, track, title, artist, song.artistId, album, song.albumId, coverartthumb, coverartfull, song.duration, song.userRating, starred, suffix, specs, url, 0, description);
|
return new model.Song(song.streamId, song.parent, track, title, artist, song.artistId, album, song.albumId, coverartthumb, coverartfull, song.duration, song.userRating, starred, suffix, specs, url, 0, description);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
this.mapPodcasts = function (episodes) {
|
||||||
|
var mappedEpisodes = [];
|
||||||
|
var mapEpisode = this.mapPodcast;
|
||||||
|
angular.forEach(episodes, function (episode) {
|
||||||
|
mappedEpisodes.push(mapEpisode(episode));
|
||||||
|
});
|
||||||
|
return mappedEpisodes;
|
||||||
|
};
|
||||||
}]);
|
}]);
|
||||||
|
|
|
@ -20,7 +20,7 @@ describe("model service", function() {
|
||||||
expect(model.displayName).toBe("Know Your Enemy - Ghost in the Shell - Stand Alone Complex OST 3 - Yoko Kanno");
|
expect(model.displayName).toBe("Know Your Enemy - Ghost in the Shell - Stand Alone Complex OST 3 - Yoko Kanno");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Given multiple songs, when I map them, it calls mapSong for each song", function() {
|
it("Given multiple songs, when I map them, then mapSong is called for each song", function() {
|
||||||
var songs = [
|
var songs = [
|
||||||
{ id: 2912 },
|
{ id: 2912 },
|
||||||
{ id: 1450 },
|
{ id: 1450 },
|
||||||
|
@ -35,4 +35,20 @@ describe("model service", function() {
|
||||||
expect(map.mapSong).toHaveBeenCalledWith({id: 6663});
|
expect(map.mapSong).toHaveBeenCalledWith({id: 6663});
|
||||||
expect(result).toEqual(songs);
|
expect(result).toEqual(songs);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("Given multiple podcast episodes, when I map them, then mapPodcast is called for each episode", function() {
|
||||||
|
var episodes = [
|
||||||
|
{ id: 63 },
|
||||||
|
{ id: 24 },
|
||||||
|
{ id: 80 }
|
||||||
|
];
|
||||||
|
spyOn(map, 'mapPodcast').and.callFake(function (episode) { return episode; });
|
||||||
|
|
||||||
|
var result = map.mapPodcasts(episodes);
|
||||||
|
expect(map.mapPodcast.calls.count()).toEqual(3);
|
||||||
|
expect(map.mapPodcast).toHaveBeenCalledWith({ id: 63 });
|
||||||
|
expect(map.mapPodcast).toHaveBeenCalledWith({ id: 24 });
|
||||||
|
expect(map.mapPodcast).toHaveBeenCalledWith({ id: 80 });
|
||||||
|
expect(result).toEqual(episodes);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -507,7 +507,11 @@ angular.module('jamstash.subsonic.service', ['jamstash.settings', 'jamstash.util
|
||||||
|
|
||||||
getPodcasts: function () {
|
getPodcasts: function () {
|
||||||
var exception = {reason: 'No podcast found on the Subsonic server.'};
|
var exception = {reason: 'No podcast found on the Subsonic server.'};
|
||||||
var promise = this.subsonicRequest('getPodcasts.view')
|
var promise = this.subsonicRequest('getPodcasts.view', {
|
||||||
|
params: {
|
||||||
|
includeEpisodes: false
|
||||||
|
}
|
||||||
|
})
|
||||||
.then(function (subsonicResponse) {
|
.then(function (subsonicResponse) {
|
||||||
if (subsonicResponse.podcasts !== undefined && subsonicResponse.podcasts.channel !== undefined && subsonicResponse.podcasts.channel.length > 0) {
|
if (subsonicResponse.podcasts !== undefined && subsonicResponse.podcasts.channel !== undefined && subsonicResponse.podcasts.channel.length > 0) {
|
||||||
return subsonicResponse.podcasts.channel;
|
return subsonicResponse.podcasts.channel;
|
||||||
|
@ -518,62 +522,31 @@ angular.module('jamstash.subsonic.service', ['jamstash.settings', 'jamstash.util
|
||||||
return promise;
|
return promise;
|
||||||
},
|
},
|
||||||
|
|
||||||
getPodcast: function (id, action) {
|
getPodcast: function (id) {
|
||||||
var deferred = $q.defer();
|
var exception = {reason: 'This podcast was not found on the Subsonic server.'};
|
||||||
content.selectedPodcast = id;
|
var promise = this.subsonicRequest('getPodcasts.view', {
|
||||||
$.ajax({
|
params: {
|
||||||
url: globals.BaseURL() + '/getPodcasts.view?' + globals.BaseParams(),
|
id: id,
|
||||||
method: 'GET',
|
includeEpisodes: true
|
||||||
dataType: globals.settings.Protocol,
|
}
|
||||||
timeout: globals.settings.Timeout,
|
}).then(function (subsonicResponse) {
|
||||||
success: function (data) {
|
var episodes = [];
|
||||||
if (data["subsonic-response"].podcasts.channel !== undefined) {
|
if (subsonicResponse.podcasts.channel !== undefined && subsonicResponse.podcasts.channel.length > 0) {
|
||||||
var podcasts = [];
|
var channel = subsonicResponse.podcasts.channel[0];
|
||||||
if (data["subsonic-response"].podcasts.channel.length > 0) {
|
if (channel !== null && channel.id === id) {
|
||||||
podcasts = data["subsonic-response"].podcasts.channel;
|
episodes = _(channel.episode).filter(function (episode) {
|
||||||
|
return episode.status === "completed";
|
||||||
|
});
|
||||||
|
if(episodes.length > 0) {
|
||||||
|
return map.mapPodcasts(episodes);
|
||||||
} else {
|
} else {
|
||||||
podcasts[0] = data["subsonic-response"].podcasts.channel;
|
return $q.reject({reason: 'No downloaded episode found for this podcast. Please check the podcast settings.'});
|
||||||
}
|
}
|
||||||
var items = [];
|
|
||||||
$.each(podcasts, function (i, item) {
|
|
||||||
if (item.id == id) {
|
|
||||||
items = item.episode;
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
return $q.reject(exception);
|
||||||
});
|
});
|
||||||
|
return promise;
|
||||||
if (typeof items != 'undefined') {
|
|
||||||
if (action == 'add') {
|
|
||||||
angular.forEach(items, function (item, key) {
|
|
||||||
if (item.status != "skipped") {
|
|
||||||
player.queue.push(map.mapPodcast(item));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
notifications.updateMessage(items.length + ' Song(s) Added to Queue', true);
|
|
||||||
} else if (action == 'play') {
|
|
||||||
player.queue = [];
|
|
||||||
angular.forEach(items, function (item, key) {
|
|
||||||
if (item.status != "skipped") {
|
|
||||||
player.queue.push(map.mapPodcast(item));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
var next = player.queue[0];
|
|
||||||
player.play(next);
|
|
||||||
notifications.updateMessage(items.length + ' Song(s) Added to Queue', true);
|
|
||||||
} else {
|
|
||||||
content.album = [];
|
|
||||||
content.song = [];
|
|
||||||
angular.forEach(items, function (item, key) {
|
|
||||||
if (item.status != "skipped") {
|
|
||||||
content.song.push(map.mapPodcast(item));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
deferred.resolve(content);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return deferred.promise;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
scrobble: function (song) {
|
scrobble: function (song) {
|
||||||
|
|
|
@ -28,6 +28,9 @@ describe("Subsonic service -", function() {
|
||||||
$delegate.mapSong = function (argument) {
|
$delegate.mapSong = function (argument) {
|
||||||
return argument;
|
return argument;
|
||||||
};
|
};
|
||||||
|
$delegate.mapPodcast = function (argument) {
|
||||||
|
return argument;
|
||||||
|
};
|
||||||
return $delegate;
|
return $delegate;
|
||||||
});
|
});
|
||||||
// Mock utils.getValue
|
// Mock utils.getValue
|
||||||
|
@ -455,6 +458,7 @@ describe("Subsonic service -", function() {
|
||||||
url = 'http://demo.subsonic.com/rest/getPlaylist.view?'+
|
url = 'http://demo.subsonic.com/rest/getPlaylist.view?'+
|
||||||
'c=Jamstash&callback=JSON_CALLBACK&f=jsonp&p=enc:cGFzc3dvcmQ%3D&u=Hyzual&v=1.10.2';
|
'c=Jamstash&callback=JSON_CALLBACK&f=jsonp&p=enc:cGFzc3dvcmQ%3D&u=Hyzual&v=1.10.2';
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Given a playlist with 2 songs in it, when I get it, it returns the 2 songs of the playlist", function() {
|
it("Given a playlist with 2 songs in it, when I get it, it returns the 2 songs of the playlist", function() {
|
||||||
url = 'http://demo.subsonic.com/rest/getPlaylist.view?'+
|
url = 'http://demo.subsonic.com/rest/getPlaylist.view?'+
|
||||||
'c=Jamstash&callback=JSON_CALLBACK&f=jsonp'+'&id=9123'+'&p=enc:cGFzc3dvcmQ%3D&u=Hyzual&v=1.10.2';
|
'c=Jamstash&callback=JSON_CALLBACK&f=jsonp'+'&id=9123'+'&p=enc:cGFzc3dvcmQ%3D&u=Hyzual&v=1.10.2';
|
||||||
|
@ -530,9 +534,10 @@ describe("Subsonic service -", function() {
|
||||||
describe("When I load the podcasts,", function() {
|
describe("When I load the podcasts,", function() {
|
||||||
var url;
|
var url;
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
url = url = 'http://demo.subsonic.com/rest/getPodcasts.view?'+
|
url = 'http://demo.subsonic.com/rest/getPodcasts.view?'+
|
||||||
'c=Jamstash&callback=JSON_CALLBACK&f=jsonp&p=enc:cGFzc3dvcmQ%3D&u=Hyzual&v=1.10.2';
|
'c=Jamstash&callback=JSON_CALLBACK&f=jsonp'+'&includeEpisodes=false'+'&p=enc:cGFzc3dvcmQ%3D&u=Hyzual&v=1.10.2';
|
||||||
});
|
});
|
||||||
|
|
||||||
it("given that there were podcasts in the library, then a promise will be resolved with an array of podcasts", function() {
|
it("given that there were podcasts in the library, then a promise will be resolved with an array of podcasts", function() {
|
||||||
response["subsonic-response"].podcasts = {
|
response["subsonic-response"].podcasts = {
|
||||||
channel: [
|
channel: [
|
||||||
|
@ -553,7 +558,7 @@ describe("Subsonic service -", function() {
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("given that there weren't any podcast in the library, then a rejected promise with an error message will be returned", function() {
|
it("given that there weren't any podcast in the library, then a promise will be rejected with an error message", function() {
|
||||||
response["subsonic-response"].podcasts = {};
|
response["subsonic-response"].podcasts = {};
|
||||||
mockBackend.expectJSONP(url).respond(JSON.stringify(response));
|
mockBackend.expectJSONP(url).respond(JSON.stringify(response));
|
||||||
|
|
||||||
|
@ -563,4 +568,84 @@ describe("Subsonic service -", function() {
|
||||||
expect(promise).toBeRejectedWith({reason: 'No podcast found on the Subsonic server.'});
|
expect(promise).toBeRejectedWith({reason: 'No podcast found on the Subsonic server.'});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("When I load a podcast,", function() {
|
||||||
|
var url;
|
||||||
|
beforeEach(function() {
|
||||||
|
url = 'http://demo.subsonic.com/rest/getPodcasts.view?'+
|
||||||
|
'c=Jamstash&callback=JSON_CALLBACK&f=jsonp'+'&id=2695&includeEpisodes=true'+'&p=enc:cGFzc3dvcmQ%3D&u=Hyzual&v=1.10.2';
|
||||||
|
});
|
||||||
|
|
||||||
|
it("given a podcast id, then a promise will be resolved with an array of songs from all the non-skipped episodes of that podcast", function() {
|
||||||
|
response["subsonic-response"].podcasts = {
|
||||||
|
channel: [
|
||||||
|
{
|
||||||
|
id: 2695,
|
||||||
|
episode: [
|
||||||
|
{
|
||||||
|
id: 691,
|
||||||
|
status: "completed"
|
||||||
|
}, {
|
||||||
|
id: 771,
|
||||||
|
status: "skipped"
|
||||||
|
}, {
|
||||||
|
id: 227,
|
||||||
|
status: "completed"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
};
|
||||||
|
mockBackend.expectJSONP(url).respond(JSON.stringify(response));
|
||||||
|
|
||||||
|
var promise = subsonic.getPodcast(2695);
|
||||||
|
mockBackend.flush();
|
||||||
|
|
||||||
|
expect(promise).toBeResolvedWith([
|
||||||
|
{
|
||||||
|
id: 691,
|
||||||
|
status: "completed"
|
||||||
|
}, {
|
||||||
|
id: 227,
|
||||||
|
status: "completed"
|
||||||
|
}
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("given that the podcast I wanted to get didn't exist in the library, when I try to get it, then a promise will be rejected with an error message", function() {
|
||||||
|
response["subsonic-response"].podcasts = {};
|
||||||
|
mockBackend.expectJSONP(url).respond(JSON.stringify(response));
|
||||||
|
|
||||||
|
var promise = subsonic.getPodcast(2695);
|
||||||
|
mockBackend.flush();
|
||||||
|
|
||||||
|
expect(promise).toBeRejectedWith({reason: 'This podcast was not found on the Subsonic server.'});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("given that the podcast I wanted to get was empty (0 non-skipped episode in it), when I get it, then a promise will be rejected with an error message", function() {
|
||||||
|
response["subsonic-response"].podcasts = {
|
||||||
|
channel: [
|
||||||
|
{
|
||||||
|
id: 2695,
|
||||||
|
episode: [
|
||||||
|
{
|
||||||
|
id: 678,
|
||||||
|
status: "skipped"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 972,
|
||||||
|
status: "skipped"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
};
|
||||||
|
mockBackend.expectJSONP(url).respond(JSON.stringify(response));
|
||||||
|
|
||||||
|
var promise = subsonic.getPodcast(2695);
|
||||||
|
mockBackend.flush();
|
||||||
|
|
||||||
|
expect(promise).toBeRejectedWith({reason: 'No downloaded episode found for this podcast. Please check the podcast settings.'});
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -181,9 +181,10 @@
|
||||||
<div id="PodcastContainer" class="leftsubsection" ng-show="showPodcast">
|
<div id="PodcastContainer" class="leftsubsection" ng-show="showPodcast">
|
||||||
<ul class="simplelist mainlist noselect">
|
<ul class="simplelist mainlist noselect">
|
||||||
<li class="index" id="auto">Podcasts</li>
|
<li class="index" id="auto">Podcasts</li>
|
||||||
<li class="item" ng-repeat="o in podcasts" ng-click="getPodcast(o.id, '')" ng-class="{ 'selected': o.id == selectedPodcast }">
|
<li class="item" ng-repeat="o in podcasts" ng-click="getPodcast('display', o.id)" ng-class="{ 'selected': o.id == selectedPodcast }">
|
||||||
<div class="itemactions">
|
<div class="itemactions">
|
||||||
<a class="add" href="" title="Add To Play Queue" ng-click="getPodcast(o.id, 'add')" stop-event="click"></a><a class="play" href="" title="Play" ng-click="getPodcast(o.id, 'play')" stop-event="click"></a>
|
<a class="add" href="" title="Add To Play Queue" ng-click="getPodcast('add', o.id)" stop-event="click"></a>
|
||||||
|
<a class="play" href="" title="Play" ng-click="getPodcast('play', o.id)" stop-event="click"></a>
|
||||||
</div>
|
</div>
|
||||||
<div class="title" title="{{o.description}}">{{o.title}}</div>
|
<div class="title" title="{{o.description}}">{{o.title}}</div>
|
||||||
</li>
|
</li>
|
||||||
|
|
|
@ -315,15 +315,20 @@ angular.module('jamstash.subsonic.controller', ['jamstash.subsonic.service', 'ja
|
||||||
var promise = subsonic.getRandomStarredSongs();
|
var promise = subsonic.getRandomStarredSongs();
|
||||||
$scope.requestSongs(promise, action);
|
$scope.requestSongs(promise, action);
|
||||||
|
|
||||||
$scope.selectedPlaylist = null;
|
$scope.album = [];
|
||||||
|
$scope.BreadCrumbs = null;
|
||||||
|
$scope.selectedAutoAlbum = null;
|
||||||
|
$scope.selectedArtist = null;
|
||||||
|
$scope.selectedAlbum = null;
|
||||||
$scope.selectedAutoPlaylist = 'starred';
|
$scope.selectedAutoPlaylist = 'starred';
|
||||||
|
$scope.selectedPlaylist = null;
|
||||||
|
$scope.selectedPodcast = null;
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.getRandomSongs = function (action, genre, folder) {
|
$scope.getRandomSongs = function (action, genre, folder) {
|
||||||
var promise = subsonic.getRandomSongs(genre, folder);
|
var promise = subsonic.getRandomSongs(genre, folder);
|
||||||
$scope.requestSongs(promise, action);
|
$scope.requestSongs(promise, action);
|
||||||
|
|
||||||
$scope.selectedPlaylist = null;
|
|
||||||
if (!isNaN(folder)) {
|
if (!isNaN(folder)) {
|
||||||
$scope.selectedAutoPlaylist = folder;
|
$scope.selectedAutoPlaylist = folder;
|
||||||
} else if (genre !== undefined && genre !== '' && genre !== 'Random') {
|
} else if (genre !== undefined && genre !== '' && genre !== 'Random') {
|
||||||
|
@ -331,6 +336,13 @@ angular.module('jamstash.subsonic.controller', ['jamstash.subsonic.service', 'ja
|
||||||
} else {
|
} else {
|
||||||
$scope.selectedAutoPlaylist = 'random';
|
$scope.selectedAutoPlaylist = 'random';
|
||||||
}
|
}
|
||||||
|
$scope.album = [];
|
||||||
|
$scope.BreadCrumbs = null;
|
||||||
|
$scope.selectedAutoAlbum = null;
|
||||||
|
$scope.selectedArtist = null;
|
||||||
|
$scope.selectedAlbum = null;
|
||||||
|
$scope.selectedPlaylist = null;
|
||||||
|
$scope.selectedPodcast = null;
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.getStarred = function (action, type) {
|
$scope.getStarred = function (action, type) {
|
||||||
|
@ -415,8 +427,15 @@ angular.module('jamstash.subsonic.controller', ['jamstash.subsonic.service', 'ja
|
||||||
notifications.updateMessage(songs.length + ' Song(s) in Playlist', true);
|
notifications.updateMessage(songs.length + ' Song(s) in Playlist', true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
$scope.selectedPlaylist = id;
|
$scope.song = [];
|
||||||
|
$scope.album = [];
|
||||||
|
$scope.BreadCrumbs = null;
|
||||||
|
$scope.selectedAutoAlbum = null;
|
||||||
|
$scope.selectedArtist = null;
|
||||||
|
$scope.selectedAlbum = null;
|
||||||
$scope.selectedAutoPlaylist = null;
|
$scope.selectedAutoPlaylist = null;
|
||||||
|
$scope.selectedPlaylist = id;
|
||||||
|
$scope.selectedPodcast = null;
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.newPlaylist = function () {
|
$scope.newPlaylist = function () {
|
||||||
|
@ -526,13 +545,21 @@ angular.module('jamstash.subsonic.controller', ['jamstash.subsonic.service', 'ja
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.getPodcast = function (id, action) {
|
$scope.getPodcast = function (action, id) {
|
||||||
subsonic.getPodcast(id, action).then(function (data) {
|
var promise = subsonic.getPodcast(id);
|
||||||
$scope.album = data.album;
|
$scope.requestSongs(promise, action);
|
||||||
$scope.song = data.song;
|
|
||||||
$scope.selectedPodcast = data.selectedPodcast;
|
$scope.song = [];
|
||||||
});
|
$scope.album = [];
|
||||||
|
$scope.BreadCrumbs = null;
|
||||||
|
$scope.selectedAutoAlbum = null;
|
||||||
|
$scope.selectedArtist = null;
|
||||||
|
$scope.selectedAlbum = null;
|
||||||
|
$scope.selectedAutoPlaylist = null;
|
||||||
|
$scope.selectedPlaylist = null;
|
||||||
|
$scope.selectedPodcast = id;
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.getMusicFolders = function () {
|
$scope.getMusicFolders = function () {
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: globals.BaseURL() + '/getMusicFolders.view?' + globals.BaseParams(),
|
url: globals.BaseURL() + '/getMusicFolders.view?' + globals.BaseParams(),
|
||||||
|
|
|
@ -41,7 +41,8 @@ describe("Subsonic controller", function() {
|
||||||
"getPlaylist",
|
"getPlaylist",
|
||||||
"newPlaylist",
|
"newPlaylist",
|
||||||
"deletePlaylist",
|
"deletePlaylist",
|
||||||
"savePlaylist"
|
"savePlaylist",
|
||||||
|
"getPodcast"
|
||||||
]);
|
]);
|
||||||
// We make them return different promises and use our deferred variable only when testing
|
// We make them return different promises and use our deferred variable only when testing
|
||||||
// a particular function, so that they stay isolated
|
// a particular function, so that they stay isolated
|
||||||
|
@ -50,9 +51,6 @@ describe("Subsonic controller", function() {
|
||||||
subsonic.getGenres.and.returnValue($q.defer().promise);
|
subsonic.getGenres.and.returnValue($q.defer().promise);
|
||||||
subsonic.getPlaylists.and.returnValue($q.defer().promise);
|
subsonic.getPlaylists.and.returnValue($q.defer().promise);
|
||||||
subsonic.getPodcasts.and.returnValue($q.defer().promise);
|
subsonic.getPodcasts.and.returnValue($q.defer().promise);
|
||||||
subsonic.getRandomStarredSongs.and.returnValue($q.defer().promise);
|
|
||||||
subsonic.getRandomSongs.and.returnValue($q.defer().promise);
|
|
||||||
subsonic.getPlaylist.and.returnValue($q.defer().promise);
|
|
||||||
subsonic.showIndex = false;
|
subsonic.showIndex = false;
|
||||||
|
|
||||||
$controller = _$controller_;
|
$controller = _$controller_;
|
||||||
|
@ -89,62 +87,106 @@ describe("Subsonic controller", function() {
|
||||||
spyOn(scope, "requestSongs").and.returnValue(deferred.promise);
|
spyOn(scope, "requestSongs").and.returnValue(deferred.promise);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("when I request random starred songs, it uses subsonic-service, delegates to requestSongs displaying, adding or playing songs and sets the scope's current playlist", function() {
|
it("when I request random starred songs, then subsonic-service will be called, displaying, adding or playing songs will be delegated to requestSongs and the current playlist will be published to the scope", function() {
|
||||||
|
subsonic.getRandomStarredSongs.and.returnValue(deferred.promise);
|
||||||
|
|
||||||
scope.getRandomStarredSongs('whatever action');
|
scope.getRandomStarredSongs('whatever action');
|
||||||
deferred.resolve(response);
|
deferred.resolve(response);
|
||||||
scope.$apply();
|
scope.$apply();
|
||||||
|
|
||||||
expect(subsonic.getRandomStarredSongs).toHaveBeenCalled();
|
expect(subsonic.getRandomStarredSongs).toHaveBeenCalled();
|
||||||
expect(scope.requestSongs).toHaveBeenCalledWith(deferred.promise, 'whatever action');
|
expect(scope.requestSongs).toHaveBeenCalledWith(deferred.promise, 'whatever action');
|
||||||
expect(scope.selectedPlaylist).toBeNull();
|
expect(scope.album).toEqual([]);
|
||||||
|
expect(scope.BreadCrumbs).toBeNull();
|
||||||
|
expect(scope.selectedAutoAlbum).toBeNull();
|
||||||
|
expect(scope.selectedArtist).toBeNull();
|
||||||
|
expect(scope.selectedAlbum).toBeNull();
|
||||||
expect(scope.selectedAutoPlaylist).toBe('starred');
|
expect(scope.selectedAutoPlaylist).toBe('starred');
|
||||||
|
expect(scope.selectedPlaylist).toBeNull();
|
||||||
|
expect(scope.selectedPodcast).toBeNull();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("when I request random songs from all folders or genres, it uses subsonic-service, delegates to requestSongs displaying, adding or playing songs and sets the scope's current playlist", function() {
|
describe("when I request random songs", function() {
|
||||||
|
beforeEach(function() {
|
||||||
|
subsonic.getRandomSongs.and.returnValue(deferred.promise);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("from all folders or genres, then subsonic-service will be called, displaying, adding or playing songs will be delegated to requestSongs and the current playlist will be published to the scope", function() {
|
||||||
scope.getRandomSongs('whatever action');
|
scope.getRandomSongs('whatever action');
|
||||||
deferred.resolve(response);
|
deferred.resolve(response);
|
||||||
scope.$apply();
|
scope.$apply();
|
||||||
|
|
||||||
expect(subsonic.getRandomSongs).toHaveBeenCalled();
|
expect(subsonic.getRandomSongs).toHaveBeenCalled();
|
||||||
expect(scope.requestSongs).toHaveBeenCalledWith(deferred.promise, 'whatever action');
|
expect(scope.requestSongs).toHaveBeenCalledWith(deferred.promise, 'whatever action');
|
||||||
expect(scope.selectedPlaylist).toBeNull();
|
expect(scope.album).toEqual([]);
|
||||||
|
expect(scope.BreadCrumbs).toBeNull();
|
||||||
|
expect(scope.selectedAutoAlbum).toBeNull();
|
||||||
|
expect(scope.selectedArtist).toBeNull();
|
||||||
|
expect(scope.selectedAlbum).toBeNull();
|
||||||
expect(scope.selectedAutoPlaylist).toBe('random');
|
expect(scope.selectedAutoPlaylist).toBe('random');
|
||||||
|
expect(scope.selectedPlaylist).toBeNull();
|
||||||
|
expect(scope.selectedPodcast).toBeNull();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("when I request random songs from a given genre, it uses subsonic-service, delegates to requestSongs displaying, adding or playing songs and sets the scope's current playlist", function() {
|
it("from a given genre, then subsonic-service will be called, displaying, adding or playing songs will be delegated to requestSongs and the current playlist will be published to the scope", function() {
|
||||||
scope.getRandomSongs('whatever action', 'Rock');
|
scope.getRandomSongs('whatever action', 'Rock');
|
||||||
deferred.resolve(response);
|
deferred.resolve(response);
|
||||||
scope.$apply();
|
scope.$apply();
|
||||||
|
|
||||||
expect(subsonic.getRandomSongs).toHaveBeenCalledWith('Rock', undefined);
|
expect(subsonic.getRandomSongs).toHaveBeenCalledWith('Rock', undefined);
|
||||||
expect(scope.requestSongs).toHaveBeenCalledWith(deferred.promise, 'whatever action');
|
expect(scope.requestSongs).toHaveBeenCalledWith(deferred.promise, 'whatever action');
|
||||||
expect(scope.selectedPlaylist).toBeNull();
|
expect(scope.album).toEqual([]);
|
||||||
|
expect(scope.BreadCrumbs).toBeNull();
|
||||||
|
expect(scope.selectedAutoAlbum).toBeNull();
|
||||||
|
expect(scope.selectedArtist).toBeNull();
|
||||||
|
expect(scope.selectedAlbum).toBeNull();
|
||||||
expect(scope.selectedAutoPlaylist).toBe('Rock');
|
expect(scope.selectedAutoPlaylist).toBe('Rock');
|
||||||
|
expect(scope.selectedPlaylist).toBeNull();
|
||||||
|
expect(scope.selectedPodcast).toBeNull();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("when I request random songs from a given folder id, it uses subsonic-service, delegates to requestSongs displaying, adding or playing songs and sets the scope's current playlist", function() {
|
it("from a given folder id, then subsonic-service will be called, displaying, adding or playing songs will be delegated to requestSongs and the current playlist will be published to the scope", function() {
|
||||||
scope.getRandomSongs('whatever action', '', 1);
|
scope.getRandomSongs('whatever action', '', 1);
|
||||||
deferred.resolve(response);
|
deferred.resolve(response);
|
||||||
scope.$apply();
|
scope.$apply();
|
||||||
|
|
||||||
expect(subsonic.getRandomSongs).toHaveBeenCalledWith('', 1);
|
expect(subsonic.getRandomSongs).toHaveBeenCalledWith('', 1);
|
||||||
expect(scope.requestSongs).toHaveBeenCalledWith(deferred.promise, 'whatever action');
|
expect(scope.requestSongs).toHaveBeenCalledWith(deferred.promise, 'whatever action');
|
||||||
expect(scope.selectedPlaylist).toBeNull();
|
expect(scope.album).toEqual([]);
|
||||||
|
expect(scope.BreadCrumbs).toBeNull();
|
||||||
|
expect(scope.selectedAutoAlbum).toBeNull();
|
||||||
|
expect(scope.selectedArtist).toBeNull();
|
||||||
|
expect(scope.selectedAlbum).toBeNull();
|
||||||
expect(scope.selectedAutoPlaylist).toBe(1);
|
expect(scope.selectedAutoPlaylist).toBe(1);
|
||||||
|
expect(scope.selectedPlaylist).toBeNull();
|
||||||
|
expect(scope.selectedPodcast).toBeNull();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("given a playlist that contains those 3 songs, when I request it, it uses subsonic-service, delegates to requestSongs displaying, adding or playing the songs of the playlist and sets the scope's current playlist", function() {
|
describe("given a playlist that contained those 3 songs,", function() {
|
||||||
|
beforeEach(function() {
|
||||||
|
subsonic.getPlaylist.and.returnValue(deferred.promise);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("when I request it, then subsonic-service will be called, displaying, adding or playing songs will be delegated to requestSongs and the current playlist will be published to the scope", function() {
|
||||||
scope.getPlaylist('whatever action', 1146);
|
scope.getPlaylist('whatever action', 1146);
|
||||||
deferred.resolve(response);
|
deferred.resolve(response);
|
||||||
scope.$apply();
|
scope.$apply();
|
||||||
|
|
||||||
expect(subsonic.getPlaylist).toHaveBeenCalledWith(1146);
|
expect(subsonic.getPlaylist).toHaveBeenCalledWith(1146);
|
||||||
expect(scope.requestSongs).toHaveBeenCalledWith(deferred.promise, 'whatever action');
|
expect(scope.requestSongs).toHaveBeenCalledWith(deferred.promise, 'whatever action');
|
||||||
expect(scope.selectedPlaylist).toBe(1146);
|
expect(scope.song).toEqual([]);
|
||||||
|
expect(scope.album).toEqual([]);
|
||||||
|
expect(scope.BreadCrumbs).toBeNull();
|
||||||
|
expect(scope.selectedAutoAlbum).toBeNull();
|
||||||
|
expect(scope.selectedArtist).toBeNull();
|
||||||
|
expect(scope.selectedAlbum).toBeNull();
|
||||||
expect(scope.selectedAutoPlaylist).toBeNull();
|
expect(scope.selectedAutoPlaylist).toBeNull();
|
||||||
|
expect(scope.selectedPlaylist).toBe(1146);
|
||||||
|
expect(scope.selectedPodcast).toBeNull();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("given a playlist that contained those 3 songs, when I display it, it will notify the user with the number of songs in the playlist", function() {
|
it("when I display it, the number of songs in the playlist will be notified", function() {
|
||||||
scope.getPlaylist('display', 1146);
|
scope.getPlaylist('display', 1146);
|
||||||
deferred.resolve(response);
|
deferred.resolve(response);
|
||||||
scope.$apply();
|
scope.$apply();
|
||||||
|
@ -153,6 +195,27 @@ describe("Subsonic controller", function() {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("given a podcast that contained those 3 songs as episodes, when I request it, then subsonic-service will be called, displaying adding or playing songs will be delegated to requestSongs and the current selected podcast will be published to the scope", function() {
|
||||||
|
subsonic.getPodcast.and.returnValue(deferred.promise);
|
||||||
|
|
||||||
|
scope.getPodcast('whatever action', 45);
|
||||||
|
deferred.resolve(response);
|
||||||
|
scope.$apply();
|
||||||
|
|
||||||
|
expect(subsonic.getPodcast).toHaveBeenCalledWith(45);
|
||||||
|
expect(scope.requestSongs).toHaveBeenCalledWith(deferred.promise, 'whatever action');
|
||||||
|
expect(scope.song).toEqual([]);
|
||||||
|
expect(scope.album).toEqual([]);
|
||||||
|
expect(scope.BreadCrumbs).toBeNull();
|
||||||
|
expect(scope.selectedAutoAlbum).toBeNull();
|
||||||
|
expect(scope.selectedArtist).toBeNull();
|
||||||
|
expect(scope.selectedAlbum).toBeNull();
|
||||||
|
expect(scope.selectedAutoPlaylist).toBeNull();
|
||||||
|
expect(scope.selectedPlaylist).toBeNull();
|
||||||
|
expect(scope.selectedPodcast).toBe(45);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe("requestSongs -", function() {
|
describe("requestSongs -", function() {
|
||||||
it("when I display songs, it sets the scope with the selected songs", function() {
|
it("when I display songs, it sets the scope with the selected songs", function() {
|
||||||
scope.requestSongs(deferred.promise, 'display');
|
scope.requestSongs(deferred.promise, 'display');
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue