2014-11-05 08:26:09 -05:00
|
|
|
'use strict';
|
|
|
|
|
2014-11-26 07:43:10 -05:00
|
|
|
var Email = require('../../../../src/js/email/email'),
|
|
|
|
Dialog = require('../../../../src/js/util/dialog'),
|
2014-12-04 10:24:42 -05:00
|
|
|
Status = require('../../../../src/js/util/status'),
|
2014-11-26 07:43:10 -05:00
|
|
|
ActionBarCtrl = require('../../../../src/js/controller/app/action-bar');
|
2014-11-05 08:26:09 -05:00
|
|
|
|
|
|
|
describe('Action Bar Controller unit test', function() {
|
2014-12-04 10:24:42 -05:00
|
|
|
var scope, actionBarCtrl, emailMock, dialogMock, statusMock;
|
2014-11-05 08:26:09 -05:00
|
|
|
|
|
|
|
beforeEach(function() {
|
2014-11-26 07:43:10 -05:00
|
|
|
emailMock = sinon.createStubInstance(Email);
|
|
|
|
dialogMock = sinon.createStubInstance(Dialog);
|
2014-12-04 10:24:42 -05:00
|
|
|
statusMock = sinon.createStubInstance(Status);
|
2014-11-05 08:26:09 -05:00
|
|
|
|
2014-12-04 10:24:42 -05:00
|
|
|
angular.module('actionbartest', ['woUtil']);
|
2014-11-26 07:43:10 -05:00
|
|
|
angular.mock.module('actionbartest');
|
|
|
|
angular.mock.inject(function($rootScope, $controller) {
|
2014-11-05 08:26:09 -05:00
|
|
|
scope = $rootScope.$new();
|
2014-12-04 10:24:42 -05:00
|
|
|
scope.state = {};
|
2014-11-05 08:26:09 -05:00
|
|
|
|
|
|
|
scope.state.nav = {
|
|
|
|
currentFolder: {
|
|
|
|
type: 'Inbox',
|
|
|
|
path: 'INBOX',
|
|
|
|
messages: [{
|
|
|
|
checked: true
|
|
|
|
}, {
|
|
|
|
checked: false
|
|
|
|
}]
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
actionBarCtrl = $controller(ActionBarCtrl, {
|
2014-11-26 07:43:10 -05:00
|
|
|
$scope: scope,
|
2014-12-18 09:19:06 -05:00
|
|
|
$q: window.qMock,
|
2014-11-26 07:43:10 -05:00
|
|
|
email: emailMock,
|
|
|
|
dialog: dialogMock,
|
2014-12-04 10:24:42 -05:00
|
|
|
status: statusMock
|
2014-11-05 08:26:09 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2014-11-26 07:43:10 -05:00
|
|
|
afterEach(function() {});
|
2014-11-05 08:26:09 -05:00
|
|
|
|
|
|
|
describe('deleteMessage', function() {
|
|
|
|
it('should not delete without a selected mail', function() {
|
|
|
|
scope.deleteMessage();
|
|
|
|
});
|
|
|
|
|
2014-12-18 09:19:06 -05:00
|
|
|
it('should delete the selected mail', function(done) {
|
|
|
|
emailMock.deleteMessage.returns(resolves());
|
2014-11-05 08:26:09 -05:00
|
|
|
|
2014-12-18 09:19:06 -05:00
|
|
|
scope.deleteMessage({}).then(function() {
|
|
|
|
expect(statusMock.setReading.withArgs(false).calledOnce).to.be.true;
|
|
|
|
expect(emailMock.deleteMessage.calledOnce).to.be.true;
|
|
|
|
done();
|
|
|
|
});
|
2014-11-05 08:26:09 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('deleteCheckedMessages', function() {
|
|
|
|
var deleteMessageStub;
|
|
|
|
|
|
|
|
beforeEach(function() {
|
|
|
|
deleteMessageStub = sinon.stub(scope, 'deleteMessage');
|
|
|
|
});
|
|
|
|
afterEach(function() {
|
|
|
|
deleteMessageStub.restore();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should delete the selected mail', function() {
|
|
|
|
scope.deleteCheckedMessages();
|
|
|
|
|
|
|
|
expect(deleteMessageStub.calledOnce).to.be.true;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('moveMessage', function() {
|
|
|
|
it('should not move without a selected mail', function() {
|
|
|
|
scope.moveMessage();
|
|
|
|
});
|
|
|
|
|
2014-12-18 09:19:06 -05:00
|
|
|
it('should move the selected mail', function(done) {
|
|
|
|
emailMock.moveMessage.returns(resolves());
|
2014-11-05 08:26:09 -05:00
|
|
|
|
2014-12-18 09:19:06 -05:00
|
|
|
scope.moveMessage({}, {}).then(function() {
|
|
|
|
expect(statusMock.setReading.withArgs(false).calledOnce).to.be.true;
|
|
|
|
expect(emailMock.moveMessage.calledOnce).to.be.true;
|
|
|
|
done();
|
|
|
|
});
|
2014-11-05 08:26:09 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('moveCheckedMessages', function() {
|
|
|
|
var moveMessageStub;
|
|
|
|
|
|
|
|
beforeEach(function() {
|
|
|
|
moveMessageStub = sinon.stub(scope, 'moveMessage');
|
|
|
|
});
|
|
|
|
afterEach(function() {
|
|
|
|
moveMessageStub.restore();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should delete the selected mail', function() {
|
|
|
|
scope.moveCheckedMessages();
|
|
|
|
|
|
|
|
expect(moveMessageStub.calledOnce).to.be.true;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2014-12-02 04:55:22 -05:00
|
|
|
describe('getJunkFolder', function() {
|
|
|
|
it('should work', function() {
|
|
|
|
scope.account = {
|
|
|
|
folders: [{
|
|
|
|
type: 'Junk'
|
|
|
|
}]
|
|
|
|
};
|
|
|
|
var folder = scope.getJunkFolder();
|
|
|
|
expect(folder).to.exist;
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should fail', function() {
|
|
|
|
scope.account = {
|
|
|
|
folders: [{
|
|
|
|
type: 'NotJunk'
|
|
|
|
}]
|
|
|
|
};
|
|
|
|
var folder = scope.getJunkFolder();
|
|
|
|
expect(folder).to.not.exist;
|
|
|
|
expect(dialogMock.error.calledOnce).to.be.true;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2014-11-05 08:26:09 -05:00
|
|
|
describe('markMessage', function() {
|
2014-12-02 12:36:15 -05:00
|
|
|
it('should not mark without a selected mail', function() {
|
2014-11-05 08:26:09 -05:00
|
|
|
scope.markMessage();
|
|
|
|
});
|
|
|
|
|
2014-12-02 12:36:15 -05:00
|
|
|
it('should not mark when old and new changes are equivalent', function() {
|
|
|
|
scope.markMessage({
|
|
|
|
unread: false
|
|
|
|
}, false);
|
|
|
|
|
|
|
|
scope.markMessage({
|
|
|
|
unread: true
|
|
|
|
}, true);
|
|
|
|
});
|
|
|
|
|
2014-12-18 09:19:06 -05:00
|
|
|
it('should mark the selected mail', function(done) {
|
|
|
|
emailMock.setFlags.returns(resolves());
|
2014-11-05 08:26:09 -05:00
|
|
|
|
2014-12-18 09:19:06 -05:00
|
|
|
scope.markMessage({}, true).then(function() {
|
|
|
|
expect(statusMock.setReading.withArgs(false).calledOnce).to.be.true;
|
|
|
|
expect(emailMock.setFlags.calledOnce).to.be.true;
|
|
|
|
done();
|
|
|
|
});
|
2014-12-04 10:24:42 -05:00
|
|
|
});
|
|
|
|
|
2014-12-18 09:19:06 -05:00
|
|
|
it('should mark the selected mail and close read mode', function(done) {
|
|
|
|
emailMock.setFlags.returns(resolves());
|
2014-12-04 10:24:42 -05:00
|
|
|
|
2014-12-18 09:19:06 -05:00
|
|
|
scope.markMessage({}, true, true).then(function() {
|
|
|
|
expect(statusMock.setReading.calledOnce).to.be.false;
|
|
|
|
expect(emailMock.setFlags.calledOnce).to.be.true;
|
|
|
|
done();
|
|
|
|
});
|
2014-11-05 08:26:09 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('markCheckedMessages', function() {
|
|
|
|
var markMessageStub;
|
|
|
|
|
|
|
|
beforeEach(function() {
|
|
|
|
markMessageStub = sinon.stub(scope, 'markMessage');
|
|
|
|
});
|
|
|
|
afterEach(function() {
|
|
|
|
markMessageStub.restore();
|
|
|
|
});
|
|
|
|
|
2014-12-02 12:36:15 -05:00
|
|
|
it('should mark the selected mail', function() {
|
2014-11-05 08:26:09 -05:00
|
|
|
scope.markCheckedMessages();
|
|
|
|
|
|
|
|
expect(markMessageStub.calledOnce).to.be.true;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2014-12-02 12:36:15 -05:00
|
|
|
describe('flagMessage', function() {
|
|
|
|
it('should not flag without a selected mail', function() {
|
|
|
|
scope.flagMessage();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should not flag when old and new changes are equivalent', function() {
|
|
|
|
scope.flagMessage({
|
|
|
|
flagged: false
|
|
|
|
}, false);
|
|
|
|
|
|
|
|
scope.flagMessage({
|
|
|
|
flagged: true
|
|
|
|
}, true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should flag the selected mail', function() {
|
2014-12-18 09:19:06 -05:00
|
|
|
emailMock.setFlags.returns(resolves());
|
2014-12-02 12:36:15 -05:00
|
|
|
|
2014-12-18 09:19:06 -05:00
|
|
|
scope.flagMessage({}, true).then(function() {
|
|
|
|
expect(emailMock.setFlags.calledOnce).to.be.true;
|
|
|
|
});
|
2014-12-02 12:36:15 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('flagCheckedMessages', function() {
|
|
|
|
var flagMessageStub;
|
|
|
|
|
|
|
|
beforeEach(function() {
|
|
|
|
flagMessageStub = sinon.stub(scope, 'flagMessage');
|
|
|
|
});
|
|
|
|
afterEach(function() {
|
|
|
|
flagMessageStub.restore();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should delete the selected mail', function() {
|
|
|
|
scope.flagCheckedMessages();
|
|
|
|
|
|
|
|
expect(flagMessageStub.calledOnce).to.be.true;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2014-11-05 08:26:09 -05:00
|
|
|
});
|