diff options
Diffstat (limited to 'web-ui/test/spec/services')
-rw-r--r-- | web-ui/test/spec/services/mail_service.spec.js | 36 | ||||
-rw-r--r-- | web-ui/test/spec/services/recover_service.spec.js | 32 |
2 files changed, 68 insertions, 0 deletions
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); + }); +}); |