summaryrefslogtreecommitdiff
path: root/web-ui/test/spec/mail_view/ui/compose_box.spec.js
blob: 414bc022f5799ccfe2fe8fc0ba8ba73391708c13 (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
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);
    });
  });

  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']
      }));
    });
  });
});