2014-10-07 14:32:23 -04:00
|
|
|
'use strict';
|
2013-11-11 11:56:51 -05:00
|
|
|
|
2014-11-25 12:19:40 -05:00
|
|
|
var NavigationCtrl = require('../../../../src/js/controller/app/navigation'),
|
|
|
|
Email = require('../../../../src/js/email/email'),
|
|
|
|
Account = require('../../../../src/js/email/account'),
|
|
|
|
Outbox = require('../../../../src/js/email/outbox'),
|
|
|
|
Dialog = require('../../../../src/js/util/dialog'),
|
|
|
|
Notif = require('../../../../src/js/util/notification');
|
2013-11-11 11:56:51 -05:00
|
|
|
|
2014-10-07 14:32:23 -04:00
|
|
|
describe('Navigation Controller unit test', function() {
|
2014-11-25 12:19:40 -05:00
|
|
|
var scope, ctrl, emailDaoMock, accountMock, notificationStub, dialogStub, outboxBoMock, outboxFolder;
|
2013-11-11 11:56:51 -05:00
|
|
|
|
2014-11-25 12:19:40 -05:00
|
|
|
beforeEach(function() {
|
|
|
|
var account = {
|
2014-10-07 14:32:23 -04:00
|
|
|
folders: [{
|
|
|
|
type: 'Inbox',
|
|
|
|
count: 2,
|
|
|
|
path: 'INBOX'
|
|
|
|
}, {
|
|
|
|
type: 'Outbox',
|
|
|
|
count: 0,
|
|
|
|
path: 'OUTBOX'
|
|
|
|
}]
|
|
|
|
};
|
2014-11-25 12:19:40 -05:00
|
|
|
|
|
|
|
emailDaoMock = sinon.createStubInstance(Email);
|
|
|
|
outboxFolder = account.folders[1];
|
|
|
|
outboxBoMock = sinon.createStubInstance(Outbox);
|
2014-10-07 14:32:23 -04:00
|
|
|
outboxBoMock.startChecking.returns();
|
2014-11-25 12:19:40 -05:00
|
|
|
dialogStub = sinon.createStubInstance(Dialog);
|
|
|
|
notificationStub = sinon.createStubInstance(Notif);
|
|
|
|
accountMock = sinon.createStubInstance(Account);
|
|
|
|
accountMock.list.returns([account]);
|
2014-11-26 13:51:15 -05:00
|
|
|
accountMock.isLoggedIn.returns(true);
|
2013-11-11 11:56:51 -05:00
|
|
|
|
2014-11-25 12:19:40 -05:00
|
|
|
angular.module('navigationtest', ['woServices', 'woEmail', 'woUtil']);
|
|
|
|
angular.mock.module('navigationtest');
|
|
|
|
angular.mock.inject(function($rootScope, $controller) {
|
2014-10-07 14:32:23 -04:00
|
|
|
scope = $rootScope.$new();
|
|
|
|
scope.state = {};
|
|
|
|
ctrl = $controller(NavigationCtrl, {
|
|
|
|
$scope: scope,
|
2014-11-25 12:19:40 -05:00
|
|
|
$routeParams: {},
|
|
|
|
account: accountMock,
|
|
|
|
email: emailDaoMock,
|
|
|
|
outbox: outboxBoMock,
|
|
|
|
notification: notificationStub,
|
|
|
|
dialog: dialogStub
|
2013-11-11 11:56:51 -05:00
|
|
|
});
|
|
|
|
});
|
2014-10-07 14:32:23 -04:00
|
|
|
});
|
2013-11-11 11:56:51 -05:00
|
|
|
|
2014-11-25 12:19:40 -05:00
|
|
|
afterEach(function() {});
|
2013-11-11 11:56:51 -05:00
|
|
|
|
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;
|
2013-11-11 11:56:51 -05:00
|
|
|
});
|
2014-10-07 14:32:23 -04:00
|
|
|
});
|
2013-11-11 11:56:51 -05: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;
|
2013-11-11 11:56:51 -05:00
|
|
|
});
|
2014-10-07 14:32:23 -04:00
|
|
|
});
|
2013-11-11 11:56:51 -05:00
|
|
|
|
2014-10-07 14:32:23 -04:00
|
|
|
describe('empty outbox', function() {
|
|
|
|
it('should work', function() {
|
|
|
|
var callback;
|
2013-11-11 11:56:51 -05:00
|
|
|
|
2014-10-07 14:32:23 -04:00
|
|
|
expect(outboxBoMock.startChecking.callCount).to.equal(1);
|
2013-11-11 11:56:51 -05:00
|
|
|
|
2014-10-07 14:32:23 -04:00
|
|
|
outboxBoMock.startChecking.calledWith(sinon.match(function(cb) {
|
|
|
|
callback = cb;
|
|
|
|
}));
|
2013-11-11 11:56:51 -05:00
|
|
|
|
2014-10-07 14:32:23 -04:00
|
|
|
callback(null, 5);
|
|
|
|
expect(outboxFolder.count).to.equal(5);
|
2013-11-11 11:56:51 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|