Commit 2b60b8459c753f005e0b90b8fbed85ad64fc4964

Authored by Victor Costa
1 parent 682b0f3e

Add some unit tests

src/app/components/navbar/navbar.directive.js
... ... @@ -48,7 +48,10 @@
48 48 vm.currentUser = Session.getCurrentUser();
49 49 });
50 50  
51   - if(!vm.currentUser) vm.openLogin();
  51 + vm.activate = function() {
  52 + if(!vm.currentUser) vm.openLogin();
  53 + }
  54 + vm.activate();
52 55 }
53 56 }
54 57  
... ...
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 })();
... ...