diff --git a/src/js/service/palette/PaletteService.js b/src/js/service/palette/PaletteService.js index d083ee40..90bd7c1f 100644 --- a/src/js/service/palette/PaletteService.js +++ b/src/js/service/palette/PaletteService.js @@ -3,11 +3,12 @@ ns.PaletteService = function () { this.dynamicPalettes = []; - this.localStorageService = window.localStorage; + // Exposed for tests. + this.localStorageGlobal = window.localStorage; }; ns.PaletteService.prototype.getPalettes = function () { - var palettesString = this.localStorageService.getItem('piskel.palettes'); + var palettesString = this.localStorageGlobal.getItem('piskel.palettes'); var palettes = JSON.parse(palettesString) || []; palettes = palettes.map(function (palette) { return pskl.model.Palette.fromObject(palette); @@ -54,7 +55,7 @@ palettes = palettes.filter(function (palette) { return this.dynamicPalettes.indexOf(palette) === -1; }.bind(this)); - this.localStorageService.setItem('piskel.palettes', JSON.stringify(palettes)); + this.localStorageGlobal.setItem('piskel.palettes', JSON.stringify(palettes)); $.publish(Events.PALETTE_LIST_UPDATED); }; diff --git a/test/js/service/palette/PaletteServiceTest.js b/test/js/service/palette/PaletteServiceTest.js index a2b5d38a..bcc72869 100644 --- a/test/js/service/palette/PaletteServiceTest.js +++ b/test/js/service/palette/PaletteServiceTest.js @@ -2,7 +2,7 @@ describe("Palette Service", function() { var paletteService = null; var localStorage = {}; - var localStorageService; + var localStorageGlobal; var addPalette = function (id, name, color) { @@ -24,7 +24,7 @@ describe("Palette Service", function() { beforeEach(function() { localStorage = {}; - localStorageService = { + localStorageGlobal = { getItem : function (key) { if (localStorage.hasOwnProperty(key)) { return localStorage[key]; @@ -38,21 +38,21 @@ describe("Palette Service", function() { }; paletteService = new pskl.service.palette.PaletteService(); - paletteService.localStorageService = localStorageService; + paletteService.localStorageGlobal = localStorageGlobal; }); it("returns an empty array when no palette is stored", function() { - spyOn(localStorageService, 'getItem').and.callThrough(); + spyOn(localStorageGlobal, 'getItem').and.callThrough(); var palettes = paletteService.getPalettes(); expect(Array.isArray(palettes)).toBe(true); expect(palettes.length).toBe(0); - expect(localStorageService.getItem).toHaveBeenCalled(); + expect(localStorageGlobal.getItem).toHaveBeenCalled(); }); it("can store a palette", function() { // when - spyOn(localStorageService, 'setItem').and.callThrough(); + spyOn(localStorageGlobal, 'setItem').and.callThrough(); var paletteId = 'palette-id'; var paletteName = 'palette-name'; @@ -63,7 +63,7 @@ describe("Palette Service", function() { var palettes = paletteService.getPalettes(); // verify - expect(localStorageService.setItem).toHaveBeenCalled(); + expect(localStorageGlobal.setItem).toHaveBeenCalled(); expect(Array.isArray(palettes)).toBe(true); expect(palettes.length).toBe(1);