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

  describe('after initialization', function () {
    beforeEach(function () {
      this.setupComponent();
    });

    it('listens to open compose box event and creates a compose box', function () {
      var composeBox = require('mail_view/ui/compose_box');
      spyOn(composeBox, 'attachTo');

      this.component.trigger(document, Pixelated.events.dispatchers.rightPane.openComposeBox);

      expect(composeBox.attachTo).toHaveBeenCalled();
    });

    describe('no message selected', function () {
      var noMessageSelectedPane;
      beforeEach(function () {
        noMessageSelectedPane = require('mail_view/ui/no_message_selected_pane');
        spyOn(noMessageSelectedPane, 'attachTo');
      });

      it('listen to open no message selected event and creates a no-message-selected-pane', function () {
        this.component.trigger(document, Pixelated.events.dispatchers.rightPane.openNoMessageSelected);

        expect(noMessageSelectedPane.attachTo).toHaveBeenCalled();
      });

      it('sends an dispatchers.middlePane.unselect event', function () {
        var unselectEvent = spyOnEvent(document, Pixelated.events.dispatchers.middlePane.cleanSelected);
        this.component.trigger(document, Pixelated.events.dispatchers.rightPane.openNoMessageSelected);

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

      it('pushes the current state with the current tag', function () {
        var pushStateEvent = spyOnEvent(document, Pixelated.events.router.pushState);

        this.component.attr.currentTag = 'sometag';
        this.component.trigger(document, Pixelated.events.dispatchers.rightPane.openNoMessageSelected);

        expect(pushStateEvent).toHaveBeenTriggeredOnAndWith(document, jasmine.objectContaining({tag: this.component.attr.currentTag }));
      });

      it('pushes the current state stating that it meant to close the right pane', function () {
        var pushStateEvent = spyOnEvent(document, Pixelated.events.router.pushState);

        this.component.attr.currentTag = 'sometag';
        this.component.trigger(document, Pixelated.events.dispatchers.rightPane.openNoMessageSelected);

        expect(pushStateEvent).toHaveBeenTriggeredOnAndWith(document, jasmine.objectContaining({ isDisplayNoMessageSelected:  true }));
      });

      it('listens to open feedback event and open feedback box', function () {
        var feedbackBox = require('mail_view/ui/feedback_box');
        spyOn(feedbackBox, 'attachTo');

        this.component.trigger(document, Pixelated.events.dispatchers.rightPane.openFeedbackBox);

        expect(feedbackBox.attachTo).toHaveBeenCalled();
      });

    });

    it('listens to open a draft and creates it', function () {
      var draftBox = require('mail_view/ui/draft_box');
      spyOn(draftBox, 'attachTo');

      this.component.trigger(document, Pixelated.events.dispatchers.rightPane.openDraft, { ident: '1' });

      expect(draftBox.attachTo).toHaveBeenCalled();
    });
  });


  describe('on initialization', function () {
    var noMessageSelectedPane;

    beforeEach(function () {
      noMessageSelectedPane = require('mail_view/ui/no_message_selected_pane');
      spyOn(noMessageSelectedPane, 'attachTo');
    });

    it('opens the no message selected pane but doesnt push the state', function () {
      var pushStateEvent = spyOnEvent(document, Pixelated.events.router.pushState);

      this.setupComponent();

      expect(noMessageSelectedPane.attachTo).toHaveBeenCalled();
      expect(pushStateEvent).not.toHaveBeenTriggeredOn(document);

    });
  });

  describe('on message selected', function () {
    beforeEach(function () {
      this.setupComponent();
    });

    it('addSpinner renders the spinner to the page', function () {
      var spinner = require('mail_view/ui/spinner');
      spyOn(spinner, 'attachTo');
      var stage = {stage: 'mail-view'};
      this.component.addSpinner(stage);

      expect(spinner.attachTo).toHaveBeenCalledWith(stage);
    });

    it('should show the spinner when opening a mail message', function () {
      spyOn(this.component, 'addSpinner');
      this.component.trigger(document, Pixelated.events.ui.mail.open, { ident: '1' });

      expect(this.component.addSpinner).toHaveBeenCalled();
    });

    it('should show the spinner when opening a draft message', function () {
      spyOn(this.component, 'addSpinner');
      this.component.trigger(document, Pixelated.events.dispatchers.rightPane.openDraft, { ident: '1' });

      expect(this.component.addSpinner).toHaveBeenCalled();
    });
  });
});