diff options
| author | Roberto Soares <roberto.tech@gmail.com> | 2015-04-09 15:58:22 -0300 | 
|---|---|---|
| committer | Roberto Soares <roberto.tech@gmail.com> | 2015-04-09 15:59:38 -0300 | 
| commit | e5b4ca353863a600a8d6151090b83f3210720a47 (patch) | |
| tree | dc815c1e397362be7d5cfe7d5536951000292f07 /web-ui/test | |
| parent | beac9142c2766ed8daf7dd13b6ba22b7895402a5 (diff) | |
listening event 'recoverMany'
Diffstat (limited to 'web-ui/test')
| -rw-r--r-- | web-ui/test/spec/mail_list_actions/ui/mail_list_actions.spec.js | 18 | ||||
| -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 | 
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); +  }); +}); | 
