summaryrefslogtreecommitdiff
path: root/spec/frontend/boards/components/item_count_spec.js
blob: 06cd3910fc011dface7d195182ad53d47609d4c5 (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
import { shallowMount } from '@vue/test-utils';
import IssueCount from '~/boards/components/item_count.vue';

describe('IssueCount', () => {
  let vm;
  let maxIssueCount;
  let itemsSize;

  const createComponent = (props) => {
    vm = shallowMount(IssueCount, { propsData: props });
  };

  afterEach(() => {
    maxIssueCount = 0;
    itemsSize = 0;

    if (vm) vm.destroy();
  });

  describe('when maxIssueCount is zero', () => {
    beforeEach(() => {
      itemsSize = 3;

      createComponent({ maxIssueCount: 0, itemsSize });
    });

    it('contains issueSize in the template', () => {
      expect(vm.find('[data-testid="board-items-count"]').text()).toEqual(String(itemsSize));
    });

    it('does not contains maxIssueCount in the template', () => {
      expect(vm.find('.max-issue-size').exists()).toBe(false);
    });
  });

  describe('when maxIssueCount is greater than zero', () => {
    beforeEach(() => {
      maxIssueCount = 2;
      itemsSize = 1;

      createComponent({ maxIssueCount, itemsSize });
    });

    afterEach(() => {
      vm.destroy();
    });

    it('contains issueSize in the template', () => {
      expect(vm.find('[data-testid="board-items-count"]').text()).toEqual(String(itemsSize));
    });

    it('contains maxIssueCount in the template', () => {
      expect(vm.find('.max-issue-size').text()).toEqual(String(maxIssueCount));
    });

    it('does not have text-danger class when issueSize is less than maxIssueCount', () => {
      expect(vm.classes('.text-danger')).toBe(false);
    });
  });

  describe('when issueSize is greater than maxIssueCount', () => {
    beforeEach(() => {
      itemsSize = 3;
      maxIssueCount = 2;

      createComponent({ maxIssueCount, itemsSize });
    });

    afterEach(() => {
      vm.destroy();
    });

    it('contains issueSize in the template', () => {
      expect(vm.find('[data-testid="board-items-count"]').text()).toEqual(String(itemsSize));
    });

    it('contains maxIssueCount in the template', () => {
      expect(vm.find('.max-issue-size').text()).toEqual(String(maxIssueCount));
    });

    it('has text-danger class', () => {
      expect(vm.find('.text-danger').text()).toEqual(String(itemsSize));
    });
  });
});