diff options
author | Jefferson Stachelski <jstachel@thoughtworks.com> | 2015-11-13 12:06:36 -0200 |
---|---|---|
committer | Jefferson Stachelski <jstachel@thoughtworks.com> | 2015-11-13 16:01:27 -0200 |
commit | 6f3e6e546457cacc35916bb7867edb1c5cfb9ab6 (patch) | |
tree | 450b2cfd5ac49fb2bf729b820bb861a0aff6dcc3 /web-ui/test/spec/services | |
parent | c9caf2f49ae09c7ce76022b63ed9047b37d71ffb (diff) |
Issue #523 - Added some JS test
Diffstat (limited to 'web-ui/test/spec/services')
-rw-r--r-- | web-ui/test/spec/services/mail_service.spec.js | 43 |
1 files changed, 40 insertions, 3 deletions
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; |