BigW Consortium Gitlab

header_spec.js 1.41 KB
Newer Older
1
/* eslint-disable space-before-function-paren, no-var */
2

3 4
require('~/header');
require('~/lib/utils/text_utility');
Clement Ho committed
5 6 7

(function() {
  describe('Header', function() {
8
    var todosPendingCount = '.todos-count';
9
    var fixtureTemplate = 'issues/open-issue.html.raw';
Clement Ho committed
10 11 12 13 14 15 16 17 18

    function isTodosCountHidden() {
      return $(todosPendingCount).hasClass('hidden');
    }

    function triggerToggle(newCount) {
      $(document).trigger('todo:toggle', newCount);
    }

19
    preloadFixtures(fixtureTemplate);
Clement Ho committed
20
    beforeEach(function() {
21
      loadFixtures(fixtureTemplate);
Clement Ho committed
22 23
    });

24
    it('should update todos-count after receiving the todo:toggle event', function() {
Clement Ho committed
25 26 27 28
      triggerToggle(5);
      expect($(todosPendingCount).text()).toEqual('5');
    });

29
    it('should hide todos-count when it is 0', function() {
Clement Ho committed
30 31 32 33
      triggerToggle(0);
      expect(isTodosCountHidden()).toEqual(true);
    });

34
    it('should show todos-count when it is more than 0', function() {
Clement Ho committed
35 36 37 38
      triggerToggle(10);
      expect(isTodosCountHidden()).toEqual(false);
    });

39
    describe('when todos-count is 1000', function() {
Clement Ho committed
40 41 42 43
      beforeEach(function() {
        triggerToggle(1000);
      });

44
      it('should show todos-count', function() {
Clement Ho committed
45 46 47
        expect(isTodosCountHidden()).toEqual(false);
      });

48
      it('should show 99+ for todos-count', function() {
49
        expect($(todosPendingCount).text()).toEqual('99+');
Clement Ho committed
50 51 52
      });
    });
  });
53
}).call(window);