From 21b025f80e8fc4168a9717cf691114a0b5154baf Mon Sep 17 00:00:00 2001
From: Duda Dornelles <ddornell@thoughtworks.com>
Date: Thu, 9 Oct 2014 10:49:08 +0200
Subject: Fixing bug where the send button would get disabled at times even if
 there were valid receipients

---
 .../test/spec/mixins/with_mail_edit_base.spec.js   | 27 +++++-----------------
 web-ui/test/spec/services/model/mail.spec.js       |  3 ++-
 web-ui/test/test_data.js                           | 10 ++++----
 3 files changed, 14 insertions(+), 26 deletions(-)

(limited to 'web-ui/test')

diff --git a/web-ui/test/spec/mixins/with_mail_edit_base.spec.js b/web-ui/test/spec/mixins/with_mail_edit_base.spec.js
index 10b7d04c..f62c1f75 100644
--- a/web-ui/test/spec/mixins/with_mail_edit_base.spec.js
+++ b/web-ui/test/spec/mixins/with_mail_edit_base.spec.js
@@ -15,33 +15,18 @@ describeMixin('mixins/with_mail_edit_base', function () {
   });
 
   describe('initialization', function() {
-    it('should enable send button when rendering with recipients', function() {
-      var enableSendButtonEvent = spyOnEvent(document, Pixelated.events.ui.sendbutton.enable);
-      this.component.render(function() {}, {
-        recipients: { to: ['foobar@mail.com'], cc: [] }
-      });
-      expect(enableSendButtonEvent).toHaveBeenTriggeredOn(document);
 
-      enableSendButtonEvent = spyOnEvent(document, Pixelated.events.ui.sendbutton.enable);
-      this.component.render(function() {}, {
-        recipients: { to: ['foobar@mail.com'], cc: undefined }
-      });
-      expect(enableSendButtonEvent).toHaveBeenTriggeredOn(document);
-    });
+    it('should warn send button of existing recipients', function () {
+      var recipientsUpdatedEvent = spyOnEvent(document, Pixelated.events.ui.recipients.updated);
 
-    it('should not enable send button when rendering without recipients', function() {
-      var enableSendButtonEvent = spyOnEvent(document, Pixelated.events.ui.sendbutton.enable);
       this.component.render(function() {}, {
-        recipients: { to: [], cc: [] }
+        recipients: { to: ['foobar@mail.com'], cc: [] }
       });
-      expect(enableSendButtonEvent).not.toHaveBeenTriggeredOn(document);
 
-      enableSendButtonEvent = spyOnEvent(document, Pixelated.events.ui.sendbutton.enable);
-      this.component.render(function() {}, {
-        recipients: { to: undefined, cc: undefined }
-      });
-      expect(enableSendButtonEvent).not.toHaveBeenTriggeredOn(document);
+      expect(recipientsUpdatedEvent).toHaveBeenTriggeredOnAndWith(document, { newRecipients: ['foobar@mail.com'], name: 'to'});
+      expect(recipientsUpdatedEvent).not.toHaveBeenTriggeredOnAndWith(document, { newRecipients: [], name: 'cc'});
     });
+
   });
 
   describe('when the user is typing in subject or body', function() {
diff --git a/web-ui/test/spec/services/model/mail.spec.js b/web-ui/test/spec/services/model/mail.spec.js
index 9b5f71c6..24a8d244 100644
--- a/web-ui/test/spec/services/model/mail.spec.js
+++ b/web-ui/test/spec/services/model/mail.spec.js
@@ -9,7 +9,8 @@ require(['services/model/mail'], function (Mail) {
       it('returns the "to" and "cc" addresses if the mail was sent', function () {
         var mail = Mail.create({
           header: { to: ['a@b.c', 'e@f.g'], cc: ['x@x.x'] },
-          tags: ['sent']
+          tags: [],
+          mailbox: 'SENT'
         });
 
         var addresses = mail.replyToAddress();
diff --git a/web-ui/test/test_data.js b/web-ui/test/test_data.js
index c32bc65f..bf3626bb 100644
--- a/web-ui/test/test_data.js
+++ b/web-ui/test/test_data.js
@@ -22,17 +22,19 @@ define(function() {
   var rawSentMail = {
     'header':{'to':'mariane_dach@davis.info', 'cc': 'duda@la.lu', 'from':'afton_braun@botsford.biz','subject':'Consectetur sit omnis veniam blanditiis.','date':'2014-06-17T11:56:53-03:00'},
     'ident':9359,
-    'tags':['sent','photography','sky'],
+    'tags':['photography','sky'],
     'status':['read'],
-    'body':'Illum eos nihil commodi voluptas. Velit consequatur odio quibusdam. Beatae aliquam hic quos.'
+    'body':'Illum eos nihil commodi voluptas. Velit consequatur odio quibusdam. Beatae aliquam hic quos.',
+    'mailbox': 'SENT'
   };
 
   var rawDraftMail = {
     'header':{'to':'mariane_dach@davis.info','from':'afton_braun@botsford.biz','subject':'Consectetur sit omnis veniam blanditiis.','date':'2014-06-17T11:56:53-03:00'},
     'ident':9360,
-    'tags':['drafts','photography','sky'],
+    'tags':['photography','sky'],
     'status':['read'],
-    'body':'Illum eos nihil commodi voluptas. Velit consequatur odio quibusdam. Beatae aliquam hic quos.'
+    'body':'Illum eos nihil commodi voluptas. Velit consequatur odio quibusdam. Beatae aliquam hic quos.',
+    'mailbox': 'DRAFTS'
   };
 
   var rawRecievedMail = {
-- 
cgit v1.2.3