1
0
mirror of https://github.com/moparisthebest/mail synced 2024-11-22 08:52:15 -05:00

Fix unit tests

This commit is contained in:
Tankred Hase 2014-11-26 19:51:15 +01:00
parent b3b947f6e5
commit 32d3ea1801
4 changed files with 21 additions and 18 deletions

View File

@ -19,7 +19,7 @@ var LoginCtrl = function($scope, $timeout, $location, updateHandler, account, au
// check if account needs to be selected
if (!info.emailAddress) {
goTo('/add-account');
$scope.goTo('/add-account');
return;
}
@ -46,7 +46,7 @@ var LoginCtrl = function($scope, $timeout, $location, updateHandler, account, au
passphrase: undefined
}, function(err) {
if (err) {
goTo('/login-existing');
$scope.goTo('/login-existing');
return;
}
@ -55,7 +55,7 @@ var LoginCtrl = function($scope, $timeout, $location, updateHandler, account, au
return dialog.error(err);
}
goTo('/desktop');
$scope.goTo('/desktop');
});
});
} else if (availableKeys && availableKeys.publicKey && !availableKeys.privateKey) {
@ -71,24 +71,24 @@ var LoginCtrl = function($scope, $timeout, $location, updateHandler, account, au
if (privateKeySynced) {
// private key is synced, proceed to download
goTo('/login-privatekey-download');
$scope.goTo('/login-privatekey-download');
return;
}
// no private key, import key file
goTo('/login-new-device');
$scope.goTo('/login-new-device');
});
} else {
// no public key available, start onboarding process
goTo('/login-initial');
$scope.goTo('/login-initial');
}
}
function goTo(location) {
$scope.goTo = function(location) {
return $timeout(function() {
$location.path(location);
});
}
};
};
module.exports = LoginCtrl;

View File

@ -27,7 +27,7 @@ describe('Dialog Controller unit test', function() {
it('should work', function(done) {
scope.callback = function(confirmed) {
expect(confirmed).to.be.true;
expect(scope.open).to.be.false;
expect(scope.state.dialog.open).to.be.false;
done();
};
scope.confirm(true);
@ -38,7 +38,7 @@ describe('Dialog Controller unit test', function() {
it('should work', function(done) {
scope.callback = function(confirmed) {
expect(confirmed).to.be.false;
expect(scope.open).to.be.false;
expect(scope.state.dialog.open).to.be.false;
done();
};
scope.confirm(false);

View File

@ -31,6 +31,7 @@ describe('Navigation Controller unit test', function() {
notificationStub = sinon.createStubInstance(Notif);
accountMock = sinon.createStubInstance(Account);
accountMock.list.returns([account]);
accountMock.isLoggedIn.returns(true);
angular.module('navigationtest', ['woServices', 'woEmail', 'woUtil']);
angular.mock.module('navigationtest');

View File

@ -10,7 +10,7 @@ var LoginCtrl = require('../../../../src/js/controller/login/login'),
describe('Login Controller unit test', function() {
var scope, location, ctrl,
emailMock, keychainMock, authMock, accountMock, dialogMock, updateHandlerMock, pathStub,
emailMock, keychainMock, authMock, accountMock, dialogMock, updateHandlerMock, goToStub,
emailAddress = 'fred@foo.com';
beforeEach(function() {
@ -24,7 +24,6 @@ describe('Login Controller unit test', function() {
location = {
path: function() {}
};
pathStub = sinon.stub(location, 'path');
authMock.emailAddress = emailAddress;
});
@ -36,6 +35,9 @@ describe('Login Controller unit test', function() {
scope = $rootScope.$new();
scope.state = {};
scope.form = {};
scope.goTo = function() {};
goToStub = sinon.stub(scope, 'goTo');
ctrl = $controller(LoginCtrl, {
$scope: scope,
$location: location,
@ -66,7 +68,7 @@ describe('Login Controller unit test', function() {
createController();
expect(pathStub.withArgs('/add-account').calledOnce).to.be.true;
expect(goToStub.withArgs('/add-account').calledOnce).to.be.true;
});
it('should fail for auth.init', function() {
@ -93,7 +95,7 @@ describe('Login Controller unit test', function() {
createController();
expect(pathStub.withArgs('/login-existing').calledOnce).to.be.true;
expect(goToStub.withArgs('/login-existing').calledOnce).to.be.true;
});
it('should fail for auth.storeCredentials', function() {
@ -125,7 +127,7 @@ describe('Login Controller unit test', function() {
createController();
expect(pathStub.withArgs('/desktop').calledOnce).to.be.true;
expect(goToStub.withArgs('/desktop').calledOnce).to.be.true;
});
it('should fail for keychain.requestPrivateKeyDownload', function() {
@ -153,7 +155,7 @@ describe('Login Controller unit test', function() {
createController();
expect(pathStub.withArgs('/login-privatekey-download').calledOnce).to.be.true;
expect(goToStub.withArgs('/login-privatekey-download').calledOnce).to.be.true;
});
it('should redirect to /login-new-device', function() {
@ -167,7 +169,7 @@ describe('Login Controller unit test', function() {
createController();
expect(pathStub.withArgs('/login-new-device').calledOnce).to.be.true;
expect(goToStub.withArgs('/login-new-device').calledOnce).to.be.true;
});
it('should redirect to /login-initial', function() {
@ -178,7 +180,7 @@ describe('Login Controller unit test', function() {
createController();
expect(pathStub.withArgs('/login-initial').calledOnce).to.be.true;
expect(goToStub.withArgs('/login-initial').calledOnce).to.be.true;
});
});