summaryrefslogtreecommitdiff
path: root/spec/frontend/issues/list/components/issue_card_statistics_spec.js
blob: 180d4ab7eb670af135d7c1e7f6fbe6fb5cca0ec9 (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
import { GlIcon } from '@gitlab/ui';
import { shallowMountExtended } from 'helpers/vue_test_utils_helper';
import IssueCardStatistics from '~/issues/list/components/issue_card_statistics.vue';
import { i18n } from '~/issues/list/constants';

describe('IssueCardStatistics CE component', () => {
  let wrapper;

  const findMergeRequests = () => wrapper.findByTestId('merge-requests');
  const findUpvotes = () => wrapper.findByTestId('issuable-upvotes');
  const findDownvotes = () => wrapper.findByTestId('issuable-downvotes');

  const mountComponent = ({ mergeRequestsCount, upvotes, downvotes } = {}) => {
    wrapper = shallowMountExtended(IssueCardStatistics, {
      propsData: {
        issue: {
          mergeRequestsCount,
          upvotes,
          downvotes,
        },
      },
    });
  };

  describe('when issue attributes are undefined', () => {
    it('does not render the attributes', () => {
      mountComponent();

      expect(findMergeRequests().exists()).toBe(false);
      expect(findUpvotes().exists()).toBe(false);
      expect(findDownvotes().exists()).toBe(false);
    });
  });

  describe('when issue attributes are defined', () => {
    beforeEach(() => {
      mountComponent({ mergeRequestsCount: 1, upvotes: 5, downvotes: 9 });
    });

    it('renders merge requests', () => {
      const mergeRequests = findMergeRequests();

      expect(mergeRequests.text()).toBe('1');
      expect(mergeRequests.attributes('title')).toBe(i18n.relatedMergeRequests);
      expect(mergeRequests.findComponent(GlIcon).props('name')).toBe('merge-request');
    });

    it('renders upvotes', () => {
      const upvotes = findUpvotes();

      expect(upvotes.text()).toBe('5');
      expect(upvotes.attributes('title')).toBe(i18n.upvotes);
      expect(upvotes.findComponent(GlIcon).props('name')).toBe('thumb-up');
    });

    it('renders downvotes', () => {
      const downvotes = findDownvotes();

      expect(downvotes.text()).toBe('9');
      expect(downvotes.attributes('title')).toBe(i18n.downvotes);
      expect(downvotes.findComponent(GlIcon).props('name')).toBe('thumb-down');
    });
  });
});