Commit 2b60b8459c753f005e0b90b8fbed85ad64fc4964
1 parent
682b0f3e
Exists in
master
and in
1 other branch
Add some unit tests
Showing
2 changed files
with
21 additions
and
2 deletions
Show diff stats
src/app/components/navbar/navbar.directive.js
src/app/components/navbar/navbar.directive.spec.js
| ... | ... | @@ -4,9 +4,13 @@ |
| 4 | 4 | describe('directive navbar', function() { |
| 5 | 5 | var vm; |
| 6 | 6 | var el; |
| 7 | + var AUTH_EVENTS; | |
| 8 | + var $state; | |
| 7 | 9 | |
| 8 | 10 | beforeEach(module('angular')); |
| 9 | - beforeEach(inject(function($compile, $rootScope, $httpBackend) { | |
| 11 | + beforeEach(inject(function($compile, $rootScope, $httpBackend, _AUTH_EVENTS_, _$state_) { | |
| 12 | + $state = _$state_; | |
| 13 | + AUTH_EVENTS = _AUTH_EVENTS_; | |
| 10 | 14 | $httpBackend.when('POST','/api/v1/login_from_cookie').respond({}); |
| 11 | 15 | |
| 12 | 16 | el = angular.element('<acme-navbar></acme-navbar>'); |
| ... | ... | @@ -25,5 +29,17 @@ |
| 25 | 29 | expect(vm.currentUser).toEqual(undefined); |
| 26 | 30 | }); |
| 27 | 31 | |
| 32 | + it('should reload current state after login', function() { | |
| 33 | + spyOn($state, 'go'); | |
| 34 | + el.isolateScope().$broadcast(AUTH_EVENTS.loginSuccess, {}); | |
| 35 | + expect($state.go).toHaveBeenCalled(); | |
| 36 | + }); | |
| 37 | + | |
| 38 | + it('should open login when not logged in', function() { | |
| 39 | + spyOn(vm, 'openLogin'); | |
| 40 | + vm.activate(); | |
| 41 | + expect(vm.openLogin).toHaveBeenCalled(); | |
| 42 | + }); | |
| 43 | + | |
| 28 | 44 | }); |
| 29 | 45 | })(); | ... | ... |