summaryrefslogtreecommitdiff
path: root/web-ui/test/spec/page/unread_count_title.spec.js
blob: e367e5790fe0d4af2f352d757878c567fede4a3b (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

describeComponent('page/unread_count_title', function () {
  'use strict';
  describe('unread count on title bar', function () {

    beforeEach(function () {
      document.title = 'example@pixelated-project.org';
      this.setupComponent();
    });

    it('listens to mails available event', function () {
      this.component.trigger(Pixelated.events.mails.available, {mails: [], tag: 'inbox'});
      expect(this.component.getTitleText()).toEqual('Inbox - example@pixelated-project.org');
    });

    it('only considers unread mails', function () {
      var readMail = {'status': ['read']};
      this.component.trigger(Pixelated.events.mails.available, {mails: [readMail], tag: 'inbox'});
      expect(this.component.getTitleText()).toEqual('Inbox - example@pixelated-project.org');
    });

    it('update for one unread email', function () {
      var mails = [{'status': ['read']}, {'status': []}];
      this.component.trigger(Pixelated.events.mails.available, {mails: mails, tag: 'inbox'});
      expect(this.component.getTitleText()).toEqual('Inbox (1) - example@pixelated-project.org');
    });

    it('update for more than one unread email', function () {
      var mails = [{'status': ['read']}, {'status': []}, {'status': []}];
      this.component.trigger(Pixelated.events.mails.available, {mails: mails, tag: 'inbox'});
      expect(this.component.getTitleText()).toEqual('Inbox (2) - example@pixelated-project.org');
    });

    it('update for more than one unread email', function () {
      var mails = [{'status': ['read']}, {'status': []}, {'status': []}];
      this.component.trigger(Pixelated.events.mails.available, {mails: mails, tag: 'inbox'});
      expect(this.component.getTitleText()).toEqual('Inbox (2) - example@pixelated-project.org');
    });

    it('decreases unread count', function () {
      document.title = 'Inbox (2) - example@pixelated-project.org';
      var mails = [{'status': ['read']}, {'status': ['read']}];
      this.component.trigger(Pixelated.events.mails.available, {mails: mails, tag: 'inbox'});
      expect(this.component.getTitleText()).toEqual('Inbox - example@pixelated-project.org');
    });
  });
});