X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=sdnr%2Fwireless-transport%2Fcode-Carbon-SR1%2Fapps%2Fdlux%2Fdlux-web%2Fsrc%2Fcommon%2Flogin%2Flogin.spec.js;fp=sdnr%2Fwireless-transport%2Fcode-Carbon-SR1%2Fapps%2Fdlux%2Fdlux-web%2Fsrc%2Fcommon%2Flogin%2Flogin.spec.js;h=47fcf35b3b630852b018b9889cfef9d74d37fd98;hb=27fb2d06608fbb070ae2c15a5580a4f5b2423d15;hp=0000000000000000000000000000000000000000;hpb=60315525ab5e7c12a9f47c409092e8dba6ad656d;p=ccsdk%2Fapps.git diff --git a/sdnr/wireless-transport/code-Carbon-SR1/apps/dlux/dlux-web/src/common/login/login.spec.js b/sdnr/wireless-transport/code-Carbon-SR1/apps/dlux/dlux-web/src/common/login/login.spec.js new file mode 100644 index 00000000..47fcf35b --- /dev/null +++ b/sdnr/wireless-transport/code-Carbon-SR1/apps/dlux/dlux-web/src/common/login/login.spec.js @@ -0,0 +1,61 @@ +define(['common/login/login.controller', 'angular-ui-router', 'common/layout/layout.module'], function() { + describe('Login Module', function() { + var scope, state, controller, location, AuthMock; + var url = '/test'; + + beforeEach(module('ui.router')); + beforeEach(module('app.common.layout')); + beforeEach(module('app.common.login', function($provide) { + AuthMock = { + isAuthed: function() {}, + login: function() {} + }; + $provide.value('Auth', AuthMock); + })); + + beforeEach(inject( function($rootScope, $controller, $state, $location) { + scope = $rootScope.$new(); + controller = $controller; + state = $state; + location = $location; + })); + + it('Should load the login state', function() { + var stateName = 'login'; + + controller('LoginCtrl', {$scope: scope, $state: state}); + expect(state.href(stateName, {})).toBe('#/login'); + }); + + it('Should redirect any url to login if not logged', function() { + var stateName = 'login'; + spyOn(AuthMock,'isAuthed').andReturn(false); + location.url(url); + controller('LoginCtrl', {$scope: scope, $state: state}); + state.go('main'); + + expect(AuthMock.isAuthed).toHaveBeenCalled(); + expect(state.is("login")); + expect(location.url()).toEqual('/login'); + }); + + it('Should not redirect if logged', function() { + spyOn(AuthMock,'isAuthed').andReturn(true); + location.url(url); + controller('LoginCtrl', {$scope: scope, $state: state}); + state.go('main'); + + expect(AuthMock.isAuthed).toHaveBeenCalled(); + expect(state.is("main")); + expect(location.url()).toEqual(url); + }); + + it('Should call the Auth module', function() { + spyOn(AuthMock,'login'); + controller('LoginCtrl', {$scope: scope, $state: state}); + + scope.sendLogin(); + expect(AuthMock.login).toHaveBeenCalled(); + }); + }); +});