mirror of https://github.com/moparisthebest/mail
reactivate tests for mail list ctrl
This commit is contained in:
parent
78453fd416
commit
32d0c08822
|
@ -2,6 +2,7 @@ define(function(require) {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var angular = require('angular'),
|
var angular = require('angular'),
|
||||||
|
_ = require('underscore'),
|
||||||
appController = require('js/app-controller'),
|
appController = require('js/app-controller'),
|
||||||
IScroll = require('iscroll'),
|
IScroll = require('iscroll'),
|
||||||
str = require('js/app-config').string,
|
str = require('js/app-config').string,
|
||||||
|
@ -9,8 +10,6 @@ define(function(require) {
|
||||||
emailDao, outboxBo;
|
emailDao, outboxBo;
|
||||||
|
|
||||||
var MailListCtrl = function($scope) {
|
var MailListCtrl = function($scope) {
|
||||||
var firstSelect = true;
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// Init
|
// Init
|
||||||
//
|
//
|
||||||
|
@ -18,37 +17,37 @@ define(function(require) {
|
||||||
emailDao = appController._emailDao;
|
emailDao = appController._emailDao;
|
||||||
outboxBo = appController._outboxBo;
|
outboxBo = appController._outboxBo;
|
||||||
|
|
||||||
// // push handler
|
// push handler
|
||||||
// if (emailDao) {
|
if (emailDao) {
|
||||||
// emailDao.onIncomingMessage = function(email) {
|
emailDao.onIncomingMessage = function(email) {
|
||||||
// if (email.subject.indexOf(str.subjectPrefix) === -1) {
|
if (email.subject.indexOf(str.subjectPrefix) === -1) {
|
||||||
// return;
|
return;
|
||||||
// }
|
}
|
||||||
|
|
||||||
// // sync
|
// sync
|
||||||
// $scope.synchronize(function() {
|
$scope.synchronize(function() {
|
||||||
// // show notification
|
// show notification
|
||||||
// notificationForEmail(email);
|
notificationForEmail(email);
|
||||||
// });
|
});
|
||||||
// };
|
};
|
||||||
// chrome.notifications.onClicked.addListener(notificationClicked);
|
chrome.notifications.onClicked.addListener(notificationClicked);
|
||||||
// }
|
}
|
||||||
|
|
||||||
// function notificationClicked(uidString) {
|
function notificationClicked(uidString) {
|
||||||
// var email, uid = parseInt(uidString, 10);
|
var email, uid = parseInt(uidString, 10);
|
||||||
|
|
||||||
// if (isNaN(uid)) {
|
if (isNaN(uid)) {
|
||||||
// return;
|
return;
|
||||||
// }
|
}
|
||||||
|
|
||||||
// email = _.findWhere(getFolder().messages, {
|
email = _.findWhere(getFolder().messages, {
|
||||||
// uid: uid
|
uid: uid
|
||||||
// });
|
});
|
||||||
|
|
||||||
// if (email) {
|
if (email) {
|
||||||
// $scope.select(email);
|
$scope.select(email);
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// scope functions
|
// scope functions
|
||||||
|
@ -66,7 +65,7 @@ define(function(require) {
|
||||||
// markAsRead(email);
|
// markAsRead(email);
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.synchronize = function() {
|
$scope.synchronize = function(callback) {
|
||||||
// if we're in the outbox, don't do an imap sync
|
// if we're in the outbox, don't do an imap sync
|
||||||
if (getFolder().type === 'Outbox') {
|
if (getFolder().type === 'Outbox') {
|
||||||
updateStatus('Last update: ', new Date());
|
updateStatus('Last update: ', new Date());
|
||||||
|
@ -90,8 +89,11 @@ define(function(require) {
|
||||||
displayEmails(getFolder().messages);
|
displayEmails(getFolder().messages);
|
||||||
// display last update
|
// display last update
|
||||||
updateStatus('Last update: ', new Date());
|
updateStatus('Last update: ', new Date());
|
||||||
|
|
||||||
$scope.$apply();
|
$scope.$apply();
|
||||||
|
|
||||||
|
if (callback) {
|
||||||
|
callback();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -100,83 +102,40 @@ define(function(require) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// var index, currentFolder, trashFolder, outboxFolder;
|
var index, currentFolder, outboxFolder;
|
||||||
|
|
||||||
// currentFolder = getFolder();
|
|
||||||
|
|
||||||
|
currentFolder = getFolder();
|
||||||
// trashFolder = _.findWhere($scope.folders, {
|
// trashFolder = _.findWhere($scope.folders, {
|
||||||
// type: 'Trash'
|
// type: 'Trash'
|
||||||
// });
|
// });
|
||||||
|
outboxFolder = _.findWhere($scope.account.folders, {
|
||||||
|
type: 'Outbox'
|
||||||
|
});
|
||||||
|
|
||||||
// outboxFolder = _.findWhere($scope.folders, {
|
if (currentFolder === outboxFolder) {
|
||||||
// type: 'Outbox'
|
$scope.onError({
|
||||||
// });
|
errMsg: 'Deleting messages from the outbox is not yet supported.'
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// if (currentFolder === outboxFolder) {
|
removeAndShowNext();
|
||||||
// $scope.onError({
|
$scope.synchronize();
|
||||||
// errMsg: 'Deleting messages from the outbox is not yet supported.'
|
|
||||||
// });
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// if (currentFolder === trashFolder) {
|
function removeAndShowNext() {
|
||||||
// $scope.state.dialog = {
|
index = getFolder().messages.indexOf(email);
|
||||||
// open: true,
|
// show the next mail
|
||||||
// title: 'Delete',
|
if (getFolder().messages.length > 1) {
|
||||||
// message: 'Delete this message permanently?',
|
// if we're about to delete the last entry of the array, show the previous (i.e. the one below in the list),
|
||||||
// callback: function(ok) {
|
// otherwise show the next one (i.e. the one above in the list)
|
||||||
// if (!ok) {
|
$scope.select(_.last(getFolder().messages) === email ? getFolder().messages[index - 1] : getFolder().messages[index + 1]);
|
||||||
// return;
|
} else {
|
||||||
// }
|
// if we have only one email in the array, show nothing
|
||||||
|
$scope.select();
|
||||||
// removeLocalAndShowNext();
|
$scope.state.mailList.selected = undefined;
|
||||||
// removeRemote();
|
}
|
||||||
// }
|
getFolder().messages.splice(index, 1);
|
||||||
// };
|
}
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// removeLocalAndShowNext();
|
|
||||||
// removeRemote();
|
|
||||||
|
|
||||||
// function removeLocalAndShowNext() {
|
|
||||||
// index = getFolder().messages.indexOf(email);
|
|
||||||
// // show the next mail
|
|
||||||
// if (getFolder().messages.length > 1) {
|
|
||||||
// // if we're about to delete the last entry of the array, show the previous (i.e. the one below in the list),
|
|
||||||
// // otherwise show the next one (i.e. the one above in the list)
|
|
||||||
// $scope.select(_.last(getFolder().messages) === email ? getFolder().messages[index - 1] : getFolder().messages[index + 1]);
|
|
||||||
// } else {
|
|
||||||
// // if we have only one email in the array, show nothing
|
|
||||||
// $scope.select();
|
|
||||||
// $scope.state.mailList.selected = undefined;
|
|
||||||
// }
|
|
||||||
// getFolder().messages.splice(index, 1);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// function removeRemote() {
|
|
||||||
// if (getFolder() === trashFolder) {
|
|
||||||
// emailDao.imapDeleteMessage({
|
|
||||||
// folder: getFolder().path,
|
|
||||||
// uid: email.uid
|
|
||||||
// }, moved);
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// emailDao.imapMoveMessage({
|
|
||||||
// folder: getFolder().path,
|
|
||||||
// uid: email.uid,
|
|
||||||
// destination: trashFolder.path
|
|
||||||
// }, moved);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// function moved(err) {
|
|
||||||
// if (err) {
|
|
||||||
// getFolder().messages.splice(index, 0, email);
|
|
||||||
// $scope.onError(err);
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope._stopWatchTask = $scope.$watch('state.nav.currentFolder', function() {
|
$scope._stopWatchTask = $scope.$watch('state.nav.currentFolder', function() {
|
||||||
|
@ -186,7 +145,6 @@ define(function(require) {
|
||||||
|
|
||||||
// development... display dummy mail objects
|
// development... display dummy mail objects
|
||||||
if (!window.chrome || !chrome.identity) {
|
if (!window.chrome || !chrome.identity) {
|
||||||
firstSelect = true;
|
|
||||||
updateStatus('Last update: ', new Date());
|
updateStatus('Last update: ', new Date());
|
||||||
getFolder().messages = createDummyMails();
|
getFolder().messages = createDummyMails();
|
||||||
displayEmails(getFolder().messages);
|
displayEmails(getFolder().messages);
|
||||||
|
@ -217,14 +175,14 @@ define(function(require) {
|
||||||
// helper functions
|
// helper functions
|
||||||
//
|
//
|
||||||
|
|
||||||
// function notificationForEmail(email) {
|
function notificationForEmail(email) {
|
||||||
// chrome.notifications.create('' + email.uid, {
|
chrome.notifications.create('' + email.uid, {
|
||||||
// type: 'basic',
|
type: 'basic',
|
||||||
// title: email.from[0].address,
|
title: email.from[0].address,
|
||||||
// message: email.subject.split(str.subjectPrefix)[1],
|
message: email.subject.split(str.subjectPrefix)[1],
|
||||||
// iconUrl: chrome.runtime.getURL(cfg.iconPath)
|
iconUrl: chrome.runtime.getURL(cfg.iconPath)
|
||||||
// }, function() {});
|
}, function() {});
|
||||||
// }
|
}
|
||||||
|
|
||||||
function updateStatus(lbl, time) {
|
function updateStatus(lbl, time) {
|
||||||
$scope.lastUpdateLbl = lbl;
|
$scope.lastUpdateLbl = lbl;
|
||||||
|
@ -251,12 +209,6 @@ define(function(require) {
|
||||||
// return;
|
// return;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// // don't mark top selected email automatically
|
|
||||||
// if (firstSelect) {
|
|
||||||
// firstSelect = false;
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// $scope.state.read.toggle(true);
|
// $scope.state.read.toggle(true);
|
||||||
// if (!window.chrome || !chrome.socket) {
|
// if (!window.chrome || !chrome.socket) {
|
||||||
// return;
|
// return;
|
||||||
|
|
|
@ -109,7 +109,7 @@ define(function(require) {
|
||||||
expect(scope.synchronize).to.exist;
|
expect(scope.synchronize).to.exist;
|
||||||
expect(scope.remove).to.exist;
|
expect(scope.remove).to.exist;
|
||||||
expect(scope.state.mailList).to.exist;
|
expect(scope.state.mailList).to.exist;
|
||||||
expect(emailDaoMock.onIncomingMessage).to.exist;
|
// expect(emailDaoMock.onIncomingMessage).to.exist;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -136,19 +136,12 @@ define(function(require) {
|
||||||
toggle: function() {}
|
toggle: function() {}
|
||||||
};
|
};
|
||||||
scope.emails = [mail];
|
scope.emails = [mail];
|
||||||
emailDaoMock.imapMarkMessageRead.withArgs({
|
emailDaoMock.sync.yieldsAsync();
|
||||||
folder: currentFolder,
|
|
||||||
uid: uid
|
|
||||||
}).yields();
|
|
||||||
emailDaoMock.unreadMessages.yieldsAsync(null, 10);
|
|
||||||
emailDaoMock.imapSync.yieldsAsync();
|
|
||||||
emailDaoMock.listMessages.yieldsAsync(null, [mail]);
|
|
||||||
window.chrome.notifications.create = function(id, opts) {
|
window.chrome.notifications.create = function(id, opts) {
|
||||||
expect(id).to.equal('123');
|
expect(id).to.equal('123');
|
||||||
expect(opts.type).to.equal('basic');
|
expect(opts.type).to.equal('basic');
|
||||||
expect(opts.message).to.equal('asdasd');
|
expect(opts.message).to.equal('asdasd');
|
||||||
expect(opts.title).to.equal('asd');
|
expect(opts.title).to.equal('asd');
|
||||||
expect(emailDaoMock.imapMarkMessageRead.callCount).to.equal(0);
|
|
||||||
done();
|
done();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -157,75 +150,55 @@ define(function(require) {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('clicking push notification', function() {
|
describe('clicking push notification', function() {
|
||||||
it('should focus mail and mark it read', function() {
|
it('should focus mail', function() {
|
||||||
var uid, mail, currentFolder;
|
var mail, currentFolder;
|
||||||
|
|
||||||
scope._stopWatchTask();
|
scope._stopWatchTask();
|
||||||
|
|
||||||
uid = 123;
|
|
||||||
mail = {
|
mail = {
|
||||||
uid: uid,
|
uid: 123,
|
||||||
from: [{
|
from: [{
|
||||||
address: 'asd'
|
address: 'asd'
|
||||||
}],
|
}],
|
||||||
subject: '[whiteout] asdasd',
|
subject: '[whiteout] asdasd',
|
||||||
unread: true
|
unread: true
|
||||||
};
|
};
|
||||||
currentFolder = 'asd';
|
currentFolder = {
|
||||||
|
type: 'asd',
|
||||||
|
messages: [mail]
|
||||||
|
};
|
||||||
scope.state.nav = {
|
scope.state.nav = {
|
||||||
currentFolder: currentFolder
|
currentFolder: currentFolder
|
||||||
};
|
};
|
||||||
scope.state.read = {
|
|
||||||
toggle: function() {}
|
|
||||||
};
|
|
||||||
scope.emails = [mail];
|
|
||||||
emailDaoMock.imapMarkMessageRead.withArgs({
|
|
||||||
folder: currentFolder,
|
|
||||||
uid: uid
|
|
||||||
}).yields();
|
|
||||||
|
|
||||||
notificationClickedHandler('123'); // first select, irrelevant
|
|
||||||
notificationClickedHandler('123');
|
notificationClickedHandler('123');
|
||||||
|
|
||||||
expect(scope.state.mailList.selected).to.equal(mail);
|
expect(scope.state.mailList.selected).to.equal(mail);
|
||||||
expect(emailDaoMock.imapMarkMessageRead.callCount).to.be.at.least(1);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('watch task', function() {
|
describe('synchronize', function() {
|
||||||
it('should do a local list and a full imap sync and mark the first message read', function(done) {
|
it('should do imap sync and display mails', function() {
|
||||||
emailDaoMock.unreadMessages.yields(null, 3);
|
scope._stopWatchTask();
|
||||||
emailDaoMock.imapSync.yields();
|
|
||||||
emailDaoMock.listMessages.yieldsAsync(null, emails);
|
|
||||||
|
|
||||||
scope.state.read = {
|
emailDaoMock.sync.yieldsAsync();
|
||||||
toggle: function() {}
|
|
||||||
};
|
|
||||||
|
|
||||||
var currentFolder = {
|
var currentFolder = {
|
||||||
type: 'Inbox'
|
type: 'Inbox',
|
||||||
|
messages: emails
|
||||||
};
|
};
|
||||||
scope.folders = [currentFolder];
|
scope.folders = [currentFolder];
|
||||||
scope.state.nav = {
|
scope.state.nav = {
|
||||||
currentFolder: currentFolder
|
currentFolder: currentFolder
|
||||||
};
|
};
|
||||||
|
|
||||||
// the behavior should be async and imapMarkMessageRead is
|
scope.synchronize(function() {
|
||||||
emailDaoMock.imapMarkMessageRead = function() {
|
expect(scope.state.nav.currentFolder.messages).to.deep.equal(emails);
|
||||||
expect(scope.emails).to.deep.equal(emails);
|
expect(scope.state.mailList.selected).to.exist;
|
||||||
expect(scope.state.mailList.selected).to.equal(emails[0]);
|
});
|
||||||
expect(emailDaoMock.unreadMessages.callCount).to.equal(2);
|
|
||||||
expect(emailDaoMock.imapSync.callCount).to.equal(2);
|
|
||||||
expect(emailDaoMock.listMessages.callCount).to.equal(3);
|
|
||||||
|
|
||||||
done();
|
|
||||||
};
|
|
||||||
|
|
||||||
scope.synchronize();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('synchronize', function() {
|
|
||||||
it('should read directly from outbox instead of doing a full imap sync', function() {
|
it('should read directly from outbox instead of doing a full imap sync', function() {
|
||||||
scope._stopWatchTask();
|
scope._stopWatchTask();
|
||||||
|
|
||||||
|
@ -239,7 +212,8 @@ define(function(require) {
|
||||||
|
|
||||||
scope.synchronize();
|
scope.synchronize();
|
||||||
|
|
||||||
expect(scope.state.mailList.selected).to.equal(emails[0]);
|
// emails array is also used as the outbox's pending mail
|
||||||
|
expect(scope.state.mailList.selected).to.deep.equal(emails[0]);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -247,7 +221,7 @@ define(function(require) {
|
||||||
it('should not delete without a selected mail', function() {
|
it('should not delete without a selected mail', function() {
|
||||||
scope.remove();
|
scope.remove();
|
||||||
|
|
||||||
expect(emailDaoMock.imapDeleteMessage.called).to.be.false;
|
expect(emailDaoMock.sync.called).to.be.false;
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not delete from the outbox', function(done) {
|
it('should not delete from the outbox', function(done) {
|
||||||
|
@ -255,19 +229,30 @@ define(function(require) {
|
||||||
|
|
||||||
scope._stopWatchTask();
|
scope._stopWatchTask();
|
||||||
|
|
||||||
mail = {};
|
scope.account = {};
|
||||||
currentFolder = {
|
mail = {
|
||||||
type: 'Outbox'
|
uid: 123,
|
||||||
|
from: [{
|
||||||
|
address: 'asd'
|
||||||
|
}],
|
||||||
|
subject: '[whiteout] asdasd',
|
||||||
|
unread: true
|
||||||
};
|
};
|
||||||
|
currentFolder = {
|
||||||
|
type: 'Outbox',
|
||||||
|
path: 'OUTBOX',
|
||||||
|
messages: [mail]
|
||||||
|
};
|
||||||
|
|
||||||
scope.emails = [mail];
|
scope.emails = [mail];
|
||||||
scope.folders = [currentFolder];
|
scope.account.folders = [currentFolder];
|
||||||
scope.state.nav = {
|
scope.state.nav = {
|
||||||
currentFolder: currentFolder
|
currentFolder: currentFolder
|
||||||
};
|
};
|
||||||
|
|
||||||
scope.onError = function(err) {
|
scope.onError = function(err) {
|
||||||
expect(err).to.exist; // would normally display the notification
|
expect(err).to.exist; // would normally display the notification
|
||||||
expect(emailDaoMock.imapDeleteMessage.called).to.be.false;
|
expect(emailDaoMock.sync.called).to.be.false;
|
||||||
done();
|
done();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -275,11 +260,12 @@ define(function(require) {
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should delete the selected mail from trash folder after clicking ok', function() {
|
it('should delete the selected mail', function() {
|
||||||
var uid, mail, currentFolder;
|
var uid, mail, currentFolder;
|
||||||
|
|
||||||
scope._stopWatchTask();
|
scope._stopWatchTask();
|
||||||
|
|
||||||
|
scope.account = {};
|
||||||
uid = 123;
|
uid = 123;
|
||||||
mail = {
|
mail = {
|
||||||
uid: uid,
|
uid: uid,
|
||||||
|
@ -289,59 +275,20 @@ define(function(require) {
|
||||||
subject: '[whiteout] asdasd',
|
subject: '[whiteout] asdasd',
|
||||||
unread: true
|
unread: true
|
||||||
};
|
};
|
||||||
scope.emails = [mail];
|
|
||||||
currentFolder = {
|
|
||||||
type: 'Trash'
|
|
||||||
};
|
|
||||||
scope.folders = [currentFolder];
|
|
||||||
scope.state.nav = {
|
|
||||||
currentFolder: currentFolder
|
|
||||||
};
|
|
||||||
emailDaoMock.imapDeleteMessage.yields();
|
|
||||||
|
|
||||||
scope.remove(mail);
|
|
||||||
scope.state.dialog.callback(true);
|
|
||||||
|
|
||||||
expect(emailDaoMock.imapDeleteMessage.calledOnce).to.be.true;
|
|
||||||
expect(scope.state.mailList.selected).to.not.exist;
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should move the selected mail to the trash folder', function() {
|
|
||||||
var uid, mail, currentFolder, trashFolder;
|
|
||||||
|
|
||||||
scope._stopWatchTask();
|
|
||||||
|
|
||||||
uid = 123;
|
|
||||||
mail = {
|
|
||||||
uid: uid,
|
|
||||||
from: [{
|
|
||||||
address: 'asd'
|
|
||||||
}],
|
|
||||||
subject: '[whiteout] asdasd',
|
|
||||||
unread: true
|
|
||||||
};
|
|
||||||
scope.emails = [mail];
|
|
||||||
currentFolder = {
|
currentFolder = {
|
||||||
type: 'Inbox',
|
type: 'Inbox',
|
||||||
path: 'INBOX'
|
path: 'INBOX',
|
||||||
|
messages: [mail]
|
||||||
};
|
};
|
||||||
trashFolder = {
|
scope.account.folders = [currentFolder];
|
||||||
type: 'Trash',
|
|
||||||
path: 'TRASH'
|
|
||||||
};
|
|
||||||
scope.folders = [currentFolder, trashFolder];
|
|
||||||
scope.state.nav = {
|
scope.state.nav = {
|
||||||
currentFolder: currentFolder
|
currentFolder: currentFolder
|
||||||
};
|
};
|
||||||
emailDaoMock.imapMoveMessage.withArgs({
|
emailDaoMock.sync.yields();
|
||||||
folder: currentFolder,
|
|
||||||
uid: uid,
|
|
||||||
destination: trashFolder.path
|
|
||||||
}).yields();
|
|
||||||
|
|
||||||
scope.remove(mail);
|
scope.remove(mail);
|
||||||
|
|
||||||
expect(emailDaoMock.imapMoveMessage.calledOnce).to.be.true;
|
expect(emailDaoMock.sync.calledOnce).to.be.true;
|
||||||
expect(scope.state.mailList.selected).to.not.exist;
|
expect(scope.state.mailList.selected).to.not.exist;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue