summaryrefslogtreecommitdiff
path: root/spec/frontend/groups/components/item_stats_spec.js
blob: 49f3f5da43c71d3e7225e21de55cbe85182c3efa (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
import { shallowMountExtended } from 'helpers/vue_test_utils_helper';
import ItemStats from '~/groups/components/item_stats.vue';
import ItemStatsValue from '~/groups/components/item_stats_value.vue';

import { mockParentGroupItem, ITEM_TYPE } from '../mock_data';

describe('ItemStats', () => {
  let wrapper;

  const defaultProps = {
    item: mockParentGroupItem,
  };

  const createComponent = (props = {}) => {
    wrapper = shallowMountExtended(ItemStats, {
      propsData: { ...defaultProps, ...props },
    });
  };

  afterEach(() => {
    if (wrapper) {
      wrapper.destroy();
      wrapper = null;
    }
  });

  const findItemStatsValue = () => wrapper.find(ItemStatsValue);

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

      expect(wrapper.classes()).toContain('stats');
    });

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

      createComponent({ item });

      expect(findItemStatsValue().exists()).toBe(true);
      expect(findItemStatsValue().props('cssClass')).toBe('project-stars');
      expect(wrapper.find('.last-updated').exists()).toBe(true);
    });

    describe('group specific rendering', () => {
      describe.each`
        provided | state                 | data
        ${true}  | ${'displays'}         | ${null}
        ${false} | ${'does not display'} | ${{ subgroupCount: undefined, projectCount: undefined }}
      `('when provided = $provided', ({ provided, state, data }) => {
        beforeEach(() => {
          const item = {
            ...mockParentGroupItem,
            ...data,
            type: ITEM_TYPE.GROUP,
          };

          createComponent({ item });
        });

        it.each`
          entity         | testId
          ${'subgroups'} | ${'subgroups-count'}
          ${'projects'}  | ${'projects-count'}
        `(`${state} $entity count`, ({ testId }) => {
          expect(wrapper.findByTestId(testId).exists()).toBe(provided);
        });
      });
    });
  });
});