Fixes tsquillario/Jamstash#206
- We no longer use toString() if the album's artist info is missing. - Moved date formatting to utils-service.js and added TODOs to use angular filters instead - Cleaned up utils-service.js and remove unused functions - We no longer exclude vendor js files in karma, so we can test our call to jquery.dateFormat
This commit is contained in:
parent
c90eb9f211
commit
f1870f2f5b
6 changed files with 56 additions and 87 deletions
|
@ -270,9 +270,6 @@ angular.module('JamStash')
|
|||
$scope.isActive = function (route) {
|
||||
return route === $location.path();
|
||||
};
|
||||
$rootScope.reloadRoute = function (reload) {
|
||||
utils.reloadRoute(reload);
|
||||
};
|
||||
$rootScope.getSplitPosition = function (scope, elm) {
|
||||
window.alert(elm.getBoundingClientRect().left);
|
||||
};
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
angular.module('jamstash.model', ['jamstash.utils'])
|
||||
|
||||
.service('model', ['utils', function (utils){
|
||||
.service('model', ['utils', function (utils) {
|
||||
'use strict';
|
||||
|
||||
this.Index = function (name, artist) {
|
||||
|
@ -57,12 +57,12 @@ angular.module('jamstash.model', ['jamstash.utils'])
|
|||
};
|
||||
}])
|
||||
|
||||
.service('map', ['$http', 'globals', 'utils', 'model', function ($http, globals, utils, model){
|
||||
.service('map', ['$http', 'globals', 'utils', 'model', function ($http, globals, utils, model) {
|
||||
'use strict';
|
||||
|
||||
this.mapAlbum = function (data) {
|
||||
var album = data;
|
||||
var title, coverartthumb, coverartfull, starred;
|
||||
var title, coverartthumb, coverartfull, starred, artist;
|
||||
if (typeof album.coverArt != 'undefined') {
|
||||
coverartthumb = globals.BaseURL() + '/getCoverArt.view?' + globals.BaseParams() + '&size=160&id=' + album.coverArt;
|
||||
coverartfull = globals.BaseURL() + '/getCoverArt.view?' + globals.BaseParams() + '&id=' + album.coverArt;
|
||||
|
@ -75,7 +75,9 @@ angular.module('jamstash.model', ['jamstash.utils'])
|
|||
} else {
|
||||
type = 'bytag';
|
||||
}
|
||||
return new model.Album(album.id, album.parent, title, album.artist.toString(), album.artistId, coverartthumb, coverartfull, $.format.date(new Date(album.created), "yyyy-MM-dd h:mm a"), starred, '', '', type);
|
||||
artist = (album.artist !== undefined) ? album.artist.toString() : '';
|
||||
//TODO: Hyz: we shouldn't format the date here but use a filter in the template
|
||||
return new model.Album(album.id, album.parent, title, artist, album.artistId, coverartthumb, coverartfull, utils.formatDate(new Date(album.created), "yyyy-MM-dd h:mm a"), starred, '', '', type);
|
||||
};
|
||||
|
||||
this.mapAlbums = function (albums) {
|
||||
|
|
|
@ -1,24 +1,30 @@
|
|||
describe("model service", function() {
|
||||
'use strict';
|
||||
'use strict';
|
||||
|
||||
var model, map;
|
||||
beforeEach(function() {
|
||||
module('jamstash.model');
|
||||
inject(function (_model_, _map_) {
|
||||
model = _model_;
|
||||
var model, map, utils;
|
||||
beforeEach(function() {
|
||||
module('jamstash.model', function ($provide) {
|
||||
$provide.decorator('utils', function ($delegate) {
|
||||
$delegate.formatDate = jasmine.createSpy("formatDate");
|
||||
return $delegate;
|
||||
});
|
||||
});
|
||||
inject(function (_model_, _map_, _utils_) {
|
||||
model = _model_;
|
||||
map = _map_;
|
||||
});
|
||||
});
|
||||
utils = _utils_;
|
||||
});
|
||||
});
|
||||
|
||||
it("given all the arguments, when calling Song() then the composite attributes are computed", function() {
|
||||
model.Song(21, 43, 3, "Know Your Enemy", "Yoko Kanno", "27", "Ghost in the Shell - Stand Alone Complex OST 3",
|
||||
"51", "cover.jpg", "big-cover.jpg", "385", "5", true, "mp3", "specs", "url", "0", "Awesome track");
|
||||
it("given all the arguments, when calling Song() then the composite attributes are computed", function() {
|
||||
model.Song(21, 43, 3, "Know Your Enemy", "Yoko Kanno", "27", "Ghost in the Shell - Stand Alone Complex OST 3",
|
||||
"51", "cover.jpg", "big-cover.jpg", "385", "5", true, "mp3", "specs", "url", "0", "Awesome track");
|
||||
|
||||
expect(model.selected).toBe(false);
|
||||
expect(model.playing).toBe(false);
|
||||
expect(model.time).toBe("06:25");
|
||||
expect(model.displayName).toBe("Know Your Enemy - Ghost in the Shell - Stand Alone Complex OST 3 - Yoko Kanno");
|
||||
});
|
||||
expect(model.selected).toBe(false);
|
||||
expect(model.playing).toBe(false);
|
||||
expect(model.time).toBe("06:25");
|
||||
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, then mapSong is called for each song", function() {
|
||||
var songs = [
|
||||
|
@ -52,6 +58,17 @@ describe("model service", function() {
|
|||
expect(result).toEqual(episodes);
|
||||
});
|
||||
|
||||
it("Given album data without artist info, when I map it to an Album, an Album with an empty artist name will be returned", function() {
|
||||
var albumData = {
|
||||
id: 584,
|
||||
artist: undefined,
|
||||
created: "2015-03-28T16:51:28.000Z"
|
||||
};
|
||||
|
||||
var result = map.mapAlbum(albumData);
|
||||
expect(result.artist).toEqual('');
|
||||
});
|
||||
|
||||
it("Given multiple albums, when I map them, then mapAlbum is called for each album", function() {
|
||||
var albums = [
|
||||
{ id: 941 },
|
||||
|
|
|
@ -58,11 +58,6 @@ angular.module('jamstash.utils', ['jamstash.settings.service'])
|
|||
return false;
|
||||
}
|
||||
};
|
||||
this.makeBaseAuth = function (user, password) {
|
||||
var tok = user + ':' + password;
|
||||
var hash = $.base64Encode(tok);
|
||||
return "Basic " + hash;
|
||||
};
|
||||
this.HexEncode = function (n) {
|
||||
for (var u = "0123456789abcdef", i = [], r = [], t = 0; t < 256; t++) {
|
||||
i[t] = u.charAt(t >> 4) + u.charAt(t & 15);
|
||||
|
@ -129,12 +124,13 @@ angular.module('jamstash.utils', ['jamstash.settings.service'])
|
|||
}
|
||||
return time;
|
||||
};
|
||||
this.arrayObjectIndexOf = function (myArray, searchTerm, property) {
|
||||
for (var i = 0, len = myArray.length; i < len; i++) {
|
||||
if (myArray[i][property] === searchTerm) { return i; }
|
||||
}
|
||||
return -1;
|
||||
|
||||
//TODO: Hyz: replace with using an angular date filter in the template
|
||||
this.formatDate = function (date, format) {
|
||||
var dateToformat = (angular.isDate(date)) ? date : new Date(date);
|
||||
return $.format.date(dateToformat, format);
|
||||
};
|
||||
|
||||
this.logObjectProperties = function (obj) {
|
||||
$.each(obj, function (key, value) {
|
||||
var parent = key;
|
||||
|
@ -147,25 +143,6 @@ angular.module('jamstash.utils', ['jamstash.settings.service'])
|
|||
}
|
||||
});
|
||||
};
|
||||
this.clickButton = function (el) {
|
||||
var el = $(el);
|
||||
if (el) {
|
||||
var classes = $(el).attr('class').split(" ");
|
||||
for (var i = 0, l = classes.length; i < l; ++i) {
|
||||
var types = ['shuffle', 'mute'];
|
||||
if (jQuery.inArray(classes[i], types) >= 0) {
|
||||
var up = classes[i] + '_up';
|
||||
if (el.hasClass(up)) {
|
||||
el.removeClass(up);
|
||||
return false;
|
||||
} else {
|
||||
el.addClass(up);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
this.findKeyForCode = function (code) {
|
||||
var map = {
|
||||
'keymap': [
|
||||
|
@ -219,22 +196,6 @@ angular.module('jamstash.utils', ['jamstash.settings.service'])
|
|||
});
|
||||
}
|
||||
};
|
||||
this.getParameterByName = function (name) {
|
||||
name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
|
||||
var regexS = "[\\?&]" + name + "=([^&#]*)";
|
||||
var regex = new RegExp(regexS);
|
||||
var results = regex.exec(window.location.search);
|
||||
if (results === null) {
|
||||
return "";
|
||||
} else {
|
||||
return decodeURIComponent(results[1].replace(/\+/g, " "));
|
||||
}
|
||||
};
|
||||
this.getPathFromUrl = function (url) {
|
||||
var strurl = url.toString();
|
||||
var u = strurl.substring(0, strurl.indexOf('?'));
|
||||
return u;
|
||||
};
|
||||
|
||||
this.parseVersionString = function (str) {
|
||||
if (typeof (str) !== 'string') { return false; }
|
||||
|
@ -299,21 +260,4 @@ angular.module('jamstash.utils', ['jamstash.settings.service'])
|
|||
}
|
||||
}
|
||||
};
|
||||
|
||||
this.reloadRoute = function (date) {
|
||||
if (reload) {
|
||||
$window.location.reload();
|
||||
} else {
|
||||
$route.reload();
|
||||
}
|
||||
};
|
||||
this.parseDate = function (date) {
|
||||
// input: "2012-09-23 20:00:00.0"
|
||||
var months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
|
||||
var parts = date.split(" ");
|
||||
var dateParts = parts[0].split("-");
|
||||
var month = parseInt(dateParts[1], 10) - 1;
|
||||
var newDate = months[month] + " " + dateParts[2] + ", " + dateParts[0];
|
||||
return newDate;
|
||||
};
|
||||
}]);
|
||||
|
|
|
@ -152,4 +152,13 @@ describe("utils service", function() {
|
|||
expect(utils.checkVersionNewer(newer, older)).toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
||||
it("formatDate() - Given a Date and a text format, when I format a Date, jQuery's format date will be called and a formatted string will be returned", function() {
|
||||
spyOn($.format, 'date');
|
||||
var date = new Date('2015-03-28T16:54:40+01:00');
|
||||
|
||||
utils.formatDate(date, 'yyyy-MM-dd h:mm a');
|
||||
|
||||
expect($.format.date).toHaveBeenCalledWith(date, 'yyyy-MM-dd h:mm a');
|
||||
});
|
||||
});
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
// Generated on 2014-10-26 using
|
||||
// generator-karma 0.8.3
|
||||
|
||||
module.exports = function(config) {
|
||||
module.exports = function (config) {
|
||||
'use strict';
|
||||
|
||||
config.set({
|
||||
|
@ -43,7 +43,7 @@ module.exports = function(config) {
|
|||
],
|
||||
|
||||
// list of files / patterns to exclude
|
||||
exclude: ['app/vendor/**/*.js'],
|
||||
// exclude: ['app/vendor/**/*.js'],
|
||||
|
||||
preprocessors: {
|
||||
'app/**/!(*_test).js': ['coverage']
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue