47fcf35b3b630852b018b9889cfef9d74d37fd98
[ccsdk/apps.git] / sdnr / wireless-transport / code-Carbon-SR1 / apps / dlux / dlux-web / src / common / login / login.spec.js
1 define(['common/login/login.controller', 'angular-ui-router', 'common/layout/layout.module'], function() {
2   describe('Login Module', function() {
3     var scope, state, controller, location, AuthMock;
4     var url = '/test';
5
6     beforeEach(module('ui.router'));
7     beforeEach(module('app.common.layout'));
8     beforeEach(module('app.common.login', function($provide) {
9       AuthMock = {
10         isAuthed: function() {},
11         login: function() {}
12       };
13       $provide.value('Auth', AuthMock);
14     }));
15
16     beforeEach(inject( function($rootScope, $controller, $state, $location) {
17       scope = $rootScope.$new();
18       controller = $controller;
19       state = $state;
20       location = $location;
21     }));
22
23     it('Should load the login state', function() {
24       var stateName = 'login';
25
26       controller('LoginCtrl', {$scope: scope, $state: state});
27       expect(state.href(stateName, {})).toBe('#/login');
28     });
29
30     it('Should redirect any url to login if not logged', function() {
31       var stateName = 'login';
32       spyOn(AuthMock,'isAuthed').andReturn(false);
33       location.url(url);
34       controller('LoginCtrl', {$scope: scope, $state: state});
35       state.go('main');
36
37       expect(AuthMock.isAuthed).toHaveBeenCalled();
38       expect(state.is("login"));
39       expect(location.url()).toEqual('/login');
40     });
41
42     it('Should not redirect if logged', function() {
43       spyOn(AuthMock,'isAuthed').andReturn(true);
44       location.url(url);
45       controller('LoginCtrl', {$scope: scope, $state: state});
46       state.go('main');
47
48       expect(AuthMock.isAuthed).toHaveBeenCalled();
49       expect(state.is("main"));
50       expect(location.url()).toEqual(url);
51     });
52
53     it('Should call the Auth module', function() {
54       spyOn(AuthMock,'login');
55       controller('LoginCtrl', {$scope: scope, $state: state});
56
57       scope.sendLogin();
58       expect(AuthMock.login).toHaveBeenCalled();
59     });
60   });
61 });