Commit 95250e4e by Patrick O'Carroll Committed by Torkel Ödegaard

replace store.js with store.ts, test for store.ts (#9646)

parent 676a1139
///<reference path="../../../headers/common.d.ts" />
import store from 'app/core/store';
import coreModule from 'app/core/core_module';
......
import store from '../store';
Object.assign(window, {
localStorage: {
removeItem(key) {
delete window.localStorage[key];
}
}
});
describe('store', () => {
it("should store", ()=> {
store.set("key1", "123");
expect(store.get("key1")).toBe("123");
});
it("get key when undefined", ()=> {
expect(store.get("key2")).toBe(undefined);
});
it("check if key exixts", ()=> {
store.set("key3", "123");
expect(store.exists("key3")).toBe(true);
});
it("get boolean when no key", ()=> {
expect(store.getBool("key4", false)).toBe(false);
});
it("get boolean", ()=> {
store.set("key5", "true");
expect(store.getBool("key5", false)).toBe(true);
});
it("key should be deleted", ()=> {
store.set("key6", "123");
store.delete("key6");
expect(store.exists("key6")).toBe(false);
});
});
define([], function() {
'use strict';
return {
get: function(key) {
return window.localStorage[key];
},
set: function(key, value) {
window.localStorage[key] = value;
},
getBool: function(key, def) {
if (def !== void 0 && !this.exists(key)) {
return def;
}
return window.localStorage[key] === 'true';
},
exists: function(key) {
return window.localStorage[key] !== void 0;
},
delete: function(key) {
window.localStorage.removeItem(key);
}
};
});
export class Store {
get(key) {
return window.localStorage[key];
}
set(key, value) {
window.localStorage[key] = value;
}
getBool(key, def) {
if (def !== void 0 && !this.exists(key)) {
return def;
}
return window.localStorage[key] === 'true';
}
exists(key) {
return window.localStorage[key] !== void 0;
}
delete(key) {
window.localStorage.removeItem(key);
}
}
const store = new Store();
export default store;
///<reference path="../../headers/common.d.ts" />
import store from 'app/core/store';
import _ from 'lodash';
import config from 'app/core/config';
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment