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

  beforeEach(function() {
    this.setupComponent('<div><div id="middle-pane" style="height: 200px; overflow-y: scroll;"><div style="height: 400px"></div></div></div>');
  });

  it ('listens to refresh mail list event', function() {
    var mailsListRefreshEventSpy = spyOnEvent(document, Pixelated.events.ui.mails.fetchByTag);
    this.component.trigger(document, Pixelated.events.dispatchers.middlePane.refreshMailList);
    expect(mailsListRefreshEventSpy).toHaveBeenTriggeredOn(document);
  });

  it ('listens to unselect event', function() {
    var mailListUnselectEvent = spyOnEvent(document, Pixelated.events.ui.mails.cleanSelected);
    this.component.trigger(document, Pixelated.events.dispatchers.middlePane.cleanSelected);
    expect(mailListUnselectEvent).toHaveBeenTriggeredOn(document);
  });

  it('resets the scrollTop value when asked to', function() {
    this.component.select('middlePane').scrollTop(200);
    this.component.trigger(document, Pixelated.events.dispatchers.middlePane.resetScroll);
    expect(this.component.select('middlePane').scrollTop()).toEqual(0);
  });

  describe('no emails available', function () {
    var noMailsAvailablePane, attachToSpy;
    beforeEach(function () {
      noMailsAvailablePane = require('mail_view/ui/no_mails_available_pane');
      attachToSpy = spyOn(noMailsAvailablePane, 'attachTo');
      spyOn(noMailsAvailablePane, 'teardownAll');
    });

    it('should listen to mails available event and show noMailsAvailablePane', function () {
        var mail_list = { mails: []};
        this.component.trigger(document, Pixelated.events.mails.available, mail_list);

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

    it('should listen to mails available event and do not show noMailsAvailablePane', function () {
        var pretend_to_be_a_mail = {};
        var mail_list = { mails: [pretend_to_be_a_mail]};
        this.component.trigger(document, Pixelated.events.mails.available, mail_list);

        expect(noMailsAvailablePane.attachTo).not.toHaveBeenCalled();
        expect(noMailsAvailablePane.teardownAll).toHaveBeenCalled();
    });

    it('should give search information to component', function () {
        var mail_list = { mails: [], tag: 'all', forSearch: 'search'};
        this.component.trigger(document, Pixelated.events.mails.available, mail_list);
 
        expect(attachToSpy.calls.mostRecent().args[1]).toEqual({tag: 'all', forSearch: 'search'});
    });
  });
});