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;
6 beforeEach(module('ui.router'));
7 beforeEach(module('app.common.layout'));
8 beforeEach(module('app.common.login', function($provide) {
10 isAuthed: function() {},
13 $provide.value('Auth', AuthMock);
16 beforeEach(inject( function($rootScope, $controller, $state, $location) {
17 scope = $rootScope.$new();
18 controller = $controller;
23 it('Should load the login state', function() {
24 var stateName = 'login';
26 controller('LoginCtrl', {$scope: scope, $state: state});
27 expect(state.href(stateName, {})).toBe('#/login');
30 it('Should redirect any url to login if not logged', function() {
31 var stateName = 'login';
32 spyOn(AuthMock,'isAuthed').andReturn(false);
34 controller('LoginCtrl', {$scope: scope, $state: state});
37 expect(AuthMock.isAuthed).toHaveBeenCalled();
38 expect(state.is("login"));
39 expect(location.url()).toEqual('/login');
42 it('Should not redirect if logged', function() {
43 spyOn(AuthMock,'isAuthed').andReturn(true);
45 controller('LoginCtrl', {$scope: scope, $state: state});
48 expect(AuthMock.isAuthed).toHaveBeenCalled();
49 expect(state.is("main"));
50 expect(location.url()).toEqual(url);
53 it('Should call the Auth module', function() {
54 spyOn(AuthMock,'login');
55 controller('LoginCtrl', {$scope: scope, $state: state});
58 expect(AuthMock.login).toHaveBeenCalled();