angular-storage
Advanced tools
Comparing version 0.0.9 to 0.0.10
{ | ||
"name": "a0-angular-storage", | ||
"version": "0.0.6", | ||
"version": "0.0.10", | ||
"authors": [ | ||
@@ -24,3 +24,4 @@ { | ||
"angular-mocks": ">= 1.2", | ||
"angular-scenario": ">= 1.2" | ||
"angular-scenario": ">= 1.2", | ||
"angular-cookies": ">= 1.2" | ||
}, | ||
@@ -27,0 +28,0 @@ "resolutions": { |
@@ -13,9 +13,27 @@ (function() { | ||
angular.module('angular-storage.internalStore', ['angular-storage.storage']) | ||
.factory('InternalStore', ["storage", "$log", function(storage, $log) { | ||
angular.module('angular-storage.cookieStorage', []) | ||
.service('cookieStorage', ["$injector", function ($injector) { | ||
var $cookieStore = $injector.get('$cookieStore'); | ||
function InternalStore(namespace, delimiter) { | ||
this.set = function (what, value) { | ||
return $cookieStore.put(what, value); | ||
}; | ||
this.get = function (what) { | ||
return $cookieStore.get(what); | ||
}; | ||
this.remove = function (what) { | ||
return $cookieStore.remove(what); | ||
}; | ||
}]); | ||
angular.module('angular-storage.internalStore', ['angular-storage.localStorage', 'angular-storage.sessionStorage']) | ||
.factory('InternalStore', ["$log", "$injector", function($log, $injector) { | ||
function InternalStore(namespace, storage, delimiter) { | ||
this.namespace = namespace || null; | ||
this.delimiter = delimiter || '.'; | ||
this.inMemoryCache = {}; | ||
this.storage = $injector.get(storage || 'localStorage'); | ||
} | ||
@@ -31,7 +49,5 @@ | ||
InternalStore.prototype.set = function(name, elem) { | ||
this.inMemoryCache[name] = elem; | ||
storage.set(this.getNamespacedKey(name), JSON.stringify(elem)); | ||
this.storage.set(this.getNamespacedKey(name), JSON.stringify(elem)); | ||
}; | ||
@@ -44,6 +60,6 @@ | ||
} | ||
var saved = storage.get(this.getNamespacedKey(name)); | ||
var saved = this.storage.get(this.getNamespacedKey(name)); | ||
try { | ||
if (typeof saved ==="undefined" || saved === "undefined") { | ||
if (typeof saved === 'undefined' || saved === 'undefined') { | ||
obj = undefined; | ||
@@ -56,3 +72,3 @@ } else { | ||
} catch(e) { | ||
$log.error("Error parsing saved value", e); | ||
$log.error('Error parsing saved value', e); | ||
this.remove(name); | ||
@@ -65,52 +81,103 @@ } | ||
this.inMemoryCache[name] = null; | ||
storage.remove(this.getNamespacedKey(name)); | ||
this.storage.remove(this.getNamespacedKey(name)); | ||
}; | ||
return InternalStore; | ||
}]); | ||
}]); | ||
angular.module('angular-storage.localStorage', ['angular-storage.cookieStorage']) | ||
.service('localStorage', ["$window", "$injector", function ($window, $injector) { | ||
var localStorageAvailable = !!$window.localStorage; | ||
angular.module('angular-storage.storage', []) | ||
.service('storage', ["$window", "$injector", function($window, $injector) { | ||
if ($window.localStorage) { | ||
this.set = function(what, value) { | ||
if (localStorageAvailable) { | ||
try { | ||
$window.localStorage.setItem('testKey', 'test'); | ||
$window.localStorage.removeItem('testKey'); | ||
localStorageAvailable = true; | ||
} catch(e) { | ||
localStorageAvailable = false; | ||
} | ||
} | ||
if (localStorageAvailable) { | ||
this.set = function (what, value) { | ||
return $window.localStorage.setItem(what, value); | ||
}; | ||
this.get = function(what) { | ||
this.get = function (what) { | ||
return $window.localStorage.getItem(what); | ||
}; | ||
this.remove = function(what) { | ||
this.remove = function (what) { | ||
return $window.localStorage.removeItem(what); | ||
}; | ||
} else { | ||
var $cookieStore = $injector.get('$cookieStore'); | ||
this.set = function(what, value) { | ||
return $cookieStore.put(what, value); | ||
var cookieStorage = $injector.get('cookieStorage'); | ||
this.set = cookieStorage.set; | ||
this.get = cookieStorage.get; | ||
this.remove = cookieStorage.remove; | ||
} | ||
}]); | ||
angular.module('angular-storage.sessionStorage', ['angular-storage.cookieStorage']) | ||
.service('sessionStorage', ["$window", "$injector", function ($window, $injector) { | ||
if ($window.sessionStorage) { | ||
this.set = function (what, value) { | ||
return $window.sessionStorage.setItem(what, value); | ||
}; | ||
this.get = function(what) { | ||
return $cookieStore.get(what); | ||
this.get = function (what) { | ||
return $window.sessionStorage.getItem(what); | ||
}; | ||
this.remove = function(what) { | ||
return $cookieStore.remove(what); | ||
this.remove = function (what) { | ||
return $window.sessionStorage.removeItem(what); | ||
}; | ||
} else { | ||
var cookieStorage = $injector.get('cookieStorage'); | ||
this.set = cookieStorage.set; | ||
this.get = cookieStorage.get; | ||
this.remove = cookieStorage.remove; | ||
} | ||
}]); | ||
angular.module('angular-storage.store', ['angular-storage.internalStore']) | ||
.factory('store', ["InternalStore", function(InternalStore) { | ||
.provider('store', function() { | ||
var store = new InternalStore(); | ||
store.getNamespacedStore = function(namespace, key) { | ||
return new InternalStore(namespace, key); | ||
} | ||
// the default storage | ||
var _storage = 'localStorage'; | ||
return store; | ||
/** | ||
* Sets the storage. | ||
* | ||
* @param {String} storage The storage name | ||
*/ | ||
this.setStore = function(storage) { | ||
if (storage && angular.isString(storage)) { | ||
_storage = storage; | ||
} | ||
}; | ||
this.$get = ["InternalStore", function(InternalStore) { | ||
var store = new InternalStore(null, _storage); | ||
}]); | ||
/** | ||
* Returns a namespaced store | ||
* | ||
* @param {String} namespace The namespace | ||
* @param {String} storage The name of the storage service | ||
* @param {String} key The key | ||
* @returns {InternalStore} | ||
*/ | ||
store.getNamespacedStore = function(namespace, storage, key) { | ||
return new InternalStore(namespace, storage, key); | ||
}; | ||
return store; | ||
}]; | ||
}); | ||
}()); |
@@ -1,1 +0,1 @@ | ||
!function(){angular.module("angular-storage",["angular-storage.store"]),angular.module("angular-storage.internalStore",["angular-storage.storage"]).factory("InternalStore",["storage","$log",function(e,t){function r(e,t){this.namespace=e||null,this.delimiter=t||".",this.inMemoryCache={}}return r.prototype.getNamespacedKey=function(e){return this.namespace?[this.namespace,e].join(this.delimiter):e},r.prototype.set=function(t,r){this.inMemoryCache[t]=r,e.set(this.getNamespacedKey(t),JSON.stringify(r))},r.prototype.get=function(r){var n=null;if(r in this.inMemoryCache)return this.inMemoryCache[r];var o=e.get(this.getNamespacedKey(r));try{n="undefined"==typeof o||"undefined"===o?void 0:JSON.parse(o),this.inMemoryCache[r]=n}catch(a){t.error("Error parsing saved value",a),this.remove(r)}return n},r.prototype.remove=function(t){this.inMemoryCache[t]=null,e.remove(this.getNamespacedKey(t))},r}]),angular.module("angular-storage.storage",[]).service("storage",["$window","$injector",function(e,t){if(e.localStorage)this.set=function(t,r){return e.localStorage.setItem(t,r)},this.get=function(t){return e.localStorage.getItem(t)},this.remove=function(t){return e.localStorage.removeItem(t)};else{var r=t.get("$cookieStore");this.set=function(e,t){return r.put(e,t)},this.get=function(e){return r.get(e)},this.remove=function(e){return r.remove(e)}}}]),angular.module("angular-storage.store",["angular-storage.internalStore"]).factory("store",["InternalStore",function(e){var t=new e;return t.getNamespacedStore=function(t,r){return new e(t,r)},t}])}(); | ||
!function(){angular.module("angular-storage",["angular-storage.store"]),angular.module("angular-storage.cookieStorage",[]).service("cookieStorage",["$injector",function(e){var t=e.get("$cookieStore");this.set=function(e,r){return t.put(e,r)},this.get=function(e){return t.get(e)},this.remove=function(e){return t.remove(e)}}]),angular.module("angular-storage.internalStore",["angular-storage.localStorage","angular-storage.sessionStorage"]).factory("InternalStore",["$log","$injector",function(e,t){function r(e,r,o){this.namespace=e||null,this.delimiter=o||".",this.inMemoryCache={},this.storage=t.get(r||"localStorage")}return r.prototype.getNamespacedKey=function(e){return this.namespace?[this.namespace,e].join(this.delimiter):e},r.prototype.set=function(e,t){this.inMemoryCache[e]=t,this.storage.set(this.getNamespacedKey(e),JSON.stringify(t))},r.prototype.get=function(t){var r=null;if(t in this.inMemoryCache)return this.inMemoryCache[t];var o=this.storage.get(this.getNamespacedKey(t));try{r="undefined"==typeof o||"undefined"===o?void 0:JSON.parse(o),this.inMemoryCache[t]=r}catch(a){e.error("Error parsing saved value",a),this.remove(t)}return r},r.prototype.remove=function(e){this.inMemoryCache[e]=null,this.storage.remove(this.getNamespacedKey(e))},r}]),angular.module("angular-storage.localStorage",["angular-storage.cookieStorage"]).service("localStorage",["$window","$injector",function(e,t){var r=!!e.localStorage;if(r)try{e.localStorage.setItem("testKey","test"),e.localStorage.removeItem("testKey"),r=!0}catch(o){r=!1}if(r)this.set=function(t,r){return e.localStorage.setItem(t,r)},this.get=function(t){return e.localStorage.getItem(t)},this.remove=function(t){return e.localStorage.removeItem(t)};else{var a=t.get("cookieStorage");this.set=a.set,this.get=a.get,this.remove=a.remove}}]),angular.module("angular-storage.sessionStorage",["angular-storage.cookieStorage"]).service("sessionStorage",["$window","$injector",function(e,t){if(e.sessionStorage)this.set=function(t,r){return e.sessionStorage.setItem(t,r)},this.get=function(t){return e.sessionStorage.getItem(t)},this.remove=function(t){return e.sessionStorage.removeItem(t)};else{var r=t.get("cookieStorage");this.set=r.set,this.get=r.get,this.remove=r.remove}}]),angular.module("angular-storage.store",["angular-storage.internalStore"]).provider("store",function(){var e="localStorage";this.setStore=function(t){t&&angular.isString(t)&&(e=t)},this.$get=["InternalStore",function(t){var r=new t(null,e);return r.getNamespacedStore=function(e,r,o){return new t(e,r,o)},r}]})}(); |
@@ -6,2 +6,3 @@ var gulp = require('gulp'), | ||
rename = require('gulp-rename'), | ||
jshint = require('gulp-jshint'), | ||
ngAnnotate = require('gulp-ng-annotate'), | ||
@@ -15,4 +16,15 @@ sourceFiles = [ | ||
'src/angularStorage/angularStorage.suffix' | ||
], | ||
lintFiles = [ | ||
'src/angularStorage/**/*.js', | ||
'test/**/*.js', | ||
'gulpfile.js' | ||
]; | ||
gulp.task('lint', function() { | ||
return gulp.src(lintFiles) | ||
.pipe(jshint()) | ||
.pipe(jshint.reporter('jshint-stylish')); | ||
}); | ||
gulp.task('build', function() { | ||
@@ -25,3 +37,3 @@ gulp.src(sourceFiles) | ||
.pipe(rename('angular-storage.min.js')) | ||
.pipe(gulp.dest('./dist')) | ||
.pipe(gulp.dest('./dist')); | ||
}); | ||
@@ -39,2 +51,12 @@ | ||
/** | ||
* Run test once in all available browsers and exit | ||
*/ | ||
gulp.task('test-all', function (done) { | ||
karma.start({ | ||
configFile: __dirname + '/karma-src-all.conf.js', | ||
singleRun: true | ||
}, done); | ||
}); | ||
gulp.task('test-debug', function (done) { | ||
@@ -68,3 +90,24 @@ karma.start({ | ||
gulp.task('default', ['test', 'build']); | ||
/** | ||
* Run code coverage tests once and exit | ||
*/ | ||
gulp.task('cover', function (done) { | ||
karma.start({ | ||
configFile: __dirname + '/karma-src.conf.js', | ||
singleRun: true, | ||
preprocessors: { | ||
'src/**/*.js': 'coverage' | ||
}, | ||
coverageReporter: { | ||
type: 'html', | ||
dir: 'reports/coverage' | ||
}, | ||
reporters: ['mocha', 'coverage'] | ||
}, function() { | ||
console.log('Code coverage report created: %s', require('path').join(process.cwd(), 'reports', 'coverage')); | ||
done(); | ||
}); | ||
}); | ||
gulp.task('default', ['lint', 'test', 'build']); | ||
gulp.task('dist', ['test-dist-concatenated', 'test-dist-minified']); |
0.0.10 / 2015-04-17 | ||
=================== | ||
* Fixed private browsing error | ||
* Merge pull request #23 from joshuabc/package-json-main | ||
* Add `main` to package.json. Allows package to be required directly in Browserify environments. | ||
* Merge pull request #20 from 4kochi/master | ||
* test: add code coverage specific karma settings to the gulpfile | ||
* add code coverage task `gulp cover` | ||
* change store service to a provider | ||
* remove storage.js file, not needed any more | ||
* fix dist tests | ||
* add method setStorage() to the store service | ||
* add gulp task test-all to run the unit tests in all available browsers on the current system | ||
* also check gulpfile.js for jshint errors | ||
* fix jshint warnings | ||
* add lint task to gulp to check for jshint errors/warnings | ||
* changer version of angular-cookies in bower.json to fix resolution error when running bower install | ||
* add field repository to package.json to fix npm warning | ||
* Merge pull request #18 from kildareflare/fixCookies | ||
* add newly built dist files | ||
* remove ngCookie dependency and code tidy up after review | ||
* add cookie dependency to bower json | ||
* add missing ngCookie depednency. add missing test for cookie fallback | ||
* Update and rename LICENSE to LICENSE.txt | ||
* Updated CDN link | ||
0.0.6 / 2014-10-08 | ||
@@ -3,0 +30,0 @@ ================== |
@@ -30,2 +30,3 @@ // Karma configuration | ||
'bower/angular-mocks/angular-mocks.js', | ||
'bower/angular-cookies/angular-cookies.js', | ||
'dist/angular-storage.js', | ||
@@ -32,0 +33,0 @@ 'test/unit/**/*.js' |
@@ -30,2 +30,3 @@ // Karma configuration | ||
'bower/angular-mocks/angular-mocks.js', | ||
'bower/angular-cookies/angular-cookies.js', | ||
'dist/angular-storage.min.js', | ||
@@ -32,0 +33,0 @@ 'test/unit/**/*.js' |
@@ -23,3 +23,4 @@ // Karma configuration | ||
'karma-chai-jquery', | ||
'karma-mocha-reporter' | ||
'karma-mocha-reporter', | ||
'karma-coverage' | ||
], | ||
@@ -31,2 +32,3 @@ | ||
'bower/angular-mocks/angular-mocks.js', | ||
'bower/angular-cookies/angular-cookies.js', | ||
'src/**/*.js', | ||
@@ -33,0 +35,0 @@ 'test/unit/**/*.js' |
{ | ||
"name": "angular-storage", | ||
"version": "0.0.9", | ||
"version": "0.0.10", | ||
"main": "dist/angular-storage.js", | ||
"author": { | ||
@@ -8,2 +9,6 @@ "name": "Martin Gontovnikas", | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/auth0/angular-storage.git" | ||
}, | ||
"dependencies": {}, | ||
@@ -13,7 +18,9 @@ "devDependencies": { | ||
"chai-jquery": "^1.2.3", | ||
"gulp": "^3.8.7", | ||
"gulp": "^3.8.11", | ||
"gulp-concat": "^2.3.4", | ||
"gulp-jshint": "^1.9.2", | ||
"gulp-ng-annotate": "^0.3.3", | ||
"gulp-rename": "^1.2.0", | ||
"gulp-uglify": "^0.3.1", | ||
"jshint-stylish": "^1.0.0", | ||
"karma": "^0.12.22", | ||
@@ -23,6 +30,8 @@ "karma-chai": "^0.1.0", | ||
"karma-chrome-launcher": "^0.1.4", | ||
"karma-coverage": "^0.2.7", | ||
"karma-detect-browsers": "^1.1.2", | ||
"karma-jasmine": "^0.1.5", | ||
"karma-jquery": "^0.1.0", | ||
"karma-mocha": "^0.1.8", | ||
"karma-mocha-reporter": "^0.3.1", | ||
"karma-mocha-reporter": "^1.0.1", | ||
"karma-phantomjs-launcher": "^0.1.4", | ||
@@ -29,0 +38,0 @@ "karma-sinon-chai": "^0.2.0", |
@@ -25,3 +25,3 @@ # angular-storage | ||
````html | ||
<script type="text/javascript" src="https://rawgit.com/auth0/angular-storage/master/dist/angular-storage.js"></script> | ||
<script type="text/javascript" src="https://cdn.rawgit.com/auth0/angular-storage/master/dist/angular-storage.js"></script> | ||
```` | ||
@@ -28,0 +28,0 @@ |
@@ -1,8 +0,9 @@ | ||
angular.module('angular-storage.internalStore', ['angular-storage.storage']) | ||
.factory('InternalStore', function(storage, $log) { | ||
angular.module('angular-storage.internalStore', ['angular-storage.localStorage', 'angular-storage.sessionStorage']) | ||
.factory('InternalStore', function($log, $injector) { | ||
function InternalStore(namespace, delimiter) { | ||
function InternalStore(namespace, storage, delimiter) { | ||
this.namespace = namespace || null; | ||
this.delimiter = delimiter || '.'; | ||
this.inMemoryCache = {}; | ||
this.storage = $injector.get(storage || 'localStorage'); | ||
} | ||
@@ -18,7 +19,5 @@ | ||
InternalStore.prototype.set = function(name, elem) { | ||
this.inMemoryCache[name] = elem; | ||
storage.set(this.getNamespacedKey(name), JSON.stringify(elem)); | ||
this.storage.set(this.getNamespacedKey(name), JSON.stringify(elem)); | ||
}; | ||
@@ -31,6 +30,6 @@ | ||
} | ||
var saved = storage.get(this.getNamespacedKey(name)); | ||
var saved = this.storage.get(this.getNamespacedKey(name)); | ||
try { | ||
if (typeof saved ==="undefined" || saved === "undefined") { | ||
if (typeof saved === 'undefined' || saved === 'undefined') { | ||
obj = undefined; | ||
@@ -43,3 +42,3 @@ } else { | ||
} catch(e) { | ||
$log.error("Error parsing saved value", e); | ||
$log.error('Error parsing saved value', e); | ||
this.remove(name); | ||
@@ -52,9 +51,7 @@ } | ||
this.inMemoryCache[name] = null; | ||
storage.remove(this.getNamespacedKey(name)); | ||
this.storage.remove(this.getNamespacedKey(name)); | ||
}; | ||
return InternalStore; | ||
}); | ||
angular.module('angular-storage.store', ['angular-storage.internalStore']) | ||
.factory('store', function(InternalStore) { | ||
.provider('store', function() { | ||
var store = new InternalStore(); | ||
store.getNamespacedStore = function(namespace, key) { | ||
return new InternalStore(namespace, key); | ||
} | ||
// the default storage | ||
var _storage = 'localStorage'; | ||
return store; | ||
/** | ||
* Sets the storage. | ||
* | ||
* @param {String} storage The storage name | ||
*/ | ||
this.setStore = function(storage) { | ||
if (storage && angular.isString(storage)) { | ||
_storage = storage; | ||
} | ||
}; | ||
this.$get = function(InternalStore) { | ||
var store = new InternalStore(null, _storage); | ||
/** | ||
* Returns a namespaced store | ||
* | ||
* @param {String} namespace The namespace | ||
* @param {String} storage The name of the storage service | ||
* @param {String} key The key | ||
* @returns {InternalStore} | ||
*/ | ||
store.getNamespacedStore = function(namespace, storage, key) { | ||
return new InternalStore(namespace, storage, key); | ||
}; | ||
return store; | ||
}; | ||
}); | ||
@@ -70,11 +70,260 @@ 'use strict'; | ||
})); | ||
}); | ||
describe('angularStorage storeProvider.setStore("sessionStorage")', function () { | ||
var provider; | ||
beforeEach(function() { | ||
module('angular-storage.store', function(storeProvider) { | ||
provider = storeProvider; | ||
provider.setStore('sessionStorage'); | ||
}); | ||
}); | ||
it('should save items correctly in the sessionStorage', inject(function(store, $window) { | ||
var value = 99; | ||
store.set('gonto123', value); | ||
store.inMemoryCache = {}; | ||
expect(store.get('gonto123')).to.equal(value); | ||
expect($window.sessionStorage.getItem('gonto123')).to.exist; | ||
expect($window.sessionStorage.getItem('gonto123')).to.equal(value.toString()); | ||
store.remove('gonto123'); | ||
expect(store.get('gonto123')).to.not.exist; | ||
expect($window.sessionStorage.getItem('gonto123')).to.not.exist; | ||
})); | ||
}); | ||
describe('angularStorage new namespaced store', function() { | ||
describe('angularStorage storeProvider.setStore("sessionStorage")', function () { | ||
var provider, windowMock, $cookieStore; | ||
beforeEach(function() { | ||
module('angular-storage.store'); | ||
module('ngCookies', 'angular-storage.store', function(storeProvider, $provide) { | ||
provider = storeProvider; | ||
provider.setStore('sessionStorage'); | ||
windowMock = { sessionStorage: undefined }; | ||
$provide.value('$window', windowMock); | ||
}); | ||
}); | ||
beforeEach(inject(function( _$cookieStore_) { | ||
$cookieStore = _$cookieStore_; | ||
})); | ||
it('should fallback to cookieStorage', inject(function(store) { | ||
var value = 99; | ||
store.set('gonto123', value); | ||
expect(store.get('gonto123')).to.equal(value); | ||
expect($cookieStore.get('gonto123')).to.equal(JSON.stringify(value)); | ||
})); | ||
}); | ||
describe('angularStorage storeProvider.setStore("localStorage")', function () { | ||
var provider; | ||
beforeEach(function() { | ||
module('angular-storage.store', function(storeProvider) { | ||
provider = storeProvider; | ||
provider.setStore('localStorage'); | ||
}); | ||
}); | ||
it('should save items correctly in the localStorage', inject(function(store, $window) { | ||
var value = 55; | ||
store.set('gonto', value); | ||
expect(store.get('gonto')).to.equal(value); | ||
expect($window.localStorage.getItem('gonto')).to.exist; | ||
expect($window.localStorage.getItem('gonto')).to.equal(value.toString()); | ||
})); | ||
}); | ||
describe('angularStorage storeProvider.setStore("cookieStorage")', function () { | ||
var provider; | ||
var $cookieStore; | ||
beforeEach(function() { | ||
module('ngCookies', 'angular-storage.store', function(storeProvider) { | ||
provider = storeProvider; | ||
provider.setStore('cookieStorage'); | ||
}); | ||
}); | ||
beforeEach(inject(function( _$cookieStore_) { | ||
$cookieStore = _$cookieStore_; | ||
})); | ||
it('should save items correctly in the cookieStorage', inject(function(store) { | ||
var value = 66; | ||
store.set('gonto', value); | ||
expect(store.get('gonto')).to.equal(value); | ||
expect($cookieStore.get('gonto')).to.equal(JSON.stringify(value)); | ||
})); | ||
}); | ||
describe('angularStorage storeProvider.setStore()', function () { | ||
var provider; | ||
beforeEach(function() { | ||
module('angular-storage.store', function(storeProvider) { | ||
provider = storeProvider; | ||
provider.setStore(); | ||
}); | ||
}); | ||
it('should save items correctly in the localStorage', inject(function(store, $window) { | ||
var value = 77; | ||
store.set('gonto', value); | ||
expect(store.get('gonto')).to.equal(value); | ||
expect($window.localStorage.getItem('gonto')).to.exist; | ||
expect($window.localStorage.getItem('gonto')).to.equal(value.toString()); | ||
})); | ||
}); | ||
describe('angularStorage storeProvider.setStore(123)', function () { | ||
var provider; | ||
beforeEach(function() { | ||
module('angular-storage.store', function(storeProvider) { | ||
provider = storeProvider; | ||
provider.setStore(123); | ||
}); | ||
}); | ||
it('should save items correctly in the localStorage', inject(function(store, $window) { | ||
var value = 77; | ||
store.set('gonto', value); | ||
expect(store.get('gonto')).to.equal(value); | ||
expect($window.localStorage.getItem('gonto')).to.exist; | ||
expect($window.localStorage.getItem('gonto')).to.equal(value.toString()); | ||
})); | ||
}); | ||
describe('angularStorage storeProvider.setStore("abc")', function () { | ||
var provider; | ||
beforeEach(function() { | ||
module('angular-storage.store', function(storeProvider) { | ||
provider = storeProvider; | ||
provider.setStore('abc'); | ||
}); | ||
}); | ||
it('should throw an error when the store is not found', function() { | ||
expect(function() { inject(function(store){ store.get('a');}); } ).to.throw(); | ||
}); | ||
}); | ||
describe('angularStorage store: cookie fallback', function() { | ||
/* these tests ensure that the cookie fallback works correctly. | ||
* | ||
* note - to confirm that cookiestore was used we attempt to retrieve the value from the cookie | ||
since this bypasses our service, the result will not have been json parsed | ||
therefore we use JSON.stringify on the expected value, so comparing like for like | ||
* | ||
*/ | ||
var windowMock, $cookieStore; | ||
/* provide a mock for $window where localStorage is not defined */ | ||
beforeEach(module('ngCookies', 'angular-storage.store', function ($provide) { | ||
windowMock = { localStorage: undefined }; | ||
$provide.value('$window', windowMock); | ||
})); | ||
beforeEach(inject(function( _$cookieStore_) { | ||
$cookieStore = _$cookieStore_; | ||
})); | ||
it('should save items correctly in localStorage', inject(function(store) { | ||
var value = 1; | ||
store.set('gonto', value); | ||
expect(store.get('gonto')).to.equal(value); //this line asserts that value was saved by our service | ||
expect($cookieStore.get('gonto')).to.equal(JSON.stringify(value)); //this line asserts that cookie store was used | ||
})); | ||
it('should save null items correctly in localStorage', inject(function(store) { | ||
store.set('gonto', null); | ||
store.inMemoryCache = {}; | ||
expect(store.get('gonto')).to.equal(null); | ||
expect($cookieStore.get('gonto')).to.equal(JSON.stringify(null)); | ||
})); | ||
it('should save undefined items correctly in localStorage', inject(function(store) { | ||
store.set('gonto', undefined); | ||
store.inMemoryCache = {}; | ||
expect(store.get('gonto')).to.equal(undefined); | ||
expect($cookieStore.get('gonto')).to.equal(JSON.stringify(undefined)); | ||
})); | ||
it('should delete items correctly from localStorage', inject(function(store) { | ||
var value = 1; | ||
store.set('gonto', value); | ||
expect(store.get('gonto')).to.equal(value); | ||
store.remove('gonto'); | ||
expect(store.get('gonto')).to.not.exist; | ||
expect($cookieStore.get('gonto')).to.not.exist; | ||
})); | ||
it('should save objects correctly', inject(function(store) { | ||
var value = { | ||
gonto: 'hola' | ||
}; | ||
store.set('gonto', value); | ||
expect(store.get('gonto')).to.eql(value); | ||
})); | ||
it('should save objects correctly', inject(function(store) { | ||
var value = { | ||
gonto: 'hola' | ||
}; | ||
store.set('gonto', value); | ||
expect(store.get('gonto')).to.eql(value); | ||
expect($cookieStore.get('gonto')).to.equal(JSON.stringify(value)); | ||
})); | ||
it('should save objects correctly without cache', inject(function(store) { | ||
var value = { | ||
gonto: 'hola' | ||
}; | ||
store.set('gonto', value); | ||
store.inMemoryCache = {}; | ||
expect(store.get('gonto')).to.eql(value); | ||
expect(store.get('gonto')).not.to.equal(value); | ||
})); | ||
it('should save objects correctly without cache', inject(function(store) { | ||
var value = { | ||
gonto: 'hola' | ||
}; | ||
store.set('gonto', value); | ||
store.inMemoryCache = {}; | ||
expect(store.get('gonto')).to.eql(value); | ||
expect(store.get('gonto')).not.to.equal(value); | ||
expect($cookieStore.get('gonto')).to.eql(JSON.stringify(value)); | ||
})); | ||
}); | ||
describe('angularStorage new namespaced store', function() { | ||
beforeEach(function() { | ||
module('ngCookies', 'angular-storage.store'); | ||
}); | ||
var newStore = null; | ||
@@ -138,3 +387,52 @@ | ||
it('should should save items correctly when the delimiter is set', inject(function(store, $window) { | ||
var value = 111; | ||
var aStore = store.getNamespacedStore('aa', 'sessionStorage', '-'); | ||
aStore.set('wayne', value); | ||
expect(aStore.get('wayne')).to.equal(value); | ||
expect($window.sessionStorage.getItem('aa-wayne')).to.exist; | ||
expect($window.sessionStorage.getItem('aa-wayne')).to.equal(value.toString()); | ||
expect($window.sessionStorage.getItem('wayne')).to.not.exist; | ||
})); | ||
describe('with param storage', function () { | ||
var $cookieStore; | ||
beforeEach(inject(function( _$cookieStore_) { | ||
$cookieStore = _$cookieStore_; | ||
})); | ||
it('should should save items correctly when the storage is set to sessionStorage', inject(function(store, $window) { | ||
var value = 111; | ||
var sessionStore = store.getNamespacedStore('aa', 'sessionStorage'); | ||
sessionStore.set('wayne', value); | ||
expect(sessionStore.get('wayne')).to.equal(value); | ||
expect($window.sessionStorage.getItem('aa.wayne')).to.exist; | ||
expect($window.sessionStorage.getItem('aa.wayne')).to.equal(value.toString()); | ||
expect($window.sessionStorage.getItem('wayne')).to.not.exist; | ||
})); | ||
it('should should save items correctly when the storage is set to localStorage', inject(function(store, $window) { | ||
var value = 222; | ||
var localStore = store.getNamespacedStore('bb', 'localStorage'); | ||
localStore.set('wayne', value); | ||
expect(localStore.get('wayne')).to.equal(value); | ||
expect($window.localStorage.getItem('bb.wayne')).to.exist; | ||
expect($window.localStorage.getItem('bb.wayne')).to.equal(value.toString()); | ||
expect($window.localStorage.getItem('wayne')).to.not.exist; | ||
})); | ||
it('should should save items correctly when the storage is set to cookieStorage', inject(function(store) { | ||
var value = 222; | ||
var cookieStore = store.getNamespacedStore('cc', 'cookieStorage'); | ||
cookieStore.set('wayne', value); | ||
expect(cookieStore.get('wayne')).to.equal(value); | ||
expect($cookieStore.get('cc.wayne')).to.equal(JSON.stringify(value)); | ||
})); | ||
}); | ||
}); | ||
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
47429
27
1036
0
24