1
0
mirror of https://github.com/moparisthebest/mail synced 2024-11-26 10:52:17 -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 // check if account needs to be selected
if (!info.emailAddress) { if (!info.emailAddress) {
goTo('/add-account'); $scope.goTo('/add-account');
return; return;
} }
@ -46,7 +46,7 @@ var LoginCtrl = function($scope, $timeout, $location, updateHandler, account, au
passphrase: undefined passphrase: undefined
}, function(err) { }, function(err) {
if (err) { if (err) {
goTo('/login-existing'); $scope.goTo('/login-existing');
return; return;
} }
@ -55,7 +55,7 @@ var LoginCtrl = function($scope, $timeout, $location, updateHandler, account, au
return dialog.error(err); return dialog.error(err);
} }
goTo('/desktop'); $scope.goTo('/desktop');
}); });
}); });
} else if (availableKeys && availableKeys.publicKey && !availableKeys.privateKey) { } else if (availableKeys && availableKeys.publicKey && !availableKeys.privateKey) {
@ -71,24 +71,24 @@ var LoginCtrl = function($scope, $timeout, $location, updateHandler, account, au
if (privateKeySynced) { if (privateKeySynced) {
// private key is synced, proceed to download // private key is synced, proceed to download
goTo('/login-privatekey-download'); $scope.goTo('/login-privatekey-download');
return; return;
} }
// no private key, import key file // no private key, import key file
goTo('/login-new-device'); $scope.goTo('/login-new-device');
}); });
} else { } else {
// no public key available, start onboarding process // no public key available, start onboarding process
goTo('/login-initial'); $scope.goTo('/login-initial');
} }
} }
function goTo(location) { $scope.goTo = function(location) {
return $timeout(function() { return $timeout(function() {
$location.path(location); $location.path(location);
}); });
} };
}; };
module.exports = LoginCtrl; module.exports = LoginCtrl;

View File

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

View File

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

View File

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