Explorar o código

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

Patrick O'Carroll %!s(int64=8) %!d(string=hai) anos
pai
achega
95250e4ea3

+ 0 - 2
public/app/core/components/layout_selector/layout_selector.ts

@@ -1,5 +1,3 @@
-///<reference path="../../../headers/common.d.ts" />
-
 import store from 'app/core/store';
 import coreModule from 'app/core/core_module';
 

+ 44 - 0
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);
+  });
+
+});
+
+

+ 0 - 26
public/app/core/store.js

@@ -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);
-    }
-
-  };
-
-});

+ 29 - 0
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;

+ 0 - 2
public/app/features/dashboard/impression_store.ts

@@ -1,5 +1,3 @@
-///<reference path="../../headers/common.d.ts" />
-
 import store from 'app/core/store';
 import _ from 'lodash';
 import config from 'app/core/config';