1
0
mirror of https://github.com/moparisthebest/mail synced 2024-12-24 08:18:48 -05:00
mail/test/unit/navigation-ctrl-test.js

97 lines
3.1 KiB
JavaScript
Raw Normal View History

2014-10-07 14:32:23 -04:00
'use strict';
2014-10-09 09:56:35 -04:00
var mocks = angular.mock,
2014-10-07 14:32:23 -04:00
NavigationCtrl = require('../../src/js/controller/navigation'),
EmailDAO = require('../../src/js/dao/email-dao'),
OutboxBO = require('../../src/js/bo/outbox'),
appController = require('../../src/js/app-controller');
2014-10-07 14:32:23 -04:00
describe('Navigation Controller unit test', function() {
var scope, ctrl, origEmailDao, emailDaoMock, outboxBoMock, outboxFolder, onConnectStub;
2014-10-07 14:32:23 -04:00
beforeEach(function(done) {
// remember original module to restore later
origEmailDao = appController._emailDao;
emailDaoMock = sinon.createStubInstance(EmailDAO);
emailDaoMock._account = {
folders: [{
type: 'Inbox',
count: 2,
path: 'INBOX'
}, {
type: 'Outbox',
count: 0,
path: 'OUTBOX'
}]
};
outboxFolder = emailDaoMock._account.folders[1];
appController._emailDao = emailDaoMock;
outboxBoMock = sinon.createStubInstance(OutboxBO);
appController._outboxBo = outboxBoMock;
outboxBoMock.startChecking.returns();
onConnectStub = sinon.stub(appController, 'onConnect');
onConnectStub.yields();
2014-10-07 14:32:23 -04:00
angular.module('navigationtest', []);
mocks.module('navigationtest');
mocks.inject(function($rootScope, $controller) {
scope = $rootScope.$new();
scope.state = {};
ctrl = $controller(NavigationCtrl, {
$scope: scope,
$routeParams: {}
});
2014-10-07 14:32:23 -04:00
done();
});
2014-10-07 14:32:23 -04:00
});
2014-10-07 14:32:23 -04:00
afterEach(function() {
// restore the module
appController._emailDao = origEmailDao;
onConnectStub.restore();
});
2014-10-07 14:32:23 -04:00
describe('initial state', function() {
it('should be well defined', function() {
expect(scope.state).to.exist;
expect(scope.state.lightbox).to.be.undefined;
expect(scope.account.folders).to.not.be.empty;
expect(scope.openFolder).to.exist;
});
2014-10-07 14:32:23 -04:00
});
2014-10-07 14:32:23 -04:00
describe('open/close nav view', function() {
it('should open/close', function() {
expect(scope.state.nav.open).to.be.false;
scope.state.nav.toggle(true);
expect(scope.state.nav.open).to.be.true;
scope.state.nav.toggle(false);
expect(scope.state.nav.open).to.be.false;
});
2014-10-07 14:32:23 -04:00
});
2014-10-07 14:32:23 -04:00
describe('open folder', function() {
it('should work', function() {
scope.state.nav.open = true;
2014-10-07 14:32:23 -04:00
scope.openFolder('asd');
expect(scope.state.nav.currentFolder).to.equal('asd');
expect(scope.state.nav.open).to.be.false;
});
2014-10-07 14:32:23 -04:00
});
2014-10-07 14:32:23 -04:00
describe('empty outbox', function() {
it('should work', function() {
var callback;
2014-10-07 14:32:23 -04:00
expect(outboxBoMock.startChecking.callCount).to.equal(1);
2014-10-07 14:32:23 -04:00
outboxBoMock.startChecking.calledWith(sinon.match(function(cb) {
callback = cb;
}));
2014-10-07 14:32:23 -04:00
callback(null, 5);
expect(outboxFolder.count).to.equal(5);
});
});
});