2013-11-11 11:56:51 -05:00
|
|
|
define(function(require) {
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var expect = chai.expect,
|
|
|
|
angular = require('angular'),
|
|
|
|
mocks = require('angularMocks'),
|
|
|
|
NavigationCtrl = require('js/controller/navigation'),
|
|
|
|
EmailDAO = require('js/dao/email-dao'),
|
2013-11-19 10:14:48 -05:00
|
|
|
OutboxBO = require('js/bo/outbox'),
|
2013-11-11 11:56:51 -05:00
|
|
|
appController = require('js/app-controller');
|
|
|
|
|
|
|
|
describe('Navigation Controller unit test', function() {
|
2014-04-02 13:47:50 -04:00
|
|
|
var scope, ctrl, origEmailDao, emailDaoMock, outboxBoMock, hasIdentity, outboxFolder, onConnectStub;
|
2013-11-11 11:56:51 -05:00
|
|
|
|
2014-04-02 13:47:50 -04:00
|
|
|
beforeEach(function(done) {
|
2013-11-19 10:14:48 -05:00
|
|
|
hasIdentity = !! window.chrome.identity;
|
|
|
|
if (!hasIdentity) {
|
|
|
|
window.chrome.identity = {};
|
2013-11-11 11:56:51 -05:00
|
|
|
}
|
|
|
|
// remember original module to restore later
|
|
|
|
origEmailDao = appController._emailDao;
|
|
|
|
emailDaoMock = sinon.createStubInstance(EmailDAO);
|
2013-12-03 13:21:50 -05:00
|
|
|
emailDaoMock._account = {
|
|
|
|
folders: [{
|
|
|
|
type: 'Inbox',
|
|
|
|
count: 2,
|
|
|
|
path: 'INBOX'
|
|
|
|
}, {
|
|
|
|
type: 'Outbox',
|
|
|
|
count: 0,
|
|
|
|
path: 'OUTBOX'
|
|
|
|
}]
|
|
|
|
};
|
|
|
|
outboxFolder = emailDaoMock._account.folders[1];
|
2013-11-11 11:56:51 -05:00
|
|
|
appController._emailDao = emailDaoMock;
|
2013-11-19 10:14:48 -05:00
|
|
|
outboxBoMock = sinon.createStubInstance(OutboxBO);
|
|
|
|
appController._outboxBo = outboxBoMock;
|
|
|
|
outboxBoMock.startChecking.returns();
|
2014-04-02 13:47:50 -04:00
|
|
|
onConnectStub = sinon.stub(appController, 'onConnect');
|
|
|
|
onConnectStub.yields();
|
2013-11-11 11:56:51 -05:00
|
|
|
|
|
|
|
angular.module('navigationtest', []);
|
|
|
|
mocks.module('navigationtest');
|
|
|
|
mocks.inject(function($rootScope, $controller) {
|
|
|
|
scope = $rootScope.$new();
|
|
|
|
scope.state = {};
|
|
|
|
ctrl = $controller(NavigationCtrl, {
|
|
|
|
$scope: scope
|
|
|
|
});
|
2014-04-02 13:47:50 -04:00
|
|
|
done();
|
2013-11-11 11:56:51 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(function() {
|
|
|
|
// restore the module
|
|
|
|
appController._emailDao = origEmailDao;
|
2013-11-19 10:14:48 -05:00
|
|
|
if (hasIdentity) {
|
|
|
|
delete window.chrome.identity;
|
2013-11-11 11:56:51 -05:00
|
|
|
}
|
2014-04-02 13:47:50 -04:00
|
|
|
onConnectStub.restore();
|
2013-11-11 11:56:51 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('initial state', function() {
|
|
|
|
it('should be well defined', function() {
|
|
|
|
expect(scope.state).to.exist;
|
2014-04-24 10:45:09 -04:00
|
|
|
expect(scope.state.lightbox).to.be.undefined;
|
2013-12-03 13:21:50 -05:00
|
|
|
expect(scope.account.folders).to.not.be.empty;
|
2013-11-11 11:56:51 -05:00
|
|
|
expect(scope.openFolder).to.exist;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
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;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('open folder', function() {
|
|
|
|
it('should work', function() {
|
|
|
|
scope.state.nav.open = true;
|
|
|
|
|
|
|
|
scope.openFolder('asd');
|
|
|
|
expect(scope.state.nav.currentFolder).to.equal('asd');
|
|
|
|
expect(scope.state.nav.open).to.be.false;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('empty outbox', function() {
|
|
|
|
it('should work', function() {
|
2013-11-19 10:14:48 -05:00
|
|
|
var callback;
|
2013-11-11 11:56:51 -05:00
|
|
|
|
2013-11-19 10:14:48 -05:00
|
|
|
expect(outboxBoMock.startChecking.callCount).to.equal(1);
|
2013-11-11 11:56:51 -05:00
|
|
|
|
2013-11-19 10:14:48 -05:00
|
|
|
outboxBoMock.startChecking.calledWith(sinon.match(function(cb) {
|
|
|
|
callback = cb;
|
|
|
|
}));
|
2013-11-11 11:56:51 -05:00
|
|
|
|
2013-11-19 10:14:48 -05:00
|
|
|
callback(null, 5);
|
|
|
|
expect(outboxFolder.count).to.equal(5);
|
2013-11-11 11:56:51 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|