summaryrefslogtreecommitdiff
path: root/web-ui/test/spec/mixins/with_mail_edit_base.spec.js
blob: c76bf31d6a380530d363000aa81aac7683157929 (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
/*global Pixelated */
/*global jasmine */
/*global runs */
/*global waits */

describeMixin('mixins/with_mail_edit_base', function () {
  'use strict';

  beforeEach(function () {
    this.setupComponent();
    // Stubing mixing wrongly!!! 'deprecated' while waiting for draft component extraction
    this.component.buildMail = function (tag) {
      return { header: { to: ['a@smth.com'], from: 'b@smth.com', subject: 'Sbject' } };
    };
  });

  describe('initialization', function() {

    it('should warn send button of existing recipients', function () {
      var recipientsUpdatedEvent = spyOnEvent(document, Pixelated.events.ui.recipients.updated);

      this.component.render(function() {}, {
        recipients: { to: ['foobar@mail.com'], cc: [] }
      });

      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() {
    beforeEach(function () {
      this.component.attr.saveDraftInterval = 10;
    });

    it('saves the draft after the save draft interval number of seconds', function(done) {
      var saveDraftSpy = spyOnEvent(document, Pixelated.events.mail.saveDraft);
      this.component.monitorInput();
      expect(saveDraftSpy).not.toHaveBeenTriggeredOn(document);

      setTimeout(function () {
        expect(saveDraftSpy).toHaveBeenTriggeredOn(document);
        done();
      }, 10);
    });

    it('does not save if mail is sent before the save draft interval number of seconds', function(done) {
      var saveDraftSpy = spyOnEvent(document, Pixelated.events.mail.saveDraft);
      this.component.monitorInput();
      this.component.sendMail();

      setTimeout(function () {
        expect(saveDraftSpy).not.toHaveBeenTriggeredOn(document);
        done();
      }, 10);
    });
  });

  describe('when a mail is sent', function () {
    it('displays a message of mail sent', function () {
      var spy = spyOnEvent(document, Pixelated.events.ui.userAlerts.displayMessage);
      this.component.trigger(document, Pixelated.events.mail.sent);
      expect(spy).toHaveBeenTriggeredOn(document);
    });
  });

  describe('when user asks to trash the mail', function() {
    it('triggers mail delete for this mail', function() {
      var spy = spyOnEvent(document, Pixelated.events.mail.save);
      this.component.trashMail();
      expect(spy).toHaveBeenTriggeredOn(document);
    });
  });

  describe('when recipients are updated', function () {
    it('triggers an event to let the send button know that the recipients in the mail are updated', function () {
      var uiMailRecipientsUpdated = spyOnEvent(document, Pixelated.events.ui.mail.recipientsUpdated);

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

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