diff --git a/Gruntfile.js b/Gruntfile.js index 29e3cc2..a07677f 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -41,7 +41,7 @@ module.exports = function (grunt) { } }, jsTest: { - files: ['test/**/*.js'], + files: ['test/**/*_test.js'], tasks: ['karma:continuous:run'], //'newer:jshint:test'] }, styles: { @@ -52,14 +52,14 @@ module.exports = function (grunt) { files: ['Gruntfile.js'] }, livereload: { - options: { - livereload: '<%= connect.options.livereload %>' - }, files: [ '<%= yeoman.app %>/{,*/}*.html', '.tmp/styles/{,*/}*.css', '<%= yeoman.app %>/images/{,*/}*.{png,jpg,jpeg,gif,webp,svg}' ] + }, + options: { + livereload: '<%= connect.options.livereload %>' } }, @@ -126,7 +126,7 @@ module.exports = function (grunt) { options: { jshintrc: 'test/.jshintrc' }, - src: ['test/spec/{,*/}*.js'] + src: ['test/{,*/}*.js'] } }, diff --git a/js/services/subsonic-service.js b/js/services/subsonic-service.js index 9bbb17d..ec84a9d 100644 --- a/js/services/subsonic-service.js +++ b/js/services/subsonic-service.js @@ -427,7 +427,7 @@ Jamstash.factory('subsonic', function ($rootScope, $http, $q, globals, utils, ma if (genre !== '' && genre != 'Random') { genreParams = '&genre=' + genre; } - folderParams = ''; + var folderParams = ''; if (typeof folder == 'number' && folder !== '' && folder != 'all') { //alert(folder); folderParams = '&musicFolderId=' + folder; @@ -556,6 +556,30 @@ Jamstash.factory('subsonic', function ($rootScope, $http, $q, globals, utils, ma }); 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) { var deferred = $q.defer(); var size = globals.settings.AutoPlaylistSize; @@ -621,11 +645,13 @@ Jamstash.factory('subsonic', function ($rootScope, $http, $q, globals, utils, ma break; } } + console.log("getStarred: ", content); deferred.resolve(content); } }); return deferred.promise; }, +*/ newPlaylist: function (data, event) { var deferred = $q.defer(); var reply = prompt("Choose a name for your new playlist.", ""); diff --git a/js/services/utils-service.js b/js/services/utils-service.js index 18188f7..b7ce56f 100644 --- a/js/services/utils-service.js +++ b/js/services/utils-service.js @@ -70,7 +70,7 @@ jamstash.service('utils', function ($rootScope, $cookieStore, globals) { this.switchTheme = function (theme) { switch (theme.toLowerCase()) { case 'dark': - $('link[data-name=theme]').attr('href', 'style/Dark.css'); + $('link[data-name=theme]').attr('href', 'styles/Dark.css'); break; case 'default': $('link[data-name=theme]').attr('href', ''); diff --git a/test/controllers/subsonic_test.js b/test/controllers/subsonic_test.js index 7faa18e..a2c46b9 100644 --- a/test/controllers/subsonic_test.js +++ b/test/controllers/subsonic_test.js @@ -1,4 +1,4 @@ describe("Subsonic controller", function() { - - + 'use strict'; + }); \ No newline at end of file diff --git a/test/karma.conf.js b/test/karma.conf.js index 066f322..5838755 100644 --- a/test/karma.conf.js +++ b/test/karma.conf.js @@ -29,7 +29,7 @@ module.exports = function(config) { 'bower_components/jplayer/jquery.jplayer/jquery.jplayer.js', 'bower_components/notify.js/notify.js', 'js/**/*.js', - 'test/**/*.js' + 'test/**/*_test.js' ], // list of files / patterns to exclude @@ -64,7 +64,7 @@ module.exports = function(config) { // level of logging // 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 // proxies: { diff --git a/test/services/globals-service_test.js b/test/services/globals-service_test.js index f7e7356..1f87313 100644 --- a/test/services/globals-service_test.js +++ b/test/services/globals-service_test.js @@ -7,12 +7,12 @@ describe("globals service", function() { 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"; 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.Password = "testpassword"; globals.settings.Protocol = "jsonp"; @@ -20,4 +20,6 @@ describe("globals service", function() { globals.settings.ApplicationName = "MyApp"; expect(globals.BaseParams()).toBe("u=jdoe&p=testpassword&f=jsonp&v=1.10.2&c=MyApp"); }); + + //TODO: JMA: add callback param if jsonp }); \ No newline at end of file diff --git a/test/services/subsonic-service.js b/test/services/subsonic-service.js deleted file mode 100644 index 4999171..0000000 --- a/test/services/subsonic-service.js +++ /dev/null @@ -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(); - })); -*/ - -}); \ No newline at end of file diff --git a/test/services/subsonic-service_test.js b/test/services/subsonic-service_test.js index fd96d9b..067e254 100644 --- a/test/services/subsonic-service_test.js +++ b/test/services/subsonic-service_test.js @@ -1,15 +1,51 @@ -describe("subsonicService", function() { - 'use strict'; -/* - var Subsonic; - beforeEach(module('JamStash')); - beforeEach(inject(function (subsonic) { - Subsonic = subsonic; - })); +describe("subsonic service -", function() { + 'use strict'; - it("should exist", inject(function(subsonic) { - expect(subsonic).toBeDefined(); - })); -*/ + var subsonic, mockBackend; + 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); + }); + }); }); \ No newline at end of file