summaryrefslogtreecommitdiff
path: root/spec/frontend/releases/components/issuable_stats_spec.js
blob: d8211ec2adcce9fda7d30774c716170ff4e2fa67 (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
import { GlLink } from '@gitlab/ui';
import { mount } from '@vue/test-utils';
import { trimText } from 'helpers/text_helper';
import IssuableStats from '~/releases/components/issuable_stats.vue';

describe('~/releases/components/issuable_stats.vue', () => {
  let wrapper;
  let defaultProps;

  const createComponent = propUpdates => {
    wrapper = mount(IssuableStats, {
      propsData: {
        ...defaultProps,
        ...propUpdates,
      },
    });
  };

  const findOpenStatLink = () => wrapper.find('[data-testid="open-stat"]').find(GlLink);
  const findMergedStatLink = () => wrapper.find('[data-testid="merged-stat"]').find(GlLink);
  const findClosedStatLink = () => wrapper.find('[data-testid="closed-stat"]').find(GlLink);

  beforeEach(() => {
    defaultProps = {
      label: 'Items',
      total: 10,
      closed: 2,
      merged: 7,
      openedPath: 'path/to/opened/items',
      closedPath: 'path/to/closed/items',
      mergedPath: 'path/to/merged/items',
    };
  });

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

  it('matches snapshot', () => {
    createComponent();

    expect(wrapper.html()).toMatchSnapshot();
  });

  describe('when only total and closed counts are provided', () => {
    beforeEach(() => {
      createComponent({ merged: undefined, mergedPath: undefined });
    });

    it('renders a label with the total count; also, the opened count and the closed count', () => {
      expect(trimText(wrapper.text())).toMatchInterpolatedText('Items 10 Open: 8 • Closed: 2');
    });
  });

  describe('when only total, merged, and closed counts are provided', () => {
    beforeEach(() => {
      createComponent();
    });

    it('renders a label with the total count; also, the opened count, the merged count, and the closed count', () => {
      expect(wrapper.text()).toMatchInterpolatedText('Items 10 Open: 1 • Merged: 7 • Closed: 2');
    });
  });

  describe('when path parameters are provided', () => {
    beforeEach(() => {
      createComponent();
    });

    it('renders the "open" stat as a link', () => {
      const link = findOpenStatLink();

      expect(link.exists()).toBe(true);
      expect(link.attributes('href')).toBe(defaultProps.openedPath);
    });

    it('renders the "merged" stat as a link', () => {
      const link = findMergedStatLink();

      expect(link.exists()).toBe(true);
      expect(link.attributes('href')).toBe(defaultProps.mergedPath);
    });

    it('renders the "closed" stat as a link', () => {
      const link = findClosedStatLink();

      expect(link.exists()).toBe(true);
      expect(link.attributes('href')).toBe(defaultProps.closedPath);
    });
  });

  describe('when path parameters are not provided', () => {
    beforeEach(() => {
      createComponent({
        openedPath: undefined,
        closedPath: undefined,
        mergedPath: undefined,
      });
    });

    it('does not render the "open" stat as a link', () => {
      expect(findOpenStatLink().exists()).toBe(false);
    });

    it('does not render the "merged" stat as a link', () => {
      expect(findMergedStatLink().exists()).toBe(false);
    });

    it('does not render the "closed" stat as a link', () => {
      expect(findClosedStatLink().exists()).toBe(false);
    });
  });
});