diff options
author | brantje <brantje@gmail.com> | 2016-10-17 12:28:48 +0300 |
---|---|---|
committer | brantje <brantje@gmail.com> | 2016-10-17 19:43:33 +0300 |
commit | e84da75f05d4b8e7d1da1d7bb40b5a15de1c5e71 (patch) | |
tree | fbde6074ea4d509ceee9aef050da4eb8df891059 /tests | |
parent | 02ef0187efd8fe7d37e0a49f33cd1a98c72cd43d (diff) |
Add required files for karma
Diffstat (limited to 'tests')
-rw-r--r-- | tests/unit/js/app/controllers/menuTest.js | 52 | ||||
-rw-r--r-- | tests/unit/js/mocks/global.js | 1 | ||||
-rw-r--r-- | tests/unit/js/mocks/localStorageMock.js | 42 |
3 files changed, 95 insertions, 0 deletions
diff --git a/tests/unit/js/app/controllers/menuTest.js b/tests/unit/js/app/controllers/menuTest.js new file mode 100644 index 00000000..9de8c6a7 --- /dev/null +++ b/tests/unit/js/app/controllers/menuTest.js @@ -0,0 +1,52 @@ +describe('MenuCtrl', function() { + beforeEach(module('passmanApp', function ($provide) { + $provide.value('$window', { + localStorage: localStorageMock() + }); + + })); + + var $controller; + var $scope; + beforeEach(inject(function(_$controller_){ + // The injector unwraps the underscores (_) from around the parameter names when matching + $controller = _$controller_; + })); + beforeEach(inject(function($rootScope) { + $scope = $rootScope.$new(); + })); + + + describe('$scope.selectedTags', function() { + it('should add a tag to selected tags', function() { + var controller = $controller('MenuCtrl', { $scope: $scope }); + $scope.tagClicked({text: 'hello'}); + expect($scope.selectedTags).toEqual([{text: 'hello'}]); + }); + }); + + describe('$scope.toggleDeleteTime', function() { + it('should toggle delete time', function() { + var controller = $controller('MenuCtrl', { $scope: $scope }); + $scope.delete_time = 0; + $scope.toggleDeleteTime(); + expect($scope.delete_time).toEqual(1); + $scope.toggleDeleteTime(); + expect($scope.delete_time).toEqual(0); + }); + }); + + describe('$scope.getTags()', function() { + var scope, ctrl, service; + beforeEach(inject(function(TagService) { + console.log('*** IN INJECT!!***: ', TagService); + service = TagService; + })); + + it('should return an empty array', function() { + var controller = $controller('MenuCtrl', { $scope: $scope }); + expect($scope.getTags()).toEqual([]); + + }); + }); +});
\ No newline at end of file diff --git a/tests/unit/js/mocks/global.js b/tests/unit/js/mocks/global.js new file mode 100644 index 00000000..328e7547 --- /dev/null +++ b/tests/unit/js/mocks/global.js @@ -0,0 +1 @@ +var oc_requesttoken = null;
\ No newline at end of file diff --git a/tests/unit/js/mocks/localStorageMock.js b/tests/unit/js/mocks/localStorageMock.js new file mode 100644 index 00000000..ea449f33 --- /dev/null +++ b/tests/unit/js/mocks/localStorageMock.js @@ -0,0 +1,42 @@ +'use strict'; +//Mock localStorage +function localStorageMock() { + var storage = {}; + Object.defineProperties(storage, { + setItem: { + value: function(key, value) { + storage[key] = value || ''; + }, + enumerable: false, + writable: true + }, + getItem: { + value: function(key) { + return storage[key] ? storage[key] : null; + }, + enumerable: false, + writable: true + }, + removeItem: { + value: function(key) { + delete storage[key]; + }, + enumerable: false, + writable: true + }, + length: { + get: function() { + return Object.keys(storage).length; + }, + enumerable: false + }, + key: { + value: function(i) { + var aKeys = Object.keys(storage); + return aKeys[i] || null; + }, + enumerable: false + } + }); + return storage; +}
\ No newline at end of file |