1
0
mirror of https://github.com/moparisthebest/mail synced 2024-11-29 12:22:22 -05:00

Use status service to close read mode from action bar

This commit is contained in:
Tankred Hase 2014-12-04 16:24:42 +01:00
parent 33b30221f7
commit df9ba7fd66
13 changed files with 119 additions and 192 deletions

View File

@ -2,7 +2,11 @@
var JUNK_FOLDER_TYPE = 'Junk'; var JUNK_FOLDER_TYPE = 'Junk';
var ActionBarCtrl = function($scope, email, dialog, statusDisplay) { var ActionBarCtrl = function($scope, email, dialog, status) {
//
// scope functions
//
/** /**
* Move a single message from the currently selected folder to another folder * Move a single message from the currently selected folder to another folder
@ -15,9 +19,9 @@ var ActionBarCtrl = function($scope, email, dialog, statusDisplay) {
} }
// close read state // close read state
$scope.state.read.toggle(false); status.setReading(false);
// show message
statusDisplay.update('Moving message...'); status.update('Moving message...');
email.moveMessage({ email.moveMessage({
folder: currentFolder(), folder: currentFolder(),
@ -28,14 +32,14 @@ var ActionBarCtrl = function($scope, email, dialog, statusDisplay) {
// show errors where appropriate // show errors where appropriate
if (err.code === 42) { if (err.code === 42) {
$scope.select(message); $scope.select(message);
statusDisplay.update('Unable to move message in offline mode!'); status.update('Unable to move message in offline mode!');
return; return;
} }
statusDisplay.update('Error during move!'); status.update('Error during move!');
dialog.error(err); dialog.error(err);
return; return;
} }
statusDisplay.update('Message moved.'); status.update('Message moved.');
$scope.$apply(); $scope.$apply();
}); });
}; };
@ -76,9 +80,8 @@ var ActionBarCtrl = function($scope, email, dialog, statusDisplay) {
} }
// close read state // close read state
$scope.state.read.toggle(false); status.setReading(false);
status.update('Deleting message...');
statusDisplay.update('Deleting message...');
email.deleteMessage({ email.deleteMessage({
folder: currentFolder(), folder: currentFolder(),
@ -88,14 +91,14 @@ var ActionBarCtrl = function($scope, email, dialog, statusDisplay) {
// show errors where appropriate // show errors where appropriate
if (err.code === 42) { if (err.code === 42) {
$scope.select(message); $scope.select(message);
statusDisplay.update('Unable to delete message in offline mode!'); status.update('Unable to delete message in offline mode!');
return; return;
} }
statusDisplay.update('Error during delete!'); status.update('Error during delete!');
dialog.error(err); dialog.error(err);
return; return;
} }
statusDisplay.update('Message deleted.'); status.update('Message deleted.');
$scope.$apply(); $scope.$apply();
}); });
}; };
@ -118,11 +121,11 @@ var ActionBarCtrl = function($scope, email, dialog, statusDisplay) {
return; return;
} }
statusDisplay.update('Updating unread flag...'); status.update('Updating unread flag...');
// close read state // close read state
if (!keepOpen) { if (!keepOpen) {
$scope.state.read.toggle(false); status.setReading(false);
} }
var originalState = message.unread; var originalState = message.unread;
@ -134,17 +137,17 @@ var ActionBarCtrl = function($scope, email, dialog, statusDisplay) {
if (err && err.code === 42) { if (err && err.code === 42) {
// offline, restore // offline, restore
message.unread = originalState; message.unread = originalState;
statusDisplay.update('Unable to mark message in offline mode!'); status.update('Unable to mark message in offline mode!');
return; return;
} }
if (err) { if (err) {
statusDisplay.update('Error on sync!'); status.update('Error on sync!');
dialog.error(err); dialog.error(err);
return; return;
} }
statusDisplay.update('Online'); status.update('Online');
$scope.$apply(); $scope.$apply();
}); });
}; };
@ -169,7 +172,7 @@ var ActionBarCtrl = function($scope, email, dialog, statusDisplay) {
return; return;
} }
statusDisplay.update(flagged ? 'Adding star to message...' : 'Removing star from message'); status.update(flagged ? 'Adding star to message...' : 'Removing star from message');
var originalState = message.flagged; var originalState = message.flagged;
message.flagged = flagged; message.flagged = flagged;
@ -180,17 +183,17 @@ var ActionBarCtrl = function($scope, email, dialog, statusDisplay) {
if (err && err.code === 42) { if (err && err.code === 42) {
// offline, restore // offline, restore
message.unread = originalState; message.unread = originalState;
statusDisplay.update('Unable to ' + (flagged ? 'add star to' : 'remove star from') + ' message in offline mode!'); status.update('Unable to ' + (flagged ? 'add star to' : 'remove star from') + ' message in offline mode!');
return; return;
} }
if (err) { if (err) {
statusDisplay.update('Error on sync!'); status.update('Error on sync!');
dialog.error(err); dialog.error(err);
return; return;
} }
statusDisplay.update('Online'); status.update('Online');
$scope.$apply(); $scope.$apply();
}); });
}; };

View File

@ -11,10 +11,10 @@ var INIT_DISPLAY_LEN = 50,
FOLDER_TYPE_INBOX = 'Inbox', FOLDER_TYPE_INBOX = 'Inbox',
NOTIFICATION_INBOX_TIMEOUT = 5000; NOTIFICATION_INBOX_TIMEOUT = 5000;
var MailListCtrl = function($scope, $timeout, $location, $filter, statusDisplay, notification, email, keychain, dialog, search, dummy) { var MailListCtrl = function($scope, $timeout, $location, $filter, status, notification, email, keychain, dialog, search, dummy) {
// //
// Init // scope state
// //
$scope.state.mailList = {}; $scope.state.mailList = {};
@ -156,7 +156,7 @@ var MailListCtrl = function($scope, $timeout, $location, $filter, statusDisplay,
// in development, display dummy mail objects // in development, display dummy mail objects
if ($location.search().dev) { if ($location.search().dev) {
statusDisplay.update('Last update: ', new Date()); status.update('Last update: ', new Date());
currentFolder().messages = dummy.listMails(); currentFolder().messages = dummy.listMails();
return; return;
} }
@ -217,20 +217,20 @@ var MailListCtrl = function($scope, $timeout, $location, $filter, statusDisplay,
if (!searchText) { if (!searchText) {
// set display buffer to first messages // set display buffer to first messages
$scope.displayMessages = currentFolder().messages.slice(0, INIT_DISPLAY_LEN); $scope.displayMessages = currentFolder().messages.slice(0, INIT_DISPLAY_LEN);
statusDisplay.setSearching(false); status.setSearching(false);
statusDisplay.update('Online'); status.update('Online');
return; return;
} }
// display searching spinner // display searching spinner
statusDisplay.setSearching(true); status.setSearching(true);
statusDisplay.update('Searching ...'); status.update('Searching ...');
searchTimeout = setTimeout(function() { searchTimeout = setTimeout(function() {
$scope.$apply(function() { $scope.$apply(function() {
// filter relevant messages // filter relevant messages
$scope.displayMessages = search.filter(currentFolder().messages, searchText); $scope.displayMessages = search.filter(currentFolder().messages, searchText);
statusDisplay.setSearching(false); status.setSearching(false);
statusDisplay.update('Matches in this folder'); status.update('Matches in this folder');
}); });
}, 500); }, 500);
}; };
@ -242,10 +242,10 @@ var MailListCtrl = function($scope, $timeout, $location, $filter, statusDisplay,
// wait one cycle for the status display controllers to init // wait one cycle for the status display controllers to init
$timeout(function() { $timeout(function() {
if (isOnline) { if (isOnline) {
statusDisplay.update('Online'); status.update('Online');
openCurrentFolder(); openCurrentFolder();
} else { } else {
statusDisplay.update('Offline mode'); status.update('Offline mode');
} }
}); });
}, true); }, true);

View File

@ -12,9 +12,6 @@ var ReadCtrl = function($scope, $location, email, invitation, outbox, pgp, keych
// scope state // scope state
// //
// set default value so that the popover height is correct on init
$scope.keyId = 'No key found.';
$scope.state.read = { $scope.state.read = {
open: false, open: false,
toggle: function(to) { toggle: function(to) {
@ -22,6 +19,13 @@ var ReadCtrl = function($scope, $location, email, invitation, outbox, pgp, keych
} }
}; };
$scope.$on('read', function(e, state) {
$scope.state.read.toggle(state);
});
// set default value so that the popover height is correct on init
$scope.keyId = 'No key found.';
// //
// url/history handling // url/history handling
// //

View File

@ -7,6 +7,6 @@ require('./dummy');
require('./dialog'); require('./dialog');
require('./connection-doctor'); require('./connection-doctor');
require('./update/update-handler'); require('./update/update-handler');
require('./status-display'); require('./status');
require('./download'); require('./download');
require('./notification'); require('./notification');

View File

@ -1,13 +1,13 @@
'use strict'; 'use strict';
var ngModule = angular.module('woUtil'); var ngModule = angular.module('woUtil');
ngModule.service('statusDisplay', StatusDisplay); ngModule.service('status', Status);
module.exports = StatusDisplay; module.exports = Status;
/** /**
* A central service to display status updates to the user * A central service to display status updates to the user
*/ */
function StatusDisplay($rootScope, axe) { function Status($rootScope, axe) {
this._rootScope = $rootScope; this._rootScope = $rootScope;
this._axe = axe; this._axe = axe;
} }
@ -17,7 +17,7 @@ function StatusDisplay($rootScope, axe) {
* @param {String} text The status message that is to be displayed to the user * @param {String} text The status message that is to be displayed to the user
* @param {Date} time The time of the last update * @param {Date} time The time of the last update
*/ */
StatusDisplay.prototype.update = function(text, time) { Status.prototype.update = function(text, time) {
this._axe.info('status display', text); this._axe.info('status display', text);
this._rootScope.$broadcast('status', text, time); this._rootScope.$broadcast('status', text, time);
}; };
@ -26,6 +26,14 @@ StatusDisplay.prototype.update = function(text, time) {
* Update the searching status to show a spinner while searching * Update the searching status to show a spinner while searching
* @param {Boolean} state If the spinner should be displayed or not * @param {Boolean} state If the spinner should be displayed or not
*/ */
StatusDisplay.prototype.setSearching = function(state) { Status.prototype.setSearching = function(state) {
this._rootScope.$broadcast('searching', state); this._rootScope.$broadcast('searching', state);
}; };
/**
* Update the reading status to communicate between controllers, if we're in read mode.
* @param {Boolean} state If the reade mode should be open or not
*/
Status.prototype.setReading = function(state) {
this._rootScope.$broadcast('read', state);
};

View File

@ -2,26 +2,22 @@
var Email = require('../../../../src/js/email/email'), var Email = require('../../../../src/js/email/email'),
Dialog = require('../../../../src/js/util/dialog'), Dialog = require('../../../../src/js/util/dialog'),
StatusDisplay = require('../../../../src/js/util/status-display'), Status = require('../../../../src/js/util/status'),
ActionBarCtrl = require('../../../../src/js/controller/app/action-bar'); ActionBarCtrl = require('../../../../src/js/controller/app/action-bar');
describe('Action Bar Controller unit test', function() { describe('Action Bar Controller unit test', function() {
var scope, actionBarCtrl, emailMock, dialogMock, statusDisplayMock; var scope, actionBarCtrl, emailMock, dialogMock, statusMock;
beforeEach(function() { beforeEach(function() {
emailMock = sinon.createStubInstance(Email); emailMock = sinon.createStubInstance(Email);
dialogMock = sinon.createStubInstance(Dialog); dialogMock = sinon.createStubInstance(Dialog);
statusDisplayMock = sinon.createStubInstance(StatusDisplay); statusMock = sinon.createStubInstance(Status);
angular.module('actionbartest', []); angular.module('actionbartest', ['woUtil']);
angular.mock.module('actionbartest'); angular.mock.module('actionbartest');
angular.mock.inject(function($rootScope, $controller) { angular.mock.inject(function($rootScope, $controller) {
scope = $rootScope.$new(); scope = $rootScope.$new();
scope.state = { scope.state = {};
mailList: {
updateStatus: function() {}
}
};
scope.state.nav = { scope.state.nav = {
currentFolder: { currentFolder: {
@ -35,15 +31,11 @@ describe('Action Bar Controller unit test', function() {
} }
}; };
scope.state.read = {
open: true
};
actionBarCtrl = $controller(ActionBarCtrl, { actionBarCtrl = $controller(ActionBarCtrl, {
$scope: scope, $scope: scope,
email: emailMock, email: emailMock,
dialog: dialogMock, dialog: dialogMock,
statusDisplay: statusDisplayMock status: statusMock
}); });
}); });
}); });
@ -60,8 +52,8 @@ describe('Action Bar Controller unit test', function() {
scope.deleteMessage({}); scope.deleteMessage({});
expect(statusMock.setReading.withArgs(false).calledOnce).to.be.true;
expect(emailMock.deleteMessage.calledOnce).to.be.true; expect(emailMock.deleteMessage.calledOnce).to.be.true;
expect(scope.state.read.open).to.be.false;
}); });
}); });
@ -92,8 +84,8 @@ describe('Action Bar Controller unit test', function() {
scope.moveMessage({}, {}); scope.moveMessage({}, {});
expect(statusMock.setReading.withArgs(false).calledOnce).to.be.true;
expect(emailMock.moveMessage.calledOnce).to.be.true; expect(emailMock.moveMessage.calledOnce).to.be.true;
expect(scope.state.read.open).to.be.false;
}); });
}); });
@ -157,8 +149,17 @@ describe('Action Bar Controller unit test', function() {
scope.markMessage({}, true); 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; expect(emailMock.setFlags.calledOnce).to.be.true;
expect(scope.state.read.open).to.be.false;
}); });
}); });

View File

@ -3,34 +3,15 @@
var MailListCtrl = require('../../../../src/js/controller/app/mail-list'), var MailListCtrl = require('../../../../src/js/controller/app/mail-list'),
EmailDAO = require('../../../../src/js/email/email'), EmailDAO = require('../../../../src/js/email/email'),
KeychainDAO = require('../../../../src/js/service/keychain'), KeychainDAO = require('../../../../src/js/service/keychain'),
StatusDisplay = require('../../../../src/js/util/status-display'), Status = require('../../../../src/js/util/status'),
Dialog = require('../../../../src/js/util/dialog'), Dialog = require('../../../../src/js/util/dialog'),
Search = require('../../../../src/js/email/search'); Search = require('../../../../src/js/email/search');
describe('Mail List controller unit test', function() { describe('Mail List controller unit test', function() {
var scope, ctrl, statusDisplayMock, notificationMock, emailMock, keychainMock, dialogMock, searchMock, var scope, ctrl, statusMock, notificationMock, emailMock, keychainMock, dialogMock, searchMock,
emailAddress, emails, emailAddress, emails, location;
hasChrome, hasSocket, hasRuntime, hasIdentity;
beforeEach(function() { beforeEach(function() {
hasChrome = !!window.chrome;
hasSocket = !!window.chrome.socket;
hasIdentity = !!window.chrome.identity;
if (!hasChrome) {
window.chrome = {};
}
if (!hasSocket) {
window.chrome.socket = {};
}
if (!hasRuntime) {
window.chrome.runtime = {
getURL: function() {}
};
}
if (!hasIdentity) {
window.chrome.identity = {};
}
emails = [{ emails = [{
unread: true unread: true
}, { }, {
@ -46,7 +27,7 @@ describe('Mail List controller unit test', function() {
close: function() {} close: function() {}
}; };
statusDisplayMock = sinon.createStubInstance(StatusDisplay); statusMock = sinon.createStubInstance(Status);
emailMock = sinon.createStubInstance(EmailDAO); emailMock = sinon.createStubInstance(EmailDAO);
keychainMock = sinon.createStubInstance(KeychainDAO); keychainMock = sinon.createStubInstance(KeychainDAO);
dialogMock = sinon.createStubInstance(Dialog); dialogMock = sinon.createStubInstance(Dialog);
@ -54,19 +35,16 @@ describe('Mail List controller unit test', function() {
angular.module('maillisttest', ['woEmail', 'woServices', 'woUtil']); angular.module('maillisttest', ['woEmail', 'woServices', 'woUtil']);
angular.mock.module('maillisttest'); angular.mock.module('maillisttest');
angular.mock.inject(function($rootScope, $controller) { angular.mock.inject(function($rootScope, $controller, $location) {
scope = $rootScope.$new(); scope = $rootScope.$new();
scope.state = { location = $location;
read: { scope.state = {};
toggle: function() {}
}
};
scope.loadVisibleBodies = function() {}; scope.loadVisibleBodies = function() {};
ctrl = $controller(MailListCtrl, { ctrl = $controller(MailListCtrl, {
$scope: scope, $scope: scope,
$routeParams: {}, $location: location,
statusDisplay: statusDisplayMock, status: statusMock,
notification: notificationMock, notification: notificationMock,
email: emailMock, email: emailMock,
keychain: keychainMock, keychain: keychainMock,
@ -76,20 +54,7 @@ describe('Mail List controller unit test', function() {
}); });
}); });
afterEach(function() { afterEach(function() {});
if (!hasSocket) {
delete window.chrome.socket;
}
if (!hasRuntime) {
delete window.chrome.runtime;
}
if (!hasChrome) {
delete window.chrome;
}
if (!hasIdentity) {
delete window.chrome.identity;
}
});
describe('displayMore', function() { describe('displayMore', function() {
beforeEach(function() { beforeEach(function() {
@ -132,21 +97,21 @@ describe('Mail List controller unit test', function() {
it('should show initial message on empty', function() { it('should show initial message on empty', function() {
scope.displaySearchResults(); scope.displaySearchResults();
expect(statusDisplayMock.setSearching.withArgs(false).calledOnce).to.be.true; expect(statusMock.setSearching.withArgs(false).calledOnce).to.be.true;
expect(statusDisplayMock.update.withArgs('Online').calledOnce).to.be.true; expect(statusMock.update.withArgs('Online').calledOnce).to.be.true;
expect(scope.displayMessages.length).to.equal(2); expect(scope.displayMessages.length).to.equal(2);
}); });
it('should show initial message on empty', function() { it('should show initial message on empty', function() {
searchMock.filter.returns(['a']); searchMock.filter.returns(['a']);
scope.displaySearchResults('query'); scope.displaySearchResults('query');
expect(statusDisplayMock.setSearching.withArgs(true).calledOnce).to.be.true; expect(statusMock.setSearching.withArgs(true).calledOnce).to.be.true;
expect(statusDisplayMock.update.withArgs('Searching ...').calledOnce).to.be.true; expect(statusMock.update.withArgs('Searching ...').calledOnce).to.be.true;
clock.tick(500); clock.tick(500);
expect(scope.displayMessages).to.deep.equal(['a']); expect(scope.displayMessages).to.deep.equal(['a']);
expect(statusDisplayMock.setSearching.withArgs(false).calledOnce).to.be.true; expect(statusMock.setSearching.withArgs(false).calledOnce).to.be.true;
expect(statusDisplayMock.update.withArgs('Matches in this folder').calledOnce).to.be.true; expect(statusMock.update.withArgs('Matches in this folder').calledOnce).to.be.true;
}); });
}); });
@ -160,10 +125,12 @@ describe('Mail List controller unit test', function() {
describe('push notification', function() { describe('push notification', function() {
beforeEach(function() { beforeEach(function() {
scope._stopWatchTask(); scope._stopWatchTask();
sinon.stub(scope, 'navigate');
}); });
afterEach(function() { afterEach(function() {
notificationMock.create.restore(); notificationMock.create.restore();
scope.navigate.restore();
}); });
it('should succeed for single mail', function(done) { it('should succeed for single mail', function(done) {
@ -181,7 +148,7 @@ describe('Mail List controller unit test', function() {
expect(opts.message).to.equal(mail.subject); expect(opts.message).to.equal(mail.subject);
opts.onClick(); opts.onClick();
expect(scope.state.mailList.selected).to.equal(mail); expect(scope.navigate.withArgs(mail).calledOnce).to.be.true;
done(); done();
}); });
@ -224,7 +191,7 @@ describe('Mail List controller unit test', function() {
expect(opts.message).to.equal(mails[0].subject + '\n' + mails[1].subject); expect(opts.message).to.equal(mails[0].subject + '\n' + mails[1].subject);
opts.onClick(); opts.onClick();
expect(scope.state.mailList.selected).to.equal(mails[0]); expect(scope.navigate.withArgs(mails[0]).calledOnce).to.be.true;
done(); done();
}); });
@ -358,7 +325,7 @@ describe('Mail List controller unit test', function() {
})); }));
it('should output date only if date is not today', angular.mock.inject(function($filter) { it('should output date only if date is not today', angular.mock.inject(function($filter) {
var yesterday = new Date(); var yesterday = new Date();
yesterday.setTime(yesterday.getTime() - 24*60*60*1000); yesterday.setTime(yesterday.getTime() - 24 * 60 * 60 * 1000);
var expected = $filter('date')(yesterday, 'mediumDate'); var expected = $filter('date')(yesterday, 'mediumDate');
expect(scope.formatDate(yesterday)).to.equal(expected); expect(scope.formatDate(yesterday)).to.equal(expected);

View File

@ -119,7 +119,7 @@ describe('Login Controller unit test', function() {
expect(dialogMock.error.calledOnce).to.be.true; expect(dialogMock.error.calledOnce).to.be.true;
}); });
it('should redirect to /desktop', function() { it('should redirect to /account', function() {
authMock.init.yields(); authMock.init.yields();
authMock.getEmailAddress.yields(null, { authMock.getEmailAddress.yields(null, {
emailAddress: emailAddress emailAddress: emailAddress
@ -133,7 +133,7 @@ describe('Login Controller unit test', function() {
createController(); createController();
expect(goToStub.withArgs('/desktop').calledOnce).to.be.true; expect(goToStub.withArgs('/account').calledOnce).to.be.true;
}); });
it('should fail for keychain.requestPrivateKeyDownload', function() { it('should fail for keychain.requestPrivateKeyDownload', function() {

View File

@ -60,7 +60,7 @@ describe('Login (existing user) Controller unit test', function() {
expect(keychainMock.getUserKeyPair.calledOnce).to.be.true; expect(keychainMock.getUserKeyPair.calledOnce).to.be.true;
expect(emailDaoMock.unlock.calledOnce).to.be.true; expect(emailDaoMock.unlock.calledOnce).to.be.true;
expect(pathSpy.calledOnce).to.be.true; expect(pathSpy.calledOnce).to.be.true;
expect(pathSpy.calledWith('/desktop')).to.be.true; expect(pathSpy.calledWith('/account')).to.be.true;
}); });
it('should not work when keypair unavailable', function() { it('should not work when keypair unavailable', function() {

View File

@ -102,7 +102,7 @@ describe('Login (initial user) Controller unit test', function() {
expect(scope.errMsg).to.not.exist; expect(scope.errMsg).to.not.exist;
expect(scope.state.ui).to.equal(2); expect(scope.state.ui).to.equal(2);
expect(newsletterStub.called).to.be.true; expect(newsletterStub.called).to.be.true;
expect(location.$$path).to.equal('/desktop'); expect(location.$$path).to.equal('/account');
expect(emailMock.unlock.calledOnce).to.be.true; expect(emailMock.unlock.calledOnce).to.be.true;
}); });
}); });

View File

@ -152,7 +152,7 @@ describe('Login Private Key Download Controller unit test', function() {
scope.decryptAndStorePrivateKeyLocally(); scope.decryptAndStorePrivateKeyLocally();
}); });
it('should goto /desktop on emailDao.unlock success', function(done) { it('should goto /account on emailDao.unlock success', function(done) {
keychainMock.decryptAndStorePrivateKeyLocally.yields(null, { keychainMock.decryptAndStorePrivateKeyLocally.yields(null, {
encryptedKey: 'keyArmored' encryptedKey: 'keyArmored'
}); });
@ -160,7 +160,7 @@ describe('Login Private Key Download Controller unit test', function() {
authMock.storeCredentials.yields(); authMock.storeCredentials.yields();
scope.goTo = function(location) { scope.goTo = function(location) {
expect(location).to.equal('/desktop'); expect(location).to.equal('/account');
expect(keychainMock.decryptAndStorePrivateKeyLocally.calledOnce).to.be.true; expect(keychainMock.decryptAndStorePrivateKeyLocally.calledOnce).to.be.true;
expect(emailDaoMock.unlock.calledOnce).to.be.true; expect(emailDaoMock.unlock.calledOnce).to.be.true;
done(); done();
@ -173,10 +173,10 @@ describe('Login Private Key Download Controller unit test', function() {
describe('goTo', function() { describe('goTo', function() {
it('should work', function() { it('should work', function() {
sinon.stub(location, 'path', function(path) { sinon.stub(location, 'path', function(path) {
expect(path).to.equal('/desktop'); expect(path).to.equal('/account');
}); });
scope.goTo('/desktop'); scope.goTo('/account');
}); });
}); });
}); });

View File

@ -1,64 +0,0 @@
'use strict';
var btnHandler = require('../../../src/js/util/backbutton-handler');
describe('Backbutton Handler', function() {
chai.config.includeStack = true;
var scope, event;
beforeEach(function() {
scope = {
state: {},
$apply: function() {}
};
event = new CustomEvent('backbutton');
// this is a precondition for the test. throw an exception
// if this would produce side effects
expect(navigator.app).to.not.exist;
navigator.app = {};
btnHandler.attachHandler(scope);
btnHandler.start();
});
afterEach(function() {
btnHandler.stop();
delete navigator.app;
});
it('should close lightbox', function() {
scope.state.lightbox = 'asd';
document.dispatchEvent(event);
expect(scope.state.lightbox).to.be.undefined;
});
it('should close reader', function() {
scope.state.read = {
open: true,
toggle: function(state) {
scope.state.read.open = state;
}
};
document.dispatchEvent(event);
expect(scope.state.read.open).to.be.false;
});
it('should close navigation', function() {
scope.state.nav = {
open: true,
toggle: function(state) {
scope.state.nav.open = state;
}
};
document.dispatchEvent(event);
expect(scope.state.nav.open).to.be.false;
});
it('should close app', function(done) {
navigator.app.exitApp = done;
document.dispatchEvent(event);
});
});

View File

@ -1,14 +1,14 @@
'use strict'; 'use strict';
describe('Status Display Service unit test', function() { describe('Status Service unit test', function() {
var statusDisplay, logInfoStub, rootScope, broadcastSpy; var status, logInfoStub, rootScope, broadcastSpy;
beforeEach(function() { beforeEach(function() {
angular.module('statusDisplay-test', ['woUtil']); angular.module('status-test', ['woUtil']);
angular.mock.module('statusDisplay-test'); angular.mock.module('status-test');
angular.mock.inject(function($injector, axe) { angular.mock.inject(function($injector, axe) {
logInfoStub = sinon.stub(axe, 'info'); logInfoStub = sinon.stub(axe, 'info');
statusDisplay = $injector.get('statusDisplay'); status = $injector.get('status');
rootScope = $injector.get('$rootScope'); rootScope = $injector.get('$rootScope');
broadcastSpy = sinon.spy(rootScope, '$broadcast'); broadcastSpy = sinon.spy(rootScope, '$broadcast');
}); });
@ -23,7 +23,7 @@ describe('Status Display Service unit test', function() {
var message = 'Tada!', var message = 'Tada!',
time = new Date(); time = new Date();
statusDisplay.update(message, time); status.update(message, time);
expect(broadcastSpy.withArgs('status', message, time).calledOnce).to.be.true; expect(broadcastSpy.withArgs('status', message, time).calledOnce).to.be.true;
expect(logInfoStub.withArgs('status display', message).calledOnce).to.be.true; expect(logInfoStub.withArgs('status display', message).calledOnce).to.be.true;
@ -32,10 +32,18 @@ describe('Status Display Service unit test', function() {
describe('setSearching', function() { describe('setSearching', function() {
it('should work', function() { it('should work', function() {
statusDisplay.setSearching(true); status.setSearching(true);
expect(broadcastSpy.withArgs('searching', true).calledOnce).to.be.true; expect(broadcastSpy.withArgs('searching', true).calledOnce).to.be.true;
}); });
}); });
describe('setReading', function() {
it('should work', function() {
status.setReading(true);
expect(broadcastSpy.withArgs('read', true).calledOnce).to.be.true;
});
});
}); });