diff options
author | Ola Bini <ola.bini@gmail.com> | 2014-07-31 19:29:33 -0300 |
---|---|---|
committer | Ola Bini <ola.bini@gmail.com> | 2014-07-31 19:29:33 -0300 |
commit | 04cf441c5ae18400c6b4865b0b37a71718dc9d46 (patch) | |
tree | dd0b0d049ec00389e2d4561b226c46eb1682b997 /web-ui/test/spec/mail_view/data | |
parent | 639a663a4c37020003586438fdcd7ac529a00f10 (diff) |
Add web-ui based on previous code
Diffstat (limited to 'web-ui/test/spec/mail_view/data')
-rw-r--r-- | web-ui/test/spec/mail_view/data/mail_builder.spec.js | 110 | ||||
-rw-r--r-- | web-ui/test/spec/mail_view/data/mail_sender.spec.js | 70 |
2 files changed, 180 insertions, 0 deletions
diff --git a/web-ui/test/spec/mail_view/data/mail_builder.spec.js b/web-ui/test/spec/mail_view/data/mail_builder.spec.js new file mode 100644 index 00000000..bf17d598 --- /dev/null +++ b/web-ui/test/spec/mail_view/data/mail_builder.spec.js @@ -0,0 +1,110 @@ +define(['mail_view/data/mail_builder'], function (mailBuilder) { + describe('mail builder', function () { + 'use strict'; + + it('sets ident if passed to constructor', function() { + var mail = mailBuilder.newMail('12345').build(); + + expect(mail.ident).toBe('12345'); + }); + + it('sets ident to empty if not passed to constructor', function() { + var mail = mailBuilder.newMail().build(); + + expect(mail.ident).toBe(''); + }); + + it('sets the subject', function() { + var mail = mailBuilder.newMail().subject("subject").build(); + + expect(mail.header.subject).toBe("subject"); + }); + + it('sets the body', function() { + var mail = mailBuilder.newMail().body("some body text").build(); + + expect(mail.body).toBe("some body text"); + }); + + describe('to field', function() { + it('adds a single address', function() { + var mail = mailBuilder.newMail().to('foo@bar.com').build(); + + expect(mail.header.to).toContain('foo@bar.com'); + }); + + it('adds multiple addresses', function() { + var mail = mailBuilder.newMail().to('foo@bar.com bar@foo.com').build(); + + expect(mail.header.to).toContain('foo@bar.com'); + expect(mail.header.to).toContain('bar@foo.com'); + }); + + it('accepts undefined without breaking', function() { + var mail = mailBuilder.newMail().to(undefined).build(); + + expect(mail.header.to).toEqual([]); + }); + }); + + describe('cc field', function() { + it('adds a single address', function() { + var mail = mailBuilder.newMail().cc('foo@bar.com').build(); + + expect(mail.header.cc).toContain('foo@bar.com'); + }); + + it('adds multiple addresses', function() { + var mail = mailBuilder.newMail().cc('foo@bar.com bar@foo.com').build(); + + expect(mail.header.cc).toContain('foo@bar.com'); + expect(mail.header.cc).toContain('bar@foo.com'); + }); + + it('accepts undefined without breaking', function() { + var mail = mailBuilder.newMail().cc(undefined).build(); + + expect(mail.header.cc).toEqual([]); + }); + }); + + describe('bcc field', function() { + it('adds a single address', function() { + var mail = mailBuilder.newMail().bcc('foo@bar.com').build(); + + expect(mail.header.bcc).toContain('foo@bar.com'); + }); + + it('adds multiple addresses', function() { + var mail = mailBuilder.newMail().bcc('foo@bar.com bar@foo.com').build(); + + expect(mail.header.bcc).toContain('foo@bar.com'); + expect(mail.header.bcc).toContain('bar@foo.com'); + }); + + it('accepts undefined without breaking', function() { + var mail = mailBuilder.newMail().bcc(undefined).build(); + + expect(mail.header.bcc).toEqual([]); + }); + }); + + it('adds arbitrary headers', function() { + var mail = mailBuilder.newMail() + .header('Reply-To', 'something') + .header('In-Reply-To', '12345') + .build(); + + expect(mail.header['Reply-To']).toBe('something'); + expect(mail.header['In-Reply-To']).toBe('12345'); + }); + + it('adds tag', function() { + var mail = mailBuilder.newMail() + .tag('tag1') + .build(); + + expect(mail.tags).toContain('tag1'); + }); + }); +}); diff --git a/web-ui/test/spec/mail_view/data/mail_sender.spec.js b/web-ui/test/spec/mail_view/data/mail_sender.spec.js new file mode 100644 index 00000000..3bdc1934 --- /dev/null +++ b/web-ui/test/spec/mail_view/data/mail_sender.spec.js @@ -0,0 +1,70 @@ +/*global Smail */ + +describeComponent('mail_view/data/mail_sender', function () { + 'use strict'; + + var mailBuilder; + var mail; + + beforeEach(function () { + mailBuilder = require('mail_view/data/mail_builder'); + mail = Smail.testData().parsedMail.simpleTextPlain; + setupComponent(); + }); + + it('sends mail data with a POST to the server when asked to send email', function() { + var mailSentEventSpy = spyOnEvent(document, Smail.events.mail.sent); + var g; + + spyOn($, 'ajax').andReturn({done: function(f) { g = f; return {fail: function(){}};}}); + + this.component.trigger(Smail.events.mail.send, mail); + + g(); + + expect(mailSentEventSpy).toHaveBeenTriggeredOn(document); + + expect($.ajax.mostRecentCall.args[0]).toEqual('/mails'); + expect($.ajax.mostRecentCall.args[1].type).toEqual('POST'); + expect(JSON.parse($.ajax.mostRecentCall.args[1].data).header).toEqual(mail.header); + expect(JSON.parse($.ajax.mostRecentCall.args[1].data).body).toEqual(mail.body); + }); + + it('save draft data with a POST to the server when asked to save draft for the first time', function() { + var draftSavedEventSpy = spyOnEvent(document, Smail.events.mail.draftSaved); + var g; + + spyOn($, 'ajax').andReturn({done: function(f) { g = f; return {fail: function(){}};}}); + + mail.ident = ''; + this.component.trigger(Smail.events.mail.saveDraft, mail); + + g(); + + expect(draftSavedEventSpy).toHaveBeenTriggeredOn(document); + + expect($.ajax.mostRecentCall.args[0]).toEqual('/mails'); + expect($.ajax.mostRecentCall.args[1].type).toEqual('POST'); + expect(JSON.parse($.ajax.mostRecentCall.args[1].data).header).toEqual(mail.header); + expect(JSON.parse($.ajax.mostRecentCall.args[1].data).body).toEqual(mail.body); + }); + + it('save draft data with a PUT to the server when asked to save draft for the second time', function() { + var draftSavedEventSpy = spyOnEvent(document, Smail.events.mail.draftSaved); + var g; + + spyOn($, 'ajax').andReturn({done: function(f) { g = f; return {fail: function(){}};}}); + + mail.ident = 0; + this.component.trigger(Smail.events.mail.saveDraft, mail); + + g(); + + expect(draftSavedEventSpy).toHaveBeenTriggeredOn(document); + + expect($.ajax.mostRecentCall.args[0]).toEqual('/mails'); + expect($.ajax.mostRecentCall.args[1].type).toEqual('PUT'); + expect(JSON.parse($.ajax.mostRecentCall.args[1].data).header).toEqual(mail.header); + expect(JSON.parse($.ajax.mostRecentCall.args[1].data).body).toEqual(mail.body); + }); +}); |