summaryrefslogtreecommitdiff
path: root/web-ui/test/spec/mail_view/ui/compose_box.spec.js
blob: 8e07481a378eb5ada768c3af13c719d5cd5317d8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
describeComponent('mail_view/ui/compose_box', function () {
  'use strict';
  beforeEach(function () {
    Pixelated.mockBloodhound();
    this.setupComponent('<div style="display:none"></div>');
  });


  describe('compose new mail', function() {

    it('only sends if all the recipients are valid emails', function() {
      $(document).trigger(Pixelated.events.ui.recipients.updated, {recipientsName: 'to', newRecipients: ['valid@email.example']});

      var eventSpy = spyOnEvent(document, Pixelated.events.mail.send);

      $(document).trigger(Pixelated.events.ui.mail.send);

      expect(eventSpy).toHaveBeenTriggeredOn(document);
    });

    it('sends the recipient entered', function () {
      $(document).trigger(Pixelated.events.ui.recipients.updated, {recipientsName: 'to', newRecipients: ['fox@somewhere.com']});

      var eventSpy = spyOnEvent(document, Pixelated.events.mail.send);

      $(document).trigger(Pixelated.events.ui.mail.send);

      expect(eventSpy).toHaveBeenTriggeredOn(document);
      expect(eventSpy.mostRecentCall.data.header).toEqual(jasmine.objectContaining({
        to: ['fox@somewhere.com']
      }));
    });

    it('sends the multiple recipients entered', function () {
      $(document).trigger(Pixelated.events.ui.recipients.updated, {recipientsName: 'to', newRecipients: ['fox@somewhere.com', 'blarg@someone.com', 'fox2@google.se']});
      var eventSpy = spyOnEvent(document, Pixelated.events.mail.send);

      $(document).trigger(Pixelated.events.ui.mail.send);

      expect(eventSpy).toHaveBeenTriggeredOn(document);
      expect(eventSpy.mostRecentCall.data.header).toEqual(jasmine.objectContaining({
        to: ['fox@somewhere.com', 'blarg@someone.com', 'fox2@google.se']
      }));
    });

    it('sends the subject line entered', function () {
      $(document).trigger(Pixelated.events.ui.recipients.updated, {recipientsName: 'to', newRecipients: ['aa@aa.com']});
      this.component.select('subjectBox').val('A new fancy subject!');
      var eventSpy = spyOnEvent(document, Pixelated.events.mail.send);

      $(document).trigger(Pixelated.events.ui.mail.send);

      expect(eventSpy).toHaveBeenTriggeredOn(document);
      expect(eventSpy.mostRecentCall.data.header).toEqual(jasmine.objectContaining({
        subject: 'A new fancy subject!'
      }));
    });

    it('sends the multiple CCs entered', function () {
      $(document).trigger(Pixelated.events.ui.recipients.updated, {recipientsName: 'cc', newRecipients: ['cc1@foo.bar', 'cc2@bar.foo', 'cc3@zz.top']});
      var eventSpy = spyOnEvent(document, Pixelated.events.mail.send);

      $(document).trigger(Pixelated.events.ui.mail.send);

      expect(eventSpy).toHaveBeenTriggeredOn(document);
      expect(eventSpy.mostRecentCall.data.header).toEqual(jasmine.objectContaining({
        cc: ['cc1@foo.bar', 'cc2@bar.foo', 'cc3@zz.top']
      }));
    });

    it('sends the multiple BCCs entered', function () {
      $(document).trigger(Pixelated.events.ui.recipients.updated, {recipientsName: 'bcc', newRecipients: ['bcc1@foo.bar', 'bcc2@bar.foo', 'bcc3@zz.top']});
      var eventSpy = spyOnEvent(document, Pixelated.events.mail.send);

      $(document).trigger(Pixelated.events.ui.mail.send);

      expect(eventSpy).toHaveBeenTriggeredOn(document);
      expect(eventSpy.mostRecentCall.data.header).toEqual(jasmine.objectContaining({
        bcc: ['bcc1@foo.bar', 'bcc2@bar.foo', 'bcc3@zz.top']
      }));
    });

    it('shows no message selected pane when deleting the email being composed', function() {
      var openNoMessageSelectedPaneEvent = spyOnEvent(document, Pixelated.events.dispatchers.rightPane.openNoMessageSelected);
      var mails = [{ident: 123}];
      this.component.attr.ident = 123;

      this.component.trigger(document, Pixelated.events.mail.deleted, {mails: mails});

      expect(openNoMessageSelectedPaneEvent).toHaveBeenTriggeredOn(document);
    });

    it('does not show no message selected pane when deleting a different set of emails', function() {
      var openNoMessageSelectedPaneEvent = spyOnEvent(document, Pixelated.events.dispatchers.rightPane.openNoMessageSelected);
      var mails = [{ident: 321}];
      this.component.attr.ident = 123;

      this.component.trigger(document, Pixelated.events.mail.deleted, {mails: mails});

      expect(openNoMessageSelectedPaneEvent).not.toHaveBeenTriggeredOn(document);
    });

    it('should call the enableFloatlabel method when events.mail.here is trigged', function() {
      spyOn(this.component, 'enableFloatlabel');

      this.component.renderComposeBox();

      expect(this.component.enableFloatlabel).toHaveBeenCalledWith('input.floatlabel');
      expect(this.component.enableFloatlabel).toHaveBeenCalledWith('textarea.floatlabel');
    });
  });

  describe('close button behavior', function() {

    it('should fire Show no message selected if the close button is clicked', function() {
      var spy = spyOnEvent(document, Pixelated.events.dispatchers.rightPane.openNoMessageSelected);
      this.component.select('closeButton').click();
      expect(spy).toHaveBeenTriggeredOn(document);
    });

  });

  describe('draft compose box', function() {
    it('should save a draft when click on draft button', function () {
      $(document).trigger(Pixelated.events.ui.recipients.updated, {recipientsName: 'to', newRecipients: ['fox@somewhere.com']});

      this.component.select('subjectBox').val('A new fancy subject!');
      var eventSpy = spyOnEvent(document, Pixelated.events.mail.saveDraft);

      this.component.select('draftButton').click();

      expect(eventSpy).toHaveBeenTriggeredOn(document);
      expect(eventSpy.mostRecentCall.data.header).toEqual(jasmine.objectContaining({
        to: ['fox@somewhere.com']
      }));
    });
  });

  describe('subject label', function() {
    var input;
    var label;

    beforeEach(function() {
      input = $(this.component.$node).find('input');
      label = input.prev('label');

      this.component.enableFloatlabel(input);
    });

    it('should show the subject label after the user starts typing', function() {
      input.val('test');
      input.trigger('keyup');

      expect(input.hasClass('showfloatlabel')).toEqual(true);
      expect(label.hasClass('showfloatlabel')).toEqual(true);
    });

    it('should not show the subject label if the field is empty', function() {
      input.val('');
      input.trigger('keyup');

      expect(input.hasClass('showfloatlabel')).toEqual(false);
      expect(label.hasClass('showfloatlabel')).toEqual(false);
    });
  });

  describe('body label', function() {
    var textarea;
    var label;

    beforeEach(function() {
      textarea = $(this.component.$node).find('textarea');
      label = textarea.prev('label');

      this.component.enableFloatlabel(textarea);
    });

    it('should show the subject label after the user starts typing', function() {
      textarea.text('test');
      textarea.trigger('keyup');

      expect(textarea.hasClass('showfloatlabel')).toEqual(true);
      expect(label.hasClass('showfloatlabel')).toEqual(true);
    });

    it('should not show the subject label if the field is empty', function() {
      textarea.text('');
      textarea.trigger('keyup');

      expect(textarea.hasClass('showfloatlabel')).toEqual(false);
      expect(label.hasClass('showfloatlabel')).toEqual(false);
    });
  });
});