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

Fix last unit tests

This commit is contained in:
Tankred Hase 2014-11-26 13:43:10 +01:00
parent 03b2e10bc3
commit 2b6da522c6
6 changed files with 68 additions and 83 deletions

View File

@ -196,8 +196,8 @@ module.exports = function(grunt) {
'test/unit/controller/app/read-ctrl-test.js',
'test/unit/controller/app/navigation-ctrl-test.js',
'test/unit/controller/app/mail-list-ctrl-test.js',
/*'test/unit/write-ctrl-test.js',
'test/unit/action-bar-ctrl-test.js',*/
'test/unit/controller/app/write-ctrl-test.js',
'test/unit/controller/app/action-bar-ctrl-test.js',
]
},
options: browserifyOpt

View File

@ -1,13 +1,12 @@
'use strict';
var axe = require('axe-logger'),
util = require('crypto-lib').util;
var util = require('crypto-lib').util;
//
// Controller
//
var WriteCtrl = function($scope, $filter, $q, appConfig, auth, keychain, pgp, email, outbox, dialog) {
var WriteCtrl = function($scope, $filter, $q, appConfig, auth, keychain, pgp, email, outbox, dialog, axe) {
var str = appConfig.string;

View File

@ -50,6 +50,8 @@ if (!Function.prototype.bind) {
// Test setup
//
chai.config.includeStack = true;
// set worker path for tests
require('../src/js/app-config').config.workerPath = '../lib';

View File

@ -1,21 +1,21 @@
'use strict';
var mocks = angular.mock,
EmailDAO = require('../../src/js/dao/email-dao'),
appController = require('../../src/js/app-controller'),
ActionBarCtrl = require('../../src/js/controller/action-bar');
var Email = require('../../../../src/js/email/email'),
Dialog = require('../../../../src/js/util/dialog'),
StatusDisplay = require('../../../../src/js/util/status-display'),
ActionBarCtrl = require('../../../../src/js/controller/app/action-bar');
describe('Action Bar Controller unit test', function() {
var scope, actionBarCtrl, emailDaoMock, origEmailDao;
var scope, actionBarCtrl, emailMock, dialogMock, statusDisplayMock;
beforeEach(function() {
origEmailDao = appController._emailDao;
emailDaoMock = sinon.createStubInstance(EmailDAO);
appController._emailDao = emailDaoMock;
emailMock = sinon.createStubInstance(Email);
dialogMock = sinon.createStubInstance(Dialog);
statusDisplayMock = sinon.createStubInstance(StatusDisplay);
angular.module('actionbartest', []);
mocks.module('actionbartest');
mocks.inject(function($rootScope, $controller) {
angular.mock.module('actionbartest');
angular.mock.inject(function($rootScope, $controller) {
scope = $rootScope.$new();
scope.state = {
mailList: {
@ -40,15 +40,15 @@ describe('Action Bar Controller unit test', function() {
};
actionBarCtrl = $controller(ActionBarCtrl, {
$scope: scope
$scope: scope,
email: emailMock,
dialog: dialogMock,
statusDisplay: statusDisplayMock
});
});
});
afterEach(function() {
// restore the module
appController._emailDao = origEmailDao;
});
afterEach(function() {});
describe('deleteMessage', function() {
it('should not delete without a selected mail', function() {
@ -56,11 +56,11 @@ describe('Action Bar Controller unit test', function() {
});
it('should delete the selected mail', function() {
emailDaoMock.deleteMessage.yields();
emailMock.deleteMessage.yields();
scope.deleteMessage({});
expect(emailDaoMock.deleteMessage.calledOnce).to.be.true;
expect(emailMock.deleteMessage.calledOnce).to.be.true;
expect(scope.state.read.open).to.be.false;
});
});
@ -88,11 +88,11 @@ describe('Action Bar Controller unit test', function() {
});
it('should move the selected mail', function() {
emailDaoMock.moveMessage.yields();
emailMock.moveMessage.yields();
scope.moveMessage({}, {});
expect(emailDaoMock.moveMessage.calledOnce).to.be.true;
expect(emailMock.moveMessage.calledOnce).to.be.true;
expect(scope.state.read.open).to.be.false;
});
});
@ -120,11 +120,11 @@ describe('Action Bar Controller unit test', function() {
});
it('should move the selected mail', function() {
emailDaoMock.setFlags.yields();
emailMock.setFlags.yields();
scope.markMessage({}, true);
expect(emailDaoMock.setFlags.calledOnce).to.be.true;
expect(emailMock.setFlags.calledOnce).to.be.true;
expect(scope.state.read.open).to.be.false;
});
});

View File

@ -1,15 +1,12 @@
'use strict';
var mocks = angular.mock,
MailListCtrl = require('../../../../src/js/controller/app/mail-list'),
var MailListCtrl = require('../../../../src/js/controller/app/mail-list'),
EmailDAO = require('../../../../src/js/email/email'),
KeychainDAO = require('../../../../src/js/service/keychain'),
StatusDisplay = require('../../../../src/js/util/status-display'),
Dialog = require('../../../../src/js/util/dialog'),
Search = require('../../../../src/js/email/search');
chai.config.includeStack = true;
describe('Mail List controller unit test', function() {
var scope, ctrl, statusDisplayMock, notificationMock, emailMock, keychainMock, dialogMock, searchMock,
emailAddress, emails,
@ -56,8 +53,8 @@ describe('Mail List controller unit test', function() {
searchMock = sinon.createStubInstance(Search);
angular.module('maillisttest', ['woEmail', 'woServices', 'woUtil']);
mocks.module('maillisttest');
mocks.inject(function($rootScope, $controller) {
angular.mock.module('maillisttest');
angular.mock.inject(function($rootScope, $controller) {
scope = $rootScope.$new();
scope.state = {
read: {

View File

@ -1,57 +1,50 @@
'use strict';
var mocks = angular.mock,
WriteCtrl = require('../../src/js/controller/write'),
EmailDAO = require('../../src/js/dao/email-dao'),
OutboxBO = require('../../src/js/bo/outbox'),
KeychainDAO = require('../../src/js/dao/keychain-dao'),
appController = require('../../src/js/app-controller');
var WriteCtrl = require('../../../../src/js/controller/app/write'),
Email = require('../../../../src/js/email/email'),
Outbox = require('../../../../src/js/email/outbox'),
Keychain = require('../../../../src/js/service/keychain'),
Auth = require('../../../../src/js/service/auth'),
PGP = require('../../../../src/js/crypto/pgp'),
Dialog = require('../../../../src/js/util/dialog');
describe('Write controller unit test', function() {
var ctrl, scope,
origEmailDao, origOutbox, origKeychain,
emailDaoMock, keychainMock, outboxMock, emailAddress, realname;
authMock, pgpMock, dialogMock, emailMock, keychainMock, outboxMock,
emailAddress, realname;
beforeEach(function() {
// the app controller is a singleton, we need to remember the
// outbox and email dao to restore it after the tests
origEmailDao = appController._emailDao;
origOutbox = appController._outboxBo;
origKeychain = appController._keychain;
outboxMock = sinon.createStubInstance(OutboxBO);
appController._outboxBo = outboxMock;
emailDaoMock = sinon.createStubInstance(EmailDAO);
appController._emailDao = emailDaoMock;
authMock = sinon.createStubInstance(Auth);
pgpMock = sinon.createStubInstance(PGP);
dialogMock = sinon.createStubInstance(Dialog);
outboxMock = sinon.createStubInstance(Outbox);
emailMock = sinon.createStubInstance(Email);
keychainMock = sinon.createStubInstance(Keychain);
emailAddress = 'fred@foo.com';
realname = 'Fred Foo';
emailDaoMock._account = {
emailAddress: emailAddress,
realname: realname
};
authMock.emailAddress = emailAddress;
authMock.realname = realname;
keychainMock = sinon.createStubInstance(KeychainDAO);
appController._keychain = keychainMock;
angular.module('writetest', []);
mocks.module('writetest');
mocks.inject(function($rootScope, $controller) {
angular.module('writetest', ['woEmail', 'woServices', 'woUtil']);
angular.mock.module('writetest');
angular.mock.inject(function($rootScope, $controller) {
scope = $rootScope.$new();
scope.state = {};
ctrl = $controller(WriteCtrl, {
$scope: scope
$scope: scope,
auth: authMock,
keychain: keychainMock,
pgp: pgpMock,
email: emailMock,
outbox: outboxMock,
dialog: dialogMock
});
});
});
afterEach(function() {
// restore the app controller
appController._emailDao = origEmailDao;
appController._outboxBo = origOutbox;
appController._keychain = origKeychain;
});
afterEach(function() {});
describe('scope variables', function() {
it('should be set correctly', function() {
@ -187,7 +180,7 @@ describe('Write controller unit test', function() {
expect(keychainMock.getReceiverPublicKey.called).to.be.false;
});
it('should not work for error in keychain', function(done) {
it('should not work for error in keychain', function() {
var recipient = {
address: 'asds@example.com'
};
@ -198,15 +191,13 @@ describe('Write controller unit test', function() {
errMsg: '404 not found yadda yadda'
});
scope.onError = function() {
expect(recipient.key).to.be.undefined;
expect(recipient.secure).to.be.false;
expect(scope.checkSendStatus.callCount).to.equal(1);
expect(keychainMock.refreshKeyForUserId.calledOnce).to.be.true;
done();
};
scope.verify(recipient);
expect(dialogMock.error.calledOnce).to.be.true;
expect(recipient.key).to.be.undefined;
expect(recipient.secure).to.be.false;
expect(scope.checkSendStatus.callCount).to.equal(1);
expect(keychainMock.refreshKeyForUserId.calledOnce).to.be.true;
});
it('should work for main userId', function(done) {
@ -337,6 +328,7 @@ describe('Write controller unit test', function() {
address: emailAddress,
name: realname
}]);
expect(mail.to).to.deep.equal(scope.to);
expect(mail.cc).to.deep.equal(scope.cc);
expect(mail.bcc).to.deep.equal(scope.bcc);
@ -345,19 +337,14 @@ describe('Write controller unit test', function() {
expect(mail.attachments).to.be.empty;
expect(mail.sentDate).to.exist;
return true;
})).yields();
emailDaoMock.setFlags.yields();
scope.onError = function(err) {
expect(err).to.not.exist;
};
emailMock.setFlags.yields();
scope.sendToOutbox();
expect(outboxMock.put.calledOnce).to.be.true;
expect(emailDaoMock.setFlags.calledOnce).to.be.true;
expect(emailMock.setFlags.calledOnce).to.be.true;
expect(scope.state.lightbox).to.be.undefined;
expect(scope.replyTo.answered).to.be.true;
});