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

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

  describe('initialize', function () {
    it('asks for tags', function () {
      var tagWantEvent = spyOnEvent(document, Pixelated.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, Pixelated.events.router.pushState);

      $(document).trigger(Pixelated.events.ui.tag.selected, { tag: 'Drafts'});
      $(document).trigger(Pixelated.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, Pixelated.events.ui.mails.fetchByTag);

      $(document).trigger(Pixelated.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, Pixelated.events.ui.mails.fetchByTag);

      $(document).trigger(Pixelated.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, Pixelated.events.tags.want);

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

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

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

      this.$node.trigger(Pixelated.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, Pixelated.events.ui.tag.select);

      $(document).trigger(Pixelated.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, Pixelated.events.ui.tag.select);

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

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