summaryrefslogtreecommitdiff
path: root/web-ui/test/spec/dispatchers/left_pane_dispatcher.spec.js
blob: fb5b169aa6996727495e1405a938939916d2e87c (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
/*global Smail */

describeComponent('dispatchers/left_pane_dispatcher', function () {
  'use strict';

  describe('initialize', function () {
    it('asks for tags', function () {
      var tagWantEvent = spyOnEvent(document, Smail.events.tags.want);

      setupComponent();

      expect(tagWantEvent).toHaveBeenTriggeredOn(document);
      expect(tagWantEvent.mostRecentCall.data.caller[0]).toEqual(this.$node[0]);
    });
  });

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

    it('pushes the url state when a tag is selected but not for the first tag', function () {
      var pushStateEvent = spyOnEvent(document, Smail.events.router.pushState);

      $(document).trigger(Smail.events.ui.tag.selected, { tag: 'Drafts'});
      $(document).trigger(Smail.events.ui.tag.selected, { tag: 'inbox'});

      expect(pushStateEvent).toHaveBeenTriggeredOn(document, { tag: 'inbox'});
    });

    it('fetches mails by tag when a tag is selected', function () {
      var fetchByTagEvent = spyOnEvent(document, Smail.events.ui.mails.fetchByTag);

      $(document).trigger(Smail.events.ui.tag.selected, { tag: 'Drafts'});

      expect(fetchByTagEvent).toHaveBeenTriggeredOn(document, { tag: 'Drafts'});
    });

    it('doesnt fetch mails by tag when skipMailListRefresh is sent on tag.selected', function () {
      var fetchByTagEvent = spyOnEvent(document, Smail.events.ui.mails.fetchByTag);

      $(document).trigger(Smail.events.ui.tag.selected, { tag: 'Drafts', skipMailListRefresh: true});

      expect(fetchByTagEvent).not.toHaveBeenTriggeredOn(document, { tag: 'Drafts'});
    });

    it('asks for more tags when refreshTagList is fired', function () {
      var tagWantEvent = spyOnEvent(document, Smail.events.tags.want);

      $(document).trigger(Smail.events.dispatchers.tags.refreshTagList);

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

    it('fires tagLoad when the tags are received', function () {
      var tagListLoadEvent = spyOnEvent(document, Smail.events.ui.tagList.load);

      this.$node.trigger(Smail.events.tags.received, { tags: ['tags']});

      expect(tagListLoadEvent).toHaveBeenTriggeredOn(document, { tags: ['tags']});
    });

    it('on tags loaded selects the inbox tag if no data is provided', function () {
      var selectTagEvent = spyOnEvent(document, Smail.events.ui.tag.select);

      $(document).trigger(Smail.events.ui.tags.loaded);

      expect(selectTagEvent).toHaveBeenTriggeredOnAndWith(document, { tag: 'inbox' });
    });

    it('on tags loaded selects the a different tag if tag is provided', function () {
      var selectTagEvent = spyOnEvent(document, Smail.events.ui.tag.select);

      $(document).trigger(Smail.events.ui.tags.loaded, { tag: 'Drafts' });

      expect(selectTagEvent).toHaveBeenTriggeredOnAndWith(document, { tag: 'Drafts' });
    });
  });
});