Make a more generic solution: KeyValueMapStore

- As QueryPersistence, stored in the localStorage too but it is now more generic and has nothing to do with Query
 - Add some js unit testing
This commit is contained in:
Jean-Baptiste Bellet
2021-05-31 10:43:54 +02:00
parent f167b09397
commit 7008b5ec7b
4 changed files with 73 additions and 36 deletions

View File

@@ -0,0 +1,38 @@
describe "Test KeyValueMapStore service", ->
KeyValueMapStore = null
beforeEach ->
module "ofn.admin"
beforeEach inject (_KeyValueMapStore_) ->
KeyValueMapStore = _KeyValueMapStore_
it "set and restore filters", ->
KeyValueMapStore.localStorageKey = 'localStorageKey'
KeyValueMapStore.storableKeys = ["a", "b", "c"]
source =
a: "1",
b: "2",
d: "4"
KeyValueMapStore.setStoredValues(source)
source = {}
restored = KeyValueMapStore.restoreValues(source)
expect(restored).toEqual true
expect(source).toEqual {a: '1', b: '2'}
it "clear filters", ->
KeyValueMapStore.storageKey = 'localStorageKey'
KeyValueMapStore.storableFilters = ["a", "b", "c"]
source =
a: "1",
b: "2",
d: "4"
KeyValueMapStore.setStoredValues(source)
KeyValueMapStore.clearKeyValueMap()
source = {}
restored = KeyValueMapStore.restoreValues(source)
expect(restored).toEqual false
expect(source).toEqual {}