Renames all tests according to angularseed's style convention.
Refactors subsonic service's getStarred method to use angular $http and to limit results on the client side since we can't do it with Subsonic's API. Adds a working unit test for this new method.
This commit is contained in:
parent
fb8bf0ef24
commit
2c6276cced
8 changed files with 89 additions and 40 deletions
10
Gruntfile.js
10
Gruntfile.js
|
@ -41,7 +41,7 @@ module.exports = function (grunt) {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
jsTest: {
|
jsTest: {
|
||||||
files: ['test/**/*.js'],
|
files: ['test/**/*_test.js'],
|
||||||
tasks: ['karma:continuous:run'], //'newer:jshint:test']
|
tasks: ['karma:continuous:run'], //'newer:jshint:test']
|
||||||
},
|
},
|
||||||
styles: {
|
styles: {
|
||||||
|
@ -52,14 +52,14 @@ module.exports = function (grunt) {
|
||||||
files: ['Gruntfile.js']
|
files: ['Gruntfile.js']
|
||||||
},
|
},
|
||||||
livereload: {
|
livereload: {
|
||||||
options: {
|
|
||||||
livereload: '<%= connect.options.livereload %>'
|
|
||||||
},
|
|
||||||
files: [
|
files: [
|
||||||
'<%= yeoman.app %>/{,*/}*.html',
|
'<%= yeoman.app %>/{,*/}*.html',
|
||||||
'.tmp/styles/{,*/}*.css',
|
'.tmp/styles/{,*/}*.css',
|
||||||
'<%= yeoman.app %>/images/{,*/}*.{png,jpg,jpeg,gif,webp,svg}'
|
'<%= yeoman.app %>/images/{,*/}*.{png,jpg,jpeg,gif,webp,svg}'
|
||||||
]
|
]
|
||||||
|
},
|
||||||
|
options: {
|
||||||
|
livereload: '<%= connect.options.livereload %>'
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -126,7 +126,7 @@ module.exports = function (grunt) {
|
||||||
options: {
|
options: {
|
||||||
jshintrc: 'test/.jshintrc'
|
jshintrc: 'test/.jshintrc'
|
||||||
},
|
},
|
||||||
src: ['test/spec/{,*/}*.js']
|
src: ['test/{,*/}*.js']
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -427,7 +427,7 @@ Jamstash.factory('subsonic', function ($rootScope, $http, $q, globals, utils, ma
|
||||||
if (genre !== '' && genre != 'Random') {
|
if (genre !== '' && genre != 'Random') {
|
||||||
genreParams = '&genre=' + genre;
|
genreParams = '&genre=' + genre;
|
||||||
}
|
}
|
||||||
folderParams = '';
|
var folderParams = '';
|
||||||
if (typeof folder == 'number' && folder !== '' && folder != 'all') {
|
if (typeof folder == 'number' && folder !== '' && folder != 'all') {
|
||||||
//alert(folder);
|
//alert(folder);
|
||||||
folderParams = '&musicFolderId=' + folder;
|
folderParams = '&musicFolderId=' + folder;
|
||||||
|
@ -556,6 +556,30 @@ Jamstash.factory('subsonic', function ($rootScope, $http, $q, globals, utils, ma
|
||||||
});
|
});
|
||||||
return deferred.promise;
|
return deferred.promise;
|
||||||
},
|
},
|
||||||
|
getStarred: function (action, type) {
|
||||||
|
var deferred = $q.defer();
|
||||||
|
// TODO: JMA: GET variant
|
||||||
|
$http.jsonp(globals.BaseURL() + '/getStarred.view?callback=JSON_CALLBACK&' + globals.BaseParams(),
|
||||||
|
{
|
||||||
|
timeout: globals.settings.Timeout
|
||||||
|
})
|
||||||
|
.success(function(data, status) {
|
||||||
|
console.log("blu");
|
||||||
|
console.log(data);
|
||||||
|
if(data['subsonic-response'] !== undefined && data['subsonic-response'].status === 'ok') {
|
||||||
|
console.log('green');
|
||||||
|
// Return only first X starred songs
|
||||||
|
var starredSongs = data['subsonic-response'].starred.song.slice(0, globals.settings.AutoPlaylistSize);
|
||||||
|
deferred.resolve(starredSongs);
|
||||||
|
} else {
|
||||||
|
deferred.reject();
|
||||||
|
}
|
||||||
|
}).error(function(data, status) {
|
||||||
|
deferred.reject();
|
||||||
|
});
|
||||||
|
return deferred.promise;
|
||||||
|
},
|
||||||
|
/*
|
||||||
getStarred: function (action, type) {
|
getStarred: function (action, type) {
|
||||||
var deferred = $q.defer();
|
var deferred = $q.defer();
|
||||||
var size = globals.settings.AutoPlaylistSize;
|
var size = globals.settings.AutoPlaylistSize;
|
||||||
|
@ -621,11 +645,13 @@ Jamstash.factory('subsonic', function ($rootScope, $http, $q, globals, utils, ma
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
console.log("getStarred: ", content);
|
||||||
deferred.resolve(content);
|
deferred.resolve(content);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return deferred.promise;
|
return deferred.promise;
|
||||||
},
|
},
|
||||||
|
*/
|
||||||
newPlaylist: function (data, event) {
|
newPlaylist: function (data, event) {
|
||||||
var deferred = $q.defer();
|
var deferred = $q.defer();
|
||||||
var reply = prompt("Choose a name for your new playlist.", "");
|
var reply = prompt("Choose a name for your new playlist.", "");
|
||||||
|
|
|
@ -70,7 +70,7 @@ jamstash.service('utils', function ($rootScope, $cookieStore, globals) {
|
||||||
this.switchTheme = function (theme) {
|
this.switchTheme = function (theme) {
|
||||||
switch (theme.toLowerCase()) {
|
switch (theme.toLowerCase()) {
|
||||||
case 'dark':
|
case 'dark':
|
||||||
$('link[data-name=theme]').attr('href', 'style/Dark.css');
|
$('link[data-name=theme]').attr('href', 'styles/Dark.css');
|
||||||
break;
|
break;
|
||||||
case 'default':
|
case 'default':
|
||||||
$('link[data-name=theme]').attr('href', '');
|
$('link[data-name=theme]').attr('href', '');
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
describe("Subsonic controller", function() {
|
describe("Subsonic controller", function() {
|
||||||
|
'use strict';
|
||||||
|
|
||||||
});
|
});
|
|
@ -29,7 +29,7 @@ module.exports = function(config) {
|
||||||
'bower_components/jplayer/jquery.jplayer/jquery.jplayer.js',
|
'bower_components/jplayer/jquery.jplayer/jquery.jplayer.js',
|
||||||
'bower_components/notify.js/notify.js',
|
'bower_components/notify.js/notify.js',
|
||||||
'js/**/*.js',
|
'js/**/*.js',
|
||||||
'test/**/*.js'
|
'test/**/*_test.js'
|
||||||
],
|
],
|
||||||
|
|
||||||
// list of files / patterns to exclude
|
// list of files / patterns to exclude
|
||||||
|
@ -64,7 +64,7 @@ module.exports = function(config) {
|
||||||
|
|
||||||
// level of logging
|
// level of logging
|
||||||
// possible values: LOG_DISABLE || LOG_ERROR || LOG_WARN || LOG_INFO || LOG_DEBUG
|
// possible values: LOG_DISABLE || LOG_ERROR || LOG_WARN || LOG_INFO || LOG_DEBUG
|
||||||
logLevel: config.LOG_INFO,
|
logLevel: config.LOG_INFO
|
||||||
|
|
||||||
// Uncomment the following lines if you are using grunt's server to run the tests
|
// Uncomment the following lines if you are using grunt's server to run the tests
|
||||||
// proxies: {
|
// proxies: {
|
||||||
|
|
|
@ -7,12 +7,12 @@ describe("globals service", function() {
|
||||||
globals = _globals_;
|
globals = _globals_;
|
||||||
}));
|
}));
|
||||||
|
|
||||||
it("given 'http://subsonic.org/demo', when calling BaseURL() then I get 'http://subsonic.org/demo/rest'", function() {
|
it("Given 'http://subsonic.org/demo', when calling BaseURL() then I get 'http://subsonic.org/demo/rest'", function() {
|
||||||
globals.settings.Server = "http://subsonic.org/demo";
|
globals.settings.Server = "http://subsonic.org/demo";
|
||||||
expect(globals.BaseURL()).toBe("http://subsonic.org/demo/rest");
|
expect(globals.BaseURL()).toBe("http://subsonic.org/demo/rest");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("given a username, password, protocol, api version and application name, when calling BaseParams() then I get a concatenated string of url params", function () {
|
it("Given a username, password, protocol, api version and application name, when calling BaseParams() then I get a concatenated string of url params", function () {
|
||||||
globals.settings.Username = "jdoe";
|
globals.settings.Username = "jdoe";
|
||||||
globals.settings.Password = "testpassword";
|
globals.settings.Password = "testpassword";
|
||||||
globals.settings.Protocol = "jsonp";
|
globals.settings.Protocol = "jsonp";
|
||||||
|
@ -20,4 +20,6 @@ describe("globals service", function() {
|
||||||
globals.settings.ApplicationName = "MyApp";
|
globals.settings.ApplicationName = "MyApp";
|
||||||
expect(globals.BaseParams()).toBe("u=jdoe&p=testpassword&f=jsonp&v=1.10.2&c=MyApp");
|
expect(globals.BaseParams()).toBe("u=jdoe&p=testpassword&f=jsonp&v=1.10.2&c=MyApp");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
//TODO: JMA: add callback param if jsonp
|
||||||
});
|
});
|
|
@ -1,15 +0,0 @@
|
||||||
describe("subsonicService", function() {
|
|
||||||
'use strict';
|
|
||||||
/*
|
|
||||||
var Subsonic;
|
|
||||||
beforeEach(module('JamStash'));
|
|
||||||
beforeEach(inject(function (subsonic) {
|
|
||||||
Subsonic = subsonic;
|
|
||||||
}));
|
|
||||||
|
|
||||||
it("should exist", inject(function(subsonic) {
|
|
||||||
expect(subsonic).toBeDefined();
|
|
||||||
}));
|
|
||||||
*/
|
|
||||||
|
|
||||||
});
|
|
|
@ -1,15 +1,51 @@
|
||||||
describe("subsonicService", function() {
|
describe("subsonic service -", function() {
|
||||||
'use strict';
|
'use strict';
|
||||||
/*
|
|
||||||
var Subsonic;
|
|
||||||
beforeEach(module('JamStash'));
|
|
||||||
beforeEach(inject(function (subsonic) {
|
|
||||||
Subsonic = subsonic;
|
|
||||||
}));
|
|
||||||
|
|
||||||
it("should exist", inject(function(subsonic) {
|
var subsonic, mockBackend;
|
||||||
expect(subsonic).toBeDefined();
|
|
||||||
}));
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
describe("Given that the global setting AutoPlaylist Size is 3", function() {
|
||||||
|
var mockGlobals = {
|
||||||
|
settings: {
|
||||||
|
AutoPlaylistSize: 3,
|
||||||
|
protocol: 'jsonp'
|
||||||
|
},
|
||||||
|
BaseURL: function () {
|
||||||
|
return 'http://subsonic.furinax.com/rest';
|
||||||
|
},
|
||||||
|
BaseParams: function () {
|
||||||
|
return 'u=Hyzual&p=enc:7375622e6461726b353079306432&v=1.10.2&c=Jamstash&f=jsonp';
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
beforeEach(function() {
|
||||||
|
module('JamStash', function ($provide) {
|
||||||
|
$provide.value('globals', mockGlobals);
|
||||||
|
});
|
||||||
|
|
||||||
|
inject(function (_subsonic_, $httpBackend) {
|
||||||
|
subsonic = _subsonic_;
|
||||||
|
mockBackend = $httpBackend;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(function() {
|
||||||
|
mockBackend.verifyNoOutstandingExpectation();
|
||||||
|
mockBackend.verifyNoOutstandingRequest();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("and given that I have more than 3 starred songs in my library, when getting the starred artists, the result should be limited to 3 starred artists", function() {
|
||||||
|
|
||||||
|
var url = 'http://subsonic.furinax.com/rest/getStarred.view?'+
|
||||||
|
'callback=JSON_CALLBACK&u=Hyzual&p=enc:7375622e6461726b353079306432&v=1.10.2&c=Jamstash&f=jsonp';
|
||||||
|
var response = '{"subsonic-response": {"status": "ok","version": "1.10.2","starred": {"song": [{"id": "11841"},{"id": "12061"},{"id": "17322"},{"id": "1547"}]}}}';
|
||||||
|
|
||||||
|
var limitedStarred = [{id: "11841"},{id: "12061"},{id: "17322"}];
|
||||||
|
mockBackend.whenJSONP(url).respond(200, response);
|
||||||
|
var success = jasmine.createSpy('success');
|
||||||
|
|
||||||
|
subsonic.getStarred().then(success);
|
||||||
|
mockBackend.flush();
|
||||||
|
expect(success).toHaveBeenCalledWith(limitedStarred);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
Loading…
Add table
Add a link
Reference in a new issue