1
0
mirror of https://github.com/moparisthebest/mail synced 2024-11-16 14:15:05 -05:00
mail/test/unit/controller/app/action-bar-ctrl-test.js

224 lines
6.3 KiB
JavaScript

'use strict';
var Email = require('../../../../src/js/email/email'),
Dialog = require('../../../../src/js/util/dialog'),
Status = require('../../../../src/js/util/status'),
ActionBarCtrl = require('../../../../src/js/controller/app/action-bar');
describe('Action Bar Controller unit test', function() {
var scope, actionBarCtrl, emailMock, dialogMock, statusMock;
beforeEach(function() {
emailMock = sinon.createStubInstance(Email);
dialogMock = sinon.createStubInstance(Dialog);
statusMock = sinon.createStubInstance(Status);
angular.module('actionbartest', ['woUtil']);
angular.mock.module('actionbartest');
angular.mock.inject(function($rootScope, $controller) {
scope = $rootScope.$new();
scope.state = {};
scope.state.nav = {
currentFolder: {
type: 'Inbox',
path: 'INBOX',
messages: [{
checked: true
}, {
checked: false
}]
}
};
actionBarCtrl = $controller(ActionBarCtrl, {
$scope: scope,
email: emailMock,
dialog: dialogMock,
status: statusMock
});
});
});
afterEach(function() {});
describe('deleteMessage', function() {
it('should not delete without a selected mail', function() {
scope.deleteMessage();
});
it('should delete the selected mail', function() {
emailMock.deleteMessage.yields();
scope.deleteMessage({});
expect(statusMock.setReading.withArgs(false).calledOnce).to.be.true;
expect(emailMock.deleteMessage.calledOnce).to.be.true;
});
});
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();
});
it('should move the selected mail', function() {
emailMock.moveMessage.yields();
scope.moveMessage({}, {});
expect(statusMock.setReading.withArgs(false).calledOnce).to.be.true;
expect(emailMock.moveMessage.calledOnce).to.be.true;
});
});
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;
});
});
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;
});
});
describe('markMessage', function() {
it('should not mark without a selected mail', function() {
scope.markMessage();
});
it('should not mark when old and new changes are equivalent', function() {
scope.markMessage({
unread: false
}, false);
scope.markMessage({
unread: true
}, true);
});
it('should mark the selected mail', function() {
emailMock.setFlags.yields();
scope.markMessage({}, true);
expect(statusMock.setReading.withArgs(false).calledOnce).to.be.true;
expect(emailMock.setFlags.calledOnce).to.be.true;
});
it('should mark the selected mail and close read mode', function() {
emailMock.setFlags.yields();
scope.markMessage({}, true, true);
expect(statusMock.setReading.calledOnce).to.be.false;
expect(emailMock.setFlags.calledOnce).to.be.true;
});
});
describe('markCheckedMessages', function() {
var markMessageStub;
beforeEach(function() {
markMessageStub = sinon.stub(scope, 'markMessage');
});
afterEach(function() {
markMessageStub.restore();
});
it('should mark the selected mail', function() {
scope.markCheckedMessages();
expect(markMessageStub.calledOnce).to.be.true;
});
});
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() {
emailMock.setFlags.yields();
scope.flagMessage({}, true);
expect(emailMock.setFlags.calledOnce).to.be.true;
});
});
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;
});
});
});