diff options
author | brantje <brantje@gmail.com> | 2016-10-17 20:25:47 +0300 |
---|---|---|
committer | brantje <brantje@gmail.com> | 2016-10-17 20:25:47 +0300 |
commit | 0d0f5bc7a04695e28e2e04462dfeb0b5484685d8 (patch) | |
tree | d598583750db847d7cfdb1e4ec5fb042ec9c65cd /tests | |
parent | e84da75f05d4b8e7d1da1d7bb40b5a15de1c5e71 (diff) |
Start with a few credentialCtrl tests
Diffstat (limited to 'tests')
-rw-r--r-- | tests/unit/js/app/controllers/credentialTest.js | 45 | ||||
-rw-r--r-- | tests/unit/js/app/controllers/menuTest.js | 1 | ||||
-rw-r--r-- | tests/unit/js/mocks/CredentialService.js | 22 |
3 files changed, 67 insertions, 1 deletions
diff --git a/tests/unit/js/app/controllers/credentialTest.js b/tests/unit/js/app/controllers/credentialTest.js new file mode 100644 index 00000000..04e71a6b --- /dev/null +++ b/tests/unit/js/app/controllers/credentialTest.js @@ -0,0 +1,45 @@ +describe('CredentialCtrl', function() { + var ctrl, scope, rootScope; + beforeEach(module('passmanApp', function ($provide) { + $provide.value('$window', { + localStorage: localStorageMock() + }); + })); + beforeEach(module('LocalStorageModule')); + beforeEach(module('mock.credentialsService')); + + beforeEach(inject(function($controller, $rootScope, _CredentialService_, SettingsService) { // inject mocked service + scope = $rootScope.$new(); + rootScope = $rootScope; + ctrl = $controller('CredentialCtrl', { + $scope: scope, + CredentialService: _CredentialService_, + SettingService: SettingsService + }); + })); + + describe('Test events', function() { + it('[event] selected_tags_updated', function() { + rootScope.$broadcast('selected_tags_updated', [{text: 'hello'}]); + expect(scope.selectedtags).toEqual(['hello']); + }); + + it('[event] set_delete_time', function() { + rootScope.$broadcast('set_delete_time', 1337); + expect(scope.delete_time).toEqual(1337); + }); + + it('[event] logout', function() { + rootScope.$broadcast('logout'); + expect(scope.active_vault).toEqual(null); + expect(scope.credentials).toEqual([]); + }); + + it('[event] close selected credential', function() { + var _spy = spyOn(rootScope, '$emit'); + scope.closeSelected(); + expect(_spy).toHaveBeenCalled(); + expect(scope.selectedCredential).toEqual(false); + }); + }); +});
\ No newline at end of file diff --git a/tests/unit/js/app/controllers/menuTest.js b/tests/unit/js/app/controllers/menuTest.js index 9de8c6a7..3a092230 100644 --- a/tests/unit/js/app/controllers/menuTest.js +++ b/tests/unit/js/app/controllers/menuTest.js @@ -3,7 +3,6 @@ describe('MenuCtrl', function() { $provide.value('$window', { localStorage: localStorageMock() }); - })); var $controller; diff --git a/tests/unit/js/mocks/CredentialService.js b/tests/unit/js/mocks/CredentialService.js new file mode 100644 index 00000000..1fac8d26 --- /dev/null +++ b/tests/unit/js/mocks/CredentialService.js @@ -0,0 +1,22 @@ +angular.module('mock.credentialsService', []). +service('CredentialService', function($q) { + var credentialService = {}; + + credentialService.getCredential = function() { + var _credential = { + id: 8888, + label: "test user" + }; + return $q.when(_credential); + }; + + credentialService.getRevisions = function() { + var mockRevision = [{ + id: 1234, + created: "" + }]; + return $q.when(mockRevision); + }; + + return credentialService; +});
\ No newline at end of file |