1
0
mirror of https://github.com/moparisthebest/mail synced 2024-11-23 09:22:23 -05:00
mail/test/unit/controller/app/navigation-ctrl-test.js

88 lines
3.0 KiB
JavaScript
Raw Normal View History

2014-10-07 14:32:23 -04:00
'use strict';
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');
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;
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);
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: {},
2014-12-18 09:19:06 -05:00
$q: window.qMock,
2014-11-25 12:19:40 -05:00
account: accountMock,
email: emailDaoMock,
outbox: outboxBoMock,
notification: notificationStub,
dialog: dialogStub
});
});
2014-10-07 14:32:23 -04:00
});
2014-11-25 12:19:40 -05:00
afterEach(function() {});
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;
});
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('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);
});
});
});