From a6854e33f6aedb43da4b3d73753262b381b7d0f4 Mon Sep 17 00:00:00 2001 From: Hyzual Date: Wed, 25 Mar 2015 23:57:09 +0100 Subject: [PATCH] Fixes the "non-finite value" error when volume has never been set - When Volume has never been stored in local storage, it causes "non-finite value" errors in jPlayer. persistence-service will now return 1.0 if it's not set. --- app/common/json_changelog.json | 2 +- app/common/persistence-service.js | 7 ++++++- app/common/persistence-service_test.js | 27 ++++++++++++++++---------- 3 files changed, 24 insertions(+), 12 deletions(-) diff --git a/app/common/json_changelog.json b/app/common/json_changelog.json index 1a0fdaf..c6dd965 100644 --- a/app/common/json_changelog.json +++ b/app/common/json_changelog.json @@ -2,7 +2,7 @@ { "date": "3/24/2015", "version": "4.4.5", "changes": [ - { "text": "- Code refactoring, fixes Podcasts retrieval"} + { "text": "- Code refactoring, fixes Podcasts retrieval."} ] }, { diff --git a/app/common/persistence-service.js b/app/common/persistence-service.js index a042e4c..02c145f 100644 --- a/app/common/persistence-service.js +++ b/app/common/persistence-service.js @@ -61,7 +61,12 @@ angular.module('jamstash.persistence', ['angular-locker', /* Manage player volume */ this.getVolume = function () { - return locker.get('Volume'); + var volume = locker.get('Volume'); + if (volume === undefined) { + locker.put('Volume', 1.0); + volume = 1.0; + } + return volume; }; this.saveVolume = function (volume) { diff --git a/app/common/persistence-service_test.js b/app/common/persistence-service_test.js index 71c04d9..5512dee 100644 --- a/app/common/persistence-service_test.js +++ b/app/common/persistence-service_test.js @@ -46,6 +46,9 @@ describe("Persistence service", function() { locker.get.and.callFake(function(key) { return fakeStorage[key]; }); + locker.put.and.callFake(function(key, value) { + fakeStorage[key] = value; + }); }); describe("loadTrackPosition() -", function() { @@ -132,11 +135,12 @@ describe("Persistence service", function() { expect(volume).toBe(0.46582); }); - it("Given that no volume value was previously saved in local storage, it returns undefined", function() { + it("Given that no volume value was previously saved in local storage, it will return 1.0 and set it in local storage", function() { var volume = persistence.getVolume(); expect(locker.get).toHaveBeenCalledWith('Volume'); - expect(volume).toBeUndefined(); + expect(volume).toBe(1.0); + expect(locker.put).toHaveBeenCalledWith('Volume', 1.0); }); }); @@ -151,7 +155,17 @@ describe("Persistence service", function() { }); describe("getSettings() -", function() { - it("Given previously saved user settings in local storage, it retrieves them", function() { + beforeEach(function() { + spyOn(persistence, 'upgradeVersion'); + json.getChangeLog.and.callFake(function (callback) { + callback([ + {version: '1.0.1'} + ]); + }); + fakeStorage.JamstashVersion = '1.0.1'; + }); + + it("Given previously saved user settings in local storage, a promise will be resovled with the user settings", function() { fakeStorage = { "Settings": { "url": "https://headed.com/aleurodidae/taistrel?a=roquet&b=trichophoric#cathole", @@ -170,13 +184,6 @@ describe("Persistence service", function() { it("Given that the previously stored Jamstash version was '1.0.0' and given the latest version in changelog.json was '1.0.1', when I get the settings, then upgradeVersion will be called", function() { fakeStorage.JamstashVersion = '1.0.0'; - spyOn(persistence, 'upgradeVersion'); - json.getChangeLog.and.callFake(function (callback) { - console.log('callback', callback); - callback([ - {version: '1.0.1'} - ]); - }); persistence.getSettings();