summaryrefslogtreecommitdiff
path: root/web-ui/test
diff options
context:
space:
mode:
authorRafael Lisboa <rafaelzlisboa@gmail.com>2015-04-27 12:35:02 -0300
committerRafael Lisboa <rafaelzlisboa@gmail.com>2015-04-27 12:35:02 -0300
commit9234ef399cac44dcdc8dab11c20dd162953e447c (patch)
treebbc3c618a245b903f99c1c41fa726062ead55ebf /web-ui/test
parent5cc53a2ac0b47a05423ed9e4a64e24a3a9994a58 (diff)
parent6617b24ae00490cf86282147b732cfa31de127fb (diff)
Merge pull request #373 from roberto/master
Allow user to move emails from trash to inbox
Diffstat (limited to 'web-ui/test')
-rw-r--r--web-ui/test/spec/mail_list_actions/ui/mail_list_actions.spec.js18
-rw-r--r--web-ui/test/spec/services/mail_service.spec.js36
-rw-r--r--web-ui/test/spec/services/recover_service.spec.js32
3 files changed, 86 insertions, 0 deletions
diff --git a/web-ui/test/spec/mail_list_actions/ui/mail_list_actions.spec.js b/web-ui/test/spec/mail_list_actions/ui/mail_list_actions.spec.js
index 7f7ba64a..d8917ed9 100644
--- a/web-ui/test/spec/mail_list_actions/ui/mail_list_actions.spec.js
+++ b/web-ui/test/spec/mail_list_actions/ui/mail_list_actions.spec.js
@@ -28,6 +28,24 @@ describeComponent('mail_list_actions/ui/mail_list_actions', function () {
expect(this.component.$node.html()).toMatch('<li><input type="button" id="delete-selected" value="Delete permanently" disabled="disabled"></li>');
});
+
+ it('should render move to inbox if on trash', function () {
+ var urlParams = require('page/router/url_params');
+ spyOn(urlParams, 'getTag').and.returnValue('trash');
+
+ this.setupComponent();
+
+ expect(this.component.$node.html()).toMatch('<li><input type="button" id="recover-selected" value="Move to Inbox" disabled="disabled"></li>');
+ });
+
+ it('should not render move to inbox if on trash', function () {
+ var urlParams = require('page/router/url_params');
+ spyOn(urlParams, 'getTag').and.returnValue('inbox');
+
+ this.setupComponent();
+
+ expect(this.component.$node.html()).not.toMatch('<li><input type="button" id="recover-selected" value="Move to Inbox" disabled="disabled"></li>');
+ });
});
});
diff --git a/web-ui/test/spec/services/mail_service.spec.js b/web-ui/test/spec/services/mail_service.spec.js
index 1a5cb9f7..7fb2bfda 100644
--- a/web-ui/test/spec/services/mail_service.spec.js
+++ b/web-ui/test/spec/services/mail_service.spec.js
@@ -174,6 +174,42 @@ describeComponent('services/mail_service', function () {
expect(spyEvent).toHaveBeenTriggeredOnAndWith(document, {message: i18n('Could not delete email')} );
});
+ it('will try to recover a message when requested to', function() {
+ var spyAjax = spyOn($, 'ajax').and.returnValue($.Deferred());
+ this.component.trigger(Pixelated.events.mail.recoverMany, {mails: [{ident: '43'}, {ident: '44'}]});
+ expect(spyAjax).toHaveBeenCalled();
+ expect(spyAjax.calls.mostRecent().args[0]).toEqual('/mails/recover');
+ 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;
+
+ beforeEach(function () {
+ displayMessageEvent = spyOnEvent(document, Pixelated.events.ui.userAlerts.displayMessage);
+ uncheckAllEvent = spyOnEvent(document, Pixelated.events.ui.mails.uncheckAll);
+ spyOn(this.component, 'refreshMails');
+
+ this.component.triggerRecovered({
+ successMessage: 'A success message',
+ mails: {1: 'email 1', 2: 'email 2'}
+ })();
+ });
+
+ it('will trigger that a message has been recovered when it is done recovering', function() {
+ expect(this.component.refreshMails).toHaveBeenCalled();
+ });
+
+ it('displays a success message', function () {
+ expect(displayMessageEvent).toHaveBeenTriggeredOnAndWith(document, {message: 'A success message'});
+ });
+
+ it('unchecks all checked mails', function () {
+ expect(uncheckAllEvent).toHaveBeenTriggeredOn(document);
+ });
+ });
+
it('triggers mails:available with received mails and keeps that tag as the current tag', function() {
var eventSpy = spyOnEvent(document, Pixelated.events.mails.available);
diff --git a/web-ui/test/spec/services/recover_service.spec.js b/web-ui/test/spec/services/recover_service.spec.js
new file mode 100644
index 00000000..86fe9f87
--- /dev/null
+++ b/web-ui/test/spec/services/recover_service.spec.js
@@ -0,0 +1,32 @@
+describeComponent('services/recover_service', function () {
+ 'use strict';
+
+ var i18n;
+
+ beforeEach( function () {
+ this.setupComponent();
+ i18n = require('views/i18n');
+ });
+
+ var mail1 = {
+ ident: 42,
+ isInTrash: function() { return false; }
+ };
+
+ var mail2 = {
+ ident: 34,
+ isInTrash: function() { return true; }
+ };
+
+ it('moves selected emails from trash back to inbox', function () {
+ var mailRecoverManyEvent = spyOnEvent(document, Pixelated.events.mail.recoverMany);
+ this.component.trigger(document, Pixelated.events.ui.mail.recoverMany, {checkedMails: {mail1: mail1, mail2: mail2}});
+
+ var expectedRecoverManyEventData = {
+ mails: [mail1, mail2],
+ successMessage: i18n('Your messages were moved to inbox!')
+ };
+
+ expect(mailRecoverManyEvent).toHaveBeenTriggeredOnAndWith(document, expectedRecoverManyEventData);
+ });
+});