diff --git a/public/app/core/components/layout_selector/layout_selector.ts b/public/app/core/components/layout_selector/layout_selector.ts index b2071723677..98f806cd63e 100644 --- a/public/app/core/components/layout_selector/layout_selector.ts +++ b/public/app/core/components/layout_selector/layout_selector.ts @@ -1,5 +1,3 @@ -/// - import store from 'app/core/store'; import coreModule from 'app/core/core_module'; diff --git a/public/app/core/specs/store.jest.ts b/public/app/core/specs/store.jest.ts new file mode 100644 index 00000000000..44cb2a84959 --- /dev/null +++ b/public/app/core/specs/store.jest.ts @@ -0,0 +1,44 @@ +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); + }); + +}); + + diff --git a/public/app/core/store.js b/public/app/core/store.js deleted file mode 100644 index 504b0e5aff5..00000000000 --- a/public/app/core/store.js +++ /dev/null @@ -1,26 +0,0 @@ -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); - } - - }; - -}); diff --git a/public/app/core/store.ts b/public/app/core/store.ts new file mode 100644 index 00000000000..cbed16510ab --- /dev/null +++ b/public/app/core/store.ts @@ -0,0 +1,29 @@ +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; diff --git a/public/app/features/dashboard/impression_store.ts b/public/app/features/dashboard/impression_store.ts index a0f20f7ec75..68478aef09a 100644 --- a/public/app/features/dashboard/impression_store.ts +++ b/public/app/features/dashboard/impression_store.ts @@ -1,5 +1,3 @@ -/// - import store from 'app/core/store'; import _ from 'lodash'; import config from 'app/core/config';