navbar.directive.spec.js
1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
(function() {
'use strict';
describe('directive navbar', function() {
var vm;
var el;
var AUTH_EVENTS;
var $state;
beforeEach(module('angular'));
beforeEach(inject(function($compile, $rootScope, $httpBackend, _AUTH_EVENTS_, _$state_) {
$state = _$state_;
AUTH_EVENTS = _AUTH_EVENTS_;
$httpBackend.when('POST','/api/v1/login_from_cookie').respond({});
el = angular.element('<acme-navbar></acme-navbar>');
$compile(el)($rootScope.$new());
$rootScope.$digest();
vm = el.isolateScope().vm;
}));
it('should be compiled', function() {
expect(el.html()).not.toEqual(null);
});
it('should have isolate scope object with instanciate members', function() {
expect(vm).toEqual(jasmine.any(Object));
expect(vm.currentUser).toEqual(undefined);
});
it('should reload current state after login', function() {
spyOn($state, 'go');
el.isolateScope().$broadcast(AUTH_EVENTS.loginSuccess, {});
expect($state.go).toHaveBeenCalled();
});
it('should open login when not logged in', function() {
spyOn(vm, 'openLogin');
vm.activate();
expect(vm.openLogin).toHaveBeenCalled();
});
});
})();