Browse Source

Fixes deleting LocalStorage item with user-id prefix

Mantas 5 years ago
parent
commit
e4bd02e4d3

+ 1 - 1
app/assets/javascripts/app/lib/app_init/local_storage.coffee

@@ -14,7 +14,7 @@ class App.LocalStorage
   @delete: (key, user_id) ->
     if _instance == undefined
       _instance ?= new _storeSingleton
-    _instance.delete(key)
+    _instance.delete(key, user_id)
 
   @clear: ->
     if _instance == undefined

+ 17 - 0
app/views/tests/local_storage.html.erb

@@ -0,0 +1,17 @@
+
+<link rel="stylesheet" href="/assets/tests/qunit-1.21.0.css">
+<script src="/assets/tests/qunit-1.21.0.js"></script>
+<script src="/assets/tests/local_storage.js"></script>
+
+<style type="text/css">
+body {
+  padding-top: 0px;
+}
+</style>
+
+<script type="text/javascript">
+</script>
+
+<div id="qunit" class="u-dontfold"></div>
+
+

+ 1 - 0
config/routes/test.rb

@@ -2,6 +2,7 @@ Zammad::Application.routes.draw do
 
   match '/tests_core',                        to: 'tests#core',                       via: :get
   match '/tests_session',                     to: 'tests#session',                    via: :get
+  match '/tests_local_storage',               to: 'tests#local_storage',              via: :get
   match '/tests_ui',                          to: 'tests#ui',                         via: :get
   match '/tests_model',                       to: 'tests#model',                      via: :get
   match '/tests_model_binding',               to: 'tests#model_binding',              via: :get

+ 30 - 0
public/assets/tests/local_storage.js

@@ -0,0 +1,30 @@
+window.onload = function() {
+
+test('Test item removal from local storage', function() {
+  var key   = 'test_key_1'
+  var value = 'test_value_1'
+
+  App.LocalStorage.set(key, value)
+
+  equal(App.LocalStorage.get(key), value)
+
+  App.LocalStorage.delete(key)
+
+  equal(App.LocalStorage.get(key), undefined)
+});
+
+test('Test user-specific item removal from local storage', function() {
+  var key     = 'test_key_2'
+  var value   = 'test_value_2'
+  var user_id = 2
+
+  App.LocalStorage.set(key, value, user_id)
+
+  equal(App.LocalStorage.get(key, user_id), value)
+
+  App.LocalStorage.delete(key, user_id)
+
+  equal(App.LocalStorage.get(key, user_id), undefined)
+});
+
+}