Extracts everything related to localStorage in common/persistence-service.js
That way, whenever we want to use something else (like a JSON file, or a DB) we will only have to change persistence-service.js - Migrated the unit tests there too. - Added replay in case of jPlayer error.
This commit is contained in:
parent
3c809d1903
commit
42830bbdbf
8 changed files with 262 additions and 222 deletions
|
@ -57,79 +57,4 @@ describe("Main controller", function() {
|
|||
xdescribe("toggleSetting -", function() {
|
||||
|
||||
});
|
||||
|
||||
describe("load from localStorage -", function() {
|
||||
var fakeStorage;
|
||||
beforeEach(function() {
|
||||
fakeStorage = {};
|
||||
|
||||
spyOn(locker, "get").and.callFake(function(key) {
|
||||
return fakeStorage[key];
|
||||
});
|
||||
});
|
||||
|
||||
describe("loadTrackPosition -", function() {
|
||||
beforeEach(function() {
|
||||
spyOn(player, "load");
|
||||
});
|
||||
|
||||
it("Given that we previously saved the current track's position in local Storage, it loads the song we saved into the player", function() {
|
||||
var song = {
|
||||
id: 8626,
|
||||
name: 'Pectinatodenticulate',
|
||||
artist: 'Isiah Hosfield',
|
||||
album: 'Tammanyize'
|
||||
};
|
||||
fakeStorage = {
|
||||
'CurrentSong': song
|
||||
};
|
||||
|
||||
scope.loadTrackPosition();
|
||||
|
||||
expect(locker.get).toHaveBeenCalledWith('CurrentSong');
|
||||
expect(player.load).toHaveBeenCalledWith(song);
|
||||
});
|
||||
|
||||
it("Given that we didn't save anything in local Storage, it doesn't load anything", function() {
|
||||
scope.loadTrackPosition();
|
||||
expect(locker.get).toHaveBeenCalledWith('CurrentSong');
|
||||
expect(player.load).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe("loadQueue -", function() {
|
||||
beforeEach(function() {
|
||||
spyOn(notifications, "updateMessage");
|
||||
spyOn(player, "addSongs").and.callFake(function (songs) {
|
||||
// Update the queue length so that notifications work
|
||||
player.queue.length += songs.length;
|
||||
});
|
||||
});
|
||||
|
||||
it("Given that we previously saved the playing queue in local Storage, it fills the player's queue with what we saved and notifies the user", function() {
|
||||
var queue = [
|
||||
{ id: 8705 },
|
||||
{ id: 1617 },
|
||||
{ id: 9812 }
|
||||
];
|
||||
fakeStorage = {
|
||||
'CurrentQueue': queue
|
||||
};
|
||||
|
||||
scope.loadQueue();
|
||||
|
||||
expect(locker.get).toHaveBeenCalledWith('CurrentQueue');
|
||||
expect(player.addSongs).toHaveBeenCalledWith(queue);
|
||||
expect(notifications.updateMessage).toHaveBeenCalledWith('3 Saved Song(s)', true);
|
||||
});
|
||||
|
||||
it("Given that we didn't save anything in local Storage, it doesn't load anything", function() {
|
||||
scope.loadQueue();
|
||||
|
||||
expect(locker.get).toHaveBeenCalledWith('CurrentQueue');
|
||||
expect(player.addSongs).not.toHaveBeenCalled();
|
||||
expect(notifications.updateMessage).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue