summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJefferson Stachelski <jstachel@thoughtworks.com>2015-11-13 12:06:36 -0200
committerJefferson Stachelski <jstachel@thoughtworks.com>2015-11-13 16:01:27 -0200
commit6f3e6e546457cacc35916bb7867edb1c5cfb9ab6 (patch)
tree450b2cfd5ac49fb2bf729b820bb861a0aff6dcc3
parentc9caf2f49ae09c7ce76022b63ed9047b37d71ffb (diff)
Issue #523 - Added some JS test
-rw-r--r--web-ui/app/js/services/mail_service.js28
-rw-r--r--web-ui/test/spec/services/mail_service.spec.js43
2 files changed, 53 insertions, 18 deletions
diff --git a/web-ui/app/js/services/mail_service.js b/web-ui/app/js/services/mail_service.js
index 6a42d920..a63d517e 100644
--- a/web-ui/app/js/services/mail_service.js
+++ b/web-ui/app/js/services/mail_service.js
@@ -137,11 +137,23 @@ define(
return _.bind(function (response) {
this.refreshMails();
this.trigger(document, events.ui.userAlerts.displayMessage, { message: i18n(response.successMessage)});
- //this.trigger(document, events.ui.userAlerts.displayMessage, { message: i18n("Your message was archived")});
this.trigger(document, events.ui.mails.uncheckAll);
}, this);
};
+ this.archiveManyMails = function(event, dataToArchive) {
+ var mailIdents = _.map(dataToArchive.checkedMails, function (mail) {
+ return mail.ident;
+ });
+ monitoredAjax(this, '/mails/archive', {
+ type: 'POST',
+ dataType: 'json',
+ contentType: 'application/json; charset=utf-8',
+ data: JSON.stringify({idents: mailIdents})
+ }).done(this.triggerArchived(dataToArchive))
+ .fail(this.errorMessage(i18n('Could not archive emails')));
+ };
+
this.deleteMail = function (ev, data) {
monitoredAjax(this, '/mail/' + data.mail.ident,
{type: 'DELETE'})
@@ -179,20 +191,6 @@ define(
.fail(this.errorMessage(i18n('Could not move emails to inbox')));
};
- this.archiveManyMails = function(event, dataToArchive) {
- var mailIdents = _.map(dataToArchive.checkedMails, function (mail) {
- return mail.ident;
- });
-
- monitoredAjax(this, '/mails/archive', {
- type: 'POST',
- dataType: 'json',
- contentType: 'application/json; charset=utf-8',
- data: JSON.stringify({idents: mailIdents})
- }).done(this.triggerArchived(dataToArchive))
- .fail(this.errorMessage(i18n('Could not archive emails')));
- }
-
function compileQuery(data) {
var query = 'tag:"' + that.attr.currentTag + '"';
diff --git a/web-ui/test/spec/services/mail_service.spec.js b/web-ui/test/spec/services/mail_service.spec.js
index 7fb2bfda..d0911768 100644
--- a/web-ui/test/spec/services/mail_service.spec.js
+++ b/web-ui/test/spec/services/mail_service.spec.js
@@ -93,7 +93,6 @@ describeComponent('services/mail_service', function () {
var spyAjax = spyOn($, 'ajax').and.returnValue(deferred);
var spyEvent = spyOnEvent(document, Pixelated.events.mail.tags.updated);
- var component = jasmine.createSpyObj('component',['successUpdateTags']);
this.component.trigger(Pixelated.events.mail.tags.update, { ident: email1.ident, tags: email1.tags });
@@ -111,7 +110,6 @@ describeComponent('services/mail_service', function () {
var spyAjax = spyOn($, 'ajax').and.returnValue(deferred);
var spyEvent = spyOnEvent(document, Pixelated.events.ui.userAlerts.displayMessage);
- var component = jasmine.createSpyObj('component',['failureUpdateTags']);
this.component.trigger(Pixelated.events.mail.tags.update, { ident: email1.ident, tags: email1.tags });
@@ -169,7 +167,7 @@ describeComponent('services/mail_service', function () {
this.component.trigger(Pixelated.events.mail.delete, {mail: {ident: '43'}});
- deferred.reject({responseJSON: {}});
+ deferred.reject({mailsJSON: {}});
expect(spyEvent).toHaveBeenTriggeredOnAndWith(document, {message: i18n('Could not delete email')} );
});
@@ -183,6 +181,45 @@ describeComponent('services/mail_service', function () {
expect(spyAjax.calls.all()[0].args[1].data).toEqual(JSON.stringify({ idents: ['43', '44'] } ));
});
+ // TODO: WIP
+ describe('when try archive emails', function() {
+ var deferred, spyAjax, mails;
+
+ beforeEach(function() {
+ deferred = $.Deferred();
+ spyAjax = spyOn($, 'ajax').and.returnValue(deferred);
+ mails = {checkedMails: [{ident: '43'}, {ident: '44'}]};
+ });
+
+ it('should call triggerArchived', function() {
+ spyOn(this.component, 'triggerArchived');
+
+ this.component.trigger(Pixelated.events.mail.archiveMany, mails);
+
+ deferred.resolve();
+ expect(this.component.triggerArchived).toHaveBeenCalledWith(mails);
+ });
+
+ it('should show an error message when request returns no success', function() {
+ spyOn(this.component, 'errorMessage');
+
+ this.component.trigger(Pixelated.events.mail.archiveMany, mails);
+
+ deferred.reject({});
+ expect(this.component.errorMessage).toHaveBeenCalledWith(i18n('Could not archive emails'));
+ });
+
+ it('make an ajax request to /mails/archive', function() {
+ this.component.trigger(Pixelated.events.mail.archiveMany,
+ {checkedMails: [{ident: '43'}, {ident: '44'}]});
+
+ expect(spyAjax).toHaveBeenCalled();
+ expect(spyAjax.calls.mostRecent().args[0]).toEqual('/mails/archive');
+ expect(spyAjax.calls.mostRecent().args[1].type).toEqual('POST');
+ expect(spyAjax.calls.all()[0].args[1].data).toEqual(JSON.stringify({ idents: ['43', '44'] } ));
+ });
+ });
+
describe('when successfuly recovers emails', function () {
var displayMessageEvent, uncheckAllEvent, mailsRecoveredEvent;