summaryrefslogtreecommitdiff
path: root/web-ui/test/spec/tags/ui/tag.spec.js
blob: 36fc83f2512f2c39cf2c04b11c6ae85b3556a8a7 (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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
/*global Pixelated */
/*global _ */

describeComponent('tags/ui/tag', function () {
  'use strict';

  describe('inbox tag', function () {
    beforeEach(function () {
      this.setupComponent('<li></li>', {
        tag: {
          name: 'inbox',
          ident: '1',
          counts: {
            total: 100,
            read: 0
          }
        }
      });
    });

    it('selects the tag on click', function () {
      var tagSelectEvent = spyOnEvent(document, Pixelated.events.ui.tag.select);

      this.component.$node.click();

      expect(this.$node.attr('class')).toMatch('selected');
      expect(tagSelectEvent).toHaveBeenTriggeredOnAndWith(document, { tag: 'inbox' });
    });

    it('should remove selected class when selecting a different tag', function () {
      this.$node.click();

      $(document).trigger(Pixelated.events.ui.tag.select, {tag: 'drafts'});

      expect(this.$node).not.toHaveClass('selected');
    });

    it('triggers tag selected on tag select', function () {
      var tagSelectedEvent = spyOnEvent(document, Pixelated.events.ui.tag.select);

      $(document).trigger(Pixelated.events.ui.tag.select, { tag: 'drafts'});

      expect(tagSelectedEvent).toHaveBeenTriggeredOnAndWith(document, { tag: 'drafts'});
    });

    describe('increasing count read when email is read', function () {
      it('doesnt update if mail.tags or mail.mailbox dont match the tag name', function () {
        this.setupComponent('<li></li>', {
          tag: { name: 'sometag', ident: '1', counts: { total: 100, read: 0 } }
        });

        $(document).trigger(Pixelated.events.mail.read, { tags: ['someothertag'], mailbox: 'inbox' });

        expect(this.component.attr.tag.counts.read).toEqual(0);
      });

      it('looks at the mail mailbox attr for default tags', function () {
        $(document).trigger(Pixelated.events.mail.read, { tags: [], mailbox: 'inbox' });

        expect(this.component.attr.tag.counts.read).toEqual(1);
        expect(this.$node.html()).toMatch('<span class="unread-count">99</span>');
      });

      it('looks at the mail tags for non default tags', function () {
        this.setupComponent('<li></li>', {
          tag: { name: 'tag', ident: '1', counts: { total: 100, read: 0 } }
        });

        $(document).trigger(Pixelated.events.mail.read, { tags: ['tag'], mailbox: 'inbox' });

        expect(this.component.attr.tag.counts.read).toEqual(1);
        expect(this.$node.html()).toMatch('<span class="unread-count">99</span>');
      });
    });

    it('re-renders the tag shortcut linked to it when increasing the read count if there is a shortcut', function () {
      this.component.attr.shortcut = jasmine.createSpyObj('shortcut', ['reRender']);

      $(document).trigger(Pixelated.events.mail.read, { tags: ['inbox'] });

      expect(this.component.attr.shortcut.reRender).toHaveBeenCalled();
    });

    it('doesnt increase the read count when the read email doesnt have the tag', function () {
      $(document).trigger(Pixelated.events.mail.read, { tags: ['amazing']});

      expect(this.component.attr.tag.counts.read).toEqual(0);
      expect(this.$node.html()).not.toMatch('<span class="unread-count">99</span>');
    });

    it('doesnt display the unread count when there are no unreads', function () {
      this.component.attr.tag.counts.read = 100;
      $(document).trigger(Pixelated.events.mail.read, { tags: ['inbox']});
      expect(this.$node.html()).not.toMatch('"unread-count"');
    });

    it('should not be selected when a search is performed', function() {
      this.component.trigger(document, Pixelated.events.search.perform);

      expect(this.component.$node).not.toHaveClass('selected');
    });

    it('should not be selected when the search is cleared', function() {
      this.component.trigger(document, Pixelated.events.search.empty);

      expect(this.component.$node).not.toHaveClass('selected');
    });
  });

  describe('drafts tag', function () {
    var containerFordrafts;
    beforeEach(function () {
      this.setupComponent('<li></li>', {
        tag: {
          name: 'drafts',
          ident: '42',
          counts: {
            total: 100,
            read: 50
          }
        }
      });
    });

    it('shows the total count instead of the unread count', function () {
      $(document).trigger(Pixelated.events.mail.read, { tags: ['drafts']});
      expect(this.$node.html()).toMatch('<span class="total-count">100</span>');
      expect(this.$node.html()).not.toMatch('"unread-count"');
    });
  });

  describe('all tag', function () {
    beforeEach(function () {
      this.setupComponent('<li></li>', {
        tag: {
          name: 'all',
          ident: '45',
          counts: {
            total: 100,
            read: 50
          }
        }
      });
    });

    it('adds searching class when user is doing a search', function () {
      $(document).trigger(Pixelated.events.search.perform, {});
      expect(this.$node.attr('class')).toMatch('searching');
    });

    it('removes searching class when user searches for empty string', function () {
      $(document).trigger(Pixelated.events.search.perform, {});
      $(document).trigger(Pixelated.events.search.empty);
      expect(this.$node.attr('class')).not.toMatch('searching');
    });

    it('removes searching class when user clicks in any tag', function () {
      $(document).trigger(Pixelated.events.search.perform, {});
      this.$node.click();
      expect(this.$node.attr('class')).not.toMatch('searching');
    });

    it('should be selected when a search is performed', function() {
      this.component.trigger(document, Pixelated.events.search.perform);

      expect(this.component.$node).toHaveClass('selected');
    });

    it('should be selected when the search is cleared', function() {
      this.component.trigger(document, Pixelated.events.search.empty);

      expect(this.component.$node).toHaveClass('selected');
    });
  });

  _.each(['sent', 'trash'], function (tag_name) {
    describe(tag_name + ' tag', function () {
      beforeEach(function () {
        this.setupComponent('<li></li>', {
          tag: {
            name: tag_name,
            ident: '42',
            counts: {
              total: 100,
              read: 50
            }
          }
        });
      });

      it('doesn\'t display unread count for special folder', function () {
        $(document).trigger(Pixelated.events.mail.read, { tags: [tag_name]});
        expect(this.$node.html()).not.toMatch('unread-count');
      });

      it('doesn\'t display read count for special folder', function () {
        $(document).trigger(Pixelated.events.mail.read, { tags: [tag_name]});
        expect(this.$node.html()).not.toMatch('total-count');
      });
    });
  });
});