angular.module('dashboard')
.controller('LoginCtrl', ['$scope', 'UserService', '$rootScope', '$state', 'PageTitle', '$translate',
function ($scope, UserService, $rootScope, $state, PageTitle, $translate) {
$translate('TITLE_LOGIN').then(function (text) {
PageTitle.setTitle(text);
});
$scope.credentials = {};
$scope.error = false;
$scope.loggingIn = false;
$scope.login = function () {
$scope.loggingIn = true;
UserService.login($scope.credentials)
.then(function (result) {
if (result) {
$scope.error = false;
$state.go('main.start');
} else {
$scope.loggingIn = false;
$scope.error = true;
}
}, function () {
$scope.loggingIn = false;
$scope.error = true;
});
};
}]);
describe('Controller: LoginCtrl', function () {
// load the controller's module
beforeEach(module('dashboard'));
var LoginCtrl,
scope,
userSvc,
conf,
base64,
localStorage,
httpBackend;
// Initialize the controller and a mock scope
beforeEach(inject(function ($controller, $rootScope, $httpBackend, UserService, configuration, Base64, localStorageService) {
scope = $rootScope.$new();
LoginCtrl = $controller('LoginCtrl', {
$scope: scope
});
httpBackend = $httpBackend;
userSvc = UserService;
conf = configuration;
base64 = Base64;
localStorage = localStorageService;
sessionStorage.clear();
}));
it('should login', function () {
var token = base64.encode('1:1');
httpBackend.expectGET('scripts/i18n/nl.json').respond(200);
httpBackend.expectGET('views/login.html').respond(200);
httpBackend.whenPOST(conf.backend + 'users/login').respond({'access_token': 1});
httpBackend.expectGET('views/main.html').respond(200);
httpBackend.expectGET('views/start.html').respond(200);
scope.login({'email': 'tester'});
httpBackend.flush();
expect(sessionStorage.accessToken).toEqual(token);
expect(userSvc.profile()).toBeObject();
});
});
Error: [$rootScope:infdig] 10 $digest() iterations reached. Aborting!
Watchers fired in the last 5 iterations: []
http://errors.angularjs.org/1.3.4/$rootScope/infdig?p0=10&p1=%5B%5D
at /srv/http/bower_components/angular/angular.js:14170
at /srv/http/bower_components/angular-mocks/angular-mocks.js:1523
at /srv/http/test/unit/controllers/login.js:38