summaryrefslogtreecommitdiff
path: root/web-ui/test/spec/mail_view/ui/send_button.spec.js
blob: 579ce4a3db620e5516ce13370daccd2d07f06468 (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
describeComponent('mail_view/ui/send_button', function () {

  describe('send button', function () {
    beforeEach(function () {
      setupComponent('<button />');
    });

    describe('when it is disabled', function () {
      beforeEach(function () {
        this.$node.prop('disabled', true);
      });

      it('gets enabled in a inputHasMail event', function () {
        $(document).trigger(Pixelated.events.ui.recipients.inputHasMail, { name: 'to' });

        expect(this.$node).not.toBeDisabled();
      });

      it('gets enabled in a recipients:updated where there are new recipients', function () {
        $(document).trigger(Pixelated.events.ui.recipients.updated, { newRecipients: ['a@b.c']});

        expect(this.$node).not.toBeDisabled();
      });
    });

    describe('multiple events', function () {
      it('gets enabled and remains enabled when a inputHasMail is followed by a recipients:updated with NO new recipients', function () {
        this.$node.prop('disabled', true);

        $(document).trigger(Pixelated.events.ui.recipients.inputHasMail, { name: 'to' });
        $(document).trigger(Pixelated.events.ui.recipients.updated, { newRecipients: [] });

        expect(this.$node).not.toBeDisabled();
      });

      it('gets enabled and remains enabled when a recipients:updated with recipients is followed by a inputHasNoMail', function () {
        this.$node.prop('disabled', true);

        $(document).trigger(Pixelated.events.ui.recipients.updated, { newRecipients: ['a@b.c']});
        $(document).trigger(Pixelated.events.ui.recipients.inputHasNoMail, { name: 'to' });

        expect(this.$node).not.toBeDisabled();
      });
    });

    describe('when it is enabled', function () {
      beforeEach(function () {
        this.$node.prop('disabled', false);
      });

      it('gets disabled in a inputHasNoMail', function () {
        $(document).trigger(Pixelated.events.ui.recipients.inputHasNoMail, { name: 'to' });

        expect(this.$node).toBeDisabled();
      });

      it('gets disabled in a recipients:updated without new recipients', function () {
        $(document).trigger(Pixelated.events.ui.recipients.updated, { newRecipients: []});

        expect(this.$node).toBeDisabled();
      });
    });

    describe('on click', function () {

      it ('asks for the recipients input to complete its current input', function () {
        var doCompleteInputEvent = spyOnEvent(document, Pixelated.events.ui.recipients.doCompleteInput);

        this.$node.click();

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

    describe('after clicking', function () {
      beforeEach(function () {
        this.$node.click();
      });

      it('waits for ui:mail:recipientsUpdated to happen 3 times in the mail then sends the mail then stops listening to ui:mail:recipientsUpdated', function () {
        var sendMailEvent = spyOnEvent(document, Pixelated.events.ui.mail.send);
        spyOn(this.component, 'off');

        _.times(3, function () { $(document).trigger(Pixelated.events.ui.mail.recipientsUpdated) });;

        expect(sendMailEvent).toHaveBeenTriggeredOn(document);
        expect(this.component.off).toHaveBeenCalledWith(document, Pixelated.events.ui.mail.recipientsUpdated);
      });
    });
  });
});