summaryrefslogtreecommitdiff
path: root/web-ui/test/spec/mail_view/ui/reply_section.spec.js
blob: e5571e2ca7c33bd1c6cc5392dbd196a778766400 (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
/*global jasmine */
/*global Smail */

describeComponent('mail_view/ui/reply_section', function () {
  'use strict';

  beforeEach(function () {
    setupComponent();
  });

  describe('clicking reply buttons', function() {
    var mailWantEvent, expectEventData;

    beforeEach(function () {
      mailWantEvent = spyOnEvent(document, Smail.events.mail.want);
      expectEventData = {
        mail: '12345',
        caller: this.component
      };
      this.component.attr.ident = '12345';
    });

    it('should ask for email when clicking on reply button', function() {
      this.component.select('replyButton').click();

      expect(mailWantEvent).toHaveBeenTriggeredOnAndWith(document, expectEventData);
    });

    it('should ask for email when clicking on replyAll button', function() {
      this.component.select('replyAllButton').click();

      expect(mailWantEvent).toHaveBeenTriggeredOnAndWith(document, expectEventData);
    });
  });

  describe('creating reply box when getting email back', function() {
    var mailData, ReplyBox, ForwardBox;

    beforeEach(function () {
      mailData = Smail.testData().mail;
      ReplyBox = require('mail_view/ui/reply_box');
      ForwardBox = require('mail_view/ui/forward_box');
      spyOn(ReplyBox, 'attachTo');
      spyOn(ForwardBox, 'attachTo');
    });

    it('for normal reply', function() {
      this.component.attr.replyType = 'reply';
      this.component.trigger(this.component, Smail.events.mail.here, { mail: mailData });

      expect(ReplyBox.attachTo).toHaveBeenCalledWith(jasmine.any(Object), {
        mail: mailData,
        replyType: 'reply'
      });
    });

    it('for reply to all', function() {
      this.component.attr.replyType = 'replyall';
      this.component.trigger(this.component, Smail.events.mail.here, { mail: mailData });

      expect(ReplyBox.attachTo).toHaveBeenCalledWith(jasmine.any(Object), {
        mail: mailData,
        replyType: 'replyall'
      });
    });

    it('creates a forward box', function() {
      this.component.attr.replyType = 'forward';
      this.component.trigger(this.component, Smail.events.mail.here, { mail: mailData });

      expect(ForwardBox.attachTo).toHaveBeenCalledWith(jasmine.any(Object), {
        mail: mailData
      });
    });
  });

  it('hides the buttons when clicked', function() {
    this.component.attr.mailIdent = 12345;

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

    expect(this.component.select('replyButton')).toBeHidden();
    expect(this.component.select('replyAllButton')).toBeHidden();
    expect(this.component.select('forwardButton')).toBeHidden();
  });

  it('shows the buttons when reply is cancelled', function() {
    this.component.attr.mailIdent = 12345;
    this.component.select('replyButton').click();

    $(document).trigger(Smail.events.ui.composeBox.trashReply);

    expect(this.component.select('replyButton')).not.toBeHidden();
    expect(this.component.select('replyAllButton')).not.toBeHidden();
    expect(this.component.select('forwardButton')).not.toBeHidden();
  });
});