mirror of
https://github.com/piskelapp/piskel.git
synced 2023-08-10 21:12:52 +03:00
Issue #640 - rename PaletteService pointer to localStorage to localStorageGlobal
PaletteService exposes window.localStorage as this.localStorageService. This is confusing since we also have the LocalStorageService class used to save piskels in local storage.
This commit is contained in:
parent
183133496e
commit
af65344c23
@ -3,11 +3,12 @@
|
|||||||
|
|
||||||
ns.PaletteService = function () {
|
ns.PaletteService = function () {
|
||||||
this.dynamicPalettes = [];
|
this.dynamicPalettes = [];
|
||||||
this.localStorageService = window.localStorage;
|
// Exposed for tests.
|
||||||
|
this.localStorageGlobal = window.localStorage;
|
||||||
};
|
};
|
||||||
|
|
||||||
ns.PaletteService.prototype.getPalettes = function () {
|
ns.PaletteService.prototype.getPalettes = function () {
|
||||||
var palettesString = this.localStorageService.getItem('piskel.palettes');
|
var palettesString = this.localStorageGlobal.getItem('piskel.palettes');
|
||||||
var palettes = JSON.parse(palettesString) || [];
|
var palettes = JSON.parse(palettesString) || [];
|
||||||
palettes = palettes.map(function (palette) {
|
palettes = palettes.map(function (palette) {
|
||||||
return pskl.model.Palette.fromObject(palette);
|
return pskl.model.Palette.fromObject(palette);
|
||||||
@ -54,7 +55,7 @@
|
|||||||
palettes = palettes.filter(function (palette) {
|
palettes = palettes.filter(function (palette) {
|
||||||
return this.dynamicPalettes.indexOf(palette) === -1;
|
return this.dynamicPalettes.indexOf(palette) === -1;
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
this.localStorageService.setItem('piskel.palettes', JSON.stringify(palettes));
|
this.localStorageGlobal.setItem('piskel.palettes', JSON.stringify(palettes));
|
||||||
$.publish(Events.PALETTE_LIST_UPDATED);
|
$.publish(Events.PALETTE_LIST_UPDATED);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@ describe("Palette Service", function() {
|
|||||||
var paletteService = null;
|
var paletteService = null;
|
||||||
var localStorage = {};
|
var localStorage = {};
|
||||||
|
|
||||||
var localStorageService;
|
var localStorageGlobal;
|
||||||
|
|
||||||
|
|
||||||
var addPalette = function (id, name, color) {
|
var addPalette = function (id, name, color) {
|
||||||
@ -24,7 +24,7 @@ describe("Palette Service", function() {
|
|||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
localStorage = {};
|
localStorage = {};
|
||||||
|
|
||||||
localStorageService = {
|
localStorageGlobal = {
|
||||||
getItem : function (key) {
|
getItem : function (key) {
|
||||||
if (localStorage.hasOwnProperty(key)) {
|
if (localStorage.hasOwnProperty(key)) {
|
||||||
return localStorage[key];
|
return localStorage[key];
|
||||||
@ -38,21 +38,21 @@ describe("Palette Service", function() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
paletteService = new pskl.service.palette.PaletteService();
|
paletteService = new pskl.service.palette.PaletteService();
|
||||||
paletteService.localStorageService = localStorageService;
|
paletteService.localStorageGlobal = localStorageGlobal;
|
||||||
});
|
});
|
||||||
|
|
||||||
it("returns an empty array when no palette is stored", function() {
|
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();
|
var palettes = paletteService.getPalettes();
|
||||||
expect(Array.isArray(palettes)).toBe(true);
|
expect(Array.isArray(palettes)).toBe(true);
|
||||||
expect(palettes.length).toBe(0);
|
expect(palettes.length).toBe(0);
|
||||||
expect(localStorageService.getItem).toHaveBeenCalled();
|
expect(localStorageGlobal.getItem).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("can store a palette", function() {
|
it("can store a palette", function() {
|
||||||
// when
|
// when
|
||||||
spyOn(localStorageService, 'setItem').and.callThrough();
|
spyOn(localStorageGlobal, 'setItem').and.callThrough();
|
||||||
|
|
||||||
var paletteId = 'palette-id';
|
var paletteId = 'palette-id';
|
||||||
var paletteName = 'palette-name';
|
var paletteName = 'palette-name';
|
||||||
@ -63,7 +63,7 @@ describe("Palette Service", function() {
|
|||||||
var palettes = paletteService.getPalettes();
|
var palettes = paletteService.getPalettes();
|
||||||
|
|
||||||
// verify
|
// verify
|
||||||
expect(localStorageService.setItem).toHaveBeenCalled();
|
expect(localStorageGlobal.setItem).toHaveBeenCalled();
|
||||||
|
|
||||||
expect(Array.isArray(palettes)).toBe(true);
|
expect(Array.isArray(palettes)).toBe(true);
|
||||||
expect(palettes.length).toBe(1);
|
expect(palettes.length).toBe(1);
|
||||||
|
Loading…
Reference in New Issue
Block a user