summaryrefslogtreecommitdiff
path: root/spec/frontend/groups/components/item_stats_spec.js
blob: 771643609ec79a4840d65791ffd03abb74cd2b27 (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
import Vue from 'vue';

import mountComponent from 'helpers/vue_mount_component_helper';
import itemStatsComponent from '~/groups/components/item_stats.vue';
import {
  mockParentGroupItem,
  ITEM_TYPE,
  VISIBILITY_TYPE_ICON,
  GROUP_VISIBILITY_TYPE,
  PROJECT_VISIBILITY_TYPE,
} from '../mock_data';

const createComponent = (item = mockParentGroupItem) => {
  const Component = Vue.extend(itemStatsComponent);

  return mountComponent(Component, {
    item,
  });
};

describe('ItemStatsComponent', () => {
  describe('computed', () => {
    describe('visibilityIcon', () => {
      it('should return icon class based on `item.visibility` value', () => {
        Object.keys(VISIBILITY_TYPE_ICON).forEach(visibility => {
          const item = { ...mockParentGroupItem, visibility };
          const vm = createComponent(item);

          expect(vm.visibilityIcon).toBe(VISIBILITY_TYPE_ICON[visibility]);
          vm.$destroy();
        });
      });
    });

    describe('visibilityTooltip', () => {
      it('should return tooltip string for Group based on `item.visibility` value', () => {
        Object.keys(GROUP_VISIBILITY_TYPE).forEach(visibility => {
          const item = { ...mockParentGroupItem, visibility, type: ITEM_TYPE.GROUP };
          const vm = createComponent(item);

          expect(vm.visibilityTooltip).toBe(GROUP_VISIBILITY_TYPE[visibility]);
          vm.$destroy();
        });
      });

      it('should return tooltip string for Project based on `item.visibility` value', () => {
        Object.keys(PROJECT_VISIBILITY_TYPE).forEach(visibility => {
          const item = { ...mockParentGroupItem, visibility, type: ITEM_TYPE.PROJECT };
          const vm = createComponent(item);

          expect(vm.visibilityTooltip).toBe(PROJECT_VISIBILITY_TYPE[visibility]);
          vm.$destroy();
        });
      });
    });

    describe('isProject', () => {
      it('should return boolean value representing whether `item.type` is Project or not', () => {
        let item;
        let vm;

        item = { ...mockParentGroupItem, type: ITEM_TYPE.PROJECT };
        vm = createComponent(item);

        expect(vm.isProject).toBeTruthy();
        vm.$destroy();

        item = { ...mockParentGroupItem, type: ITEM_TYPE.GROUP };
        vm = createComponent(item);

        expect(vm.isProject).toBeFalsy();
        vm.$destroy();
      });
    });

    describe('isGroup', () => {
      it('should return boolean value representing whether `item.type` is Group or not', () => {
        let item;
        let vm;

        item = { ...mockParentGroupItem, type: ITEM_TYPE.GROUP };
        vm = createComponent(item);

        expect(vm.isGroup).toBeTruthy();
        vm.$destroy();

        item = { ...mockParentGroupItem, type: ITEM_TYPE.PROJECT };
        vm = createComponent(item);

        expect(vm.isGroup).toBeFalsy();
        vm.$destroy();
      });
    });
  });

  describe('template', () => {
    it('renders component container element correctly', () => {
      const vm = createComponent();

      expect(vm.$el.classList.contains('stats')).toBeTruthy();

      vm.$destroy();
    });

    it('renders start count and last updated information for project item correctly', () => {
      const item = { ...mockParentGroupItem, type: ITEM_TYPE.PROJECT, starCount: 4 };
      const vm = createComponent(item);

      const projectStarIconEl = vm.$el.querySelector('.project-stars');

      expect(projectStarIconEl).not.toBeNull();
      expect(projectStarIconEl.querySelectorAll('svg').length).toBeGreaterThan(0);
      expect(projectStarIconEl.querySelectorAll('.stat-value').length).toBeGreaterThan(0);
      expect(vm.$el.querySelectorAll('.last-updated').length).toBeGreaterThan(0);

      vm.$destroy();
    });
  });
});