diff options
Diffstat (limited to 'web-ui/test/spec/mail_view/data/mail_builder.spec.js')
-rw-r--r-- | web-ui/test/spec/mail_view/data/mail_builder.spec.js | 110 |
1 files changed, 110 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'); + }); + }); +}); |