summaryrefslogtreecommitdiff
path: root/web-ui/test/spec/mail_view/ui/reply_box.spec.js
blob: 9542f37acbb68d58a7cdaa9127895d732bea29b8 (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
describeComponent('mail_view/ui/reply_box', function () {
  'use strict';

  var attrs, i18n;
  beforeEach(function () {
    attrs = {
      mail: Pixelated.testData().parsedMail.simpleTextPlain
    };
    this.setupComponent(attrs);
    i18n = require('views/i18n');
    spyOn($, 'getJSON').and.returnValue($.Deferred());
  });

  describe('reply compose box', function() {
    it('should display subject of the reply', function() {
      expect(this.component.select('subjectDisplay').text()).toBe(i18n('Re: ') + attrs.mail.header.subject);
    });

    it('should show recipient fields when clicking on recipient display', function() {
      this.component.select('recipientsDisplay').click();

      expect(this.component.select('recipientsFields')).not.toBeHidden();
      expect(this.component.select('recipientsDisplay')).toBeHidden();
    });

    it('should show subject field when clicking on subject display', function() {
      this.component.select('subjectDisplay').click();

      expect(this.component.select('subjectInput')).not.toBeHidden();
      expect(this.component.select('subjectDisplay')).toBeHidden();
    });

    it('should use the from field when Reply-To header does not exist', function() {
      attrs.mail.header.reply_to = undefined;

      this.setupComponent(attrs);

      expect(this.component.attr.recipientValues.to).toEqual([attrs.mail.header.from]);
    });

    it('should have a subject of Re: <original_message>', function() {
      attrs.mail.header.subject = 'Very interesting';

      this.setupComponent(attrs);

      expect(this.component.select('subjectDisplay').text()).toEqual(i18n('Re: ')+ attrs.mail.header.subject);
    });

    it('should use set In-Reply-To header when Message-Id header is set', function() {
      var mailSendEvent = spyOnEvent(document, Pixelated.events.mail.send);

      attrs.mail.header.message_id = '12345';
      this.setupComponent(attrs);

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

      expect(mailSendEvent).toHaveBeenTriggeredOn(document);
      expect(mailSendEvent.mostRecentCall.data.header).toEqual(jasmine.objectContaining({
        in_reply_to: '12345'
      }));
    });

    it('keeps the List-Id header when it exists', function() {
      var mailSendEvent = spyOnEvent(document, Pixelated.events.mail.send);
      attrs.mail.header.list_id = 'somelist';

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

      expect(mailSendEvent.mostRecentCall.data.header).toEqual(jasmine.objectContaining({
        list_id: 'somelist'
      }));
    });

    it('populates body text area with quote of email being replied', function() {
      var viewHelper = require('helpers/view_helper');
      spyOn(viewHelper, 'quoteMail').and.returnValue('quoted email');

      this.setupComponent(attrs);

      expect(viewHelper.quoteMail).toHaveBeenCalledWith(attrs.mail);
      expect(this.component.select('bodyBox').val()).toBe('quoted email');
    });

    it('triggers mail when cancelling a reply', function () {
      var mailSaveEvent = spyOnEvent(document, Pixelated.events.mail.save);

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

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

    it('reopens the mail after the reply is sent', function () {
      var mailOpenEvent = spyOnEvent(document, Pixelated.events.ui.mail.open);

      this.component.trigger(document, Pixelated.events.mail.sent);

      expect(mailOpenEvent).toHaveBeenTriggeredOnAndWith(document, {
        ident: this.component.attr.mail.ident
      });
    });
  });
});