summaryrefslogtreecommitdiff
path: root/spec/frontend/analytics/instance_statistics/components/instance_counts_spec.js
blob: 2274f4c3fde11701634408560f2412bc0c8a231c (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
import { shallowMount } from '@vue/test-utils';
import InstanceCounts from '~/analytics/instance_statistics/components/instance_counts.vue';
import MetricCard from '~/analytics/shared/components/metric_card.vue';
import countsMockData from '../mock_data';

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

  const createComponent = ({ loading = false, data = {} } = {}) => {
    const $apollo = {
      queries: {
        counts: {
          loading,
        },
      },
    };

    wrapper = shallowMount(InstanceCounts, {
      mocks: { $apollo },
      data() {
        return {
          ...data,
        };
      },
    });
  };

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

  const findMetricCard = () => wrapper.find(MetricCard);

  describe('while loading', () => {
    beforeEach(() => {
      createComponent({ loading: true });
    });

    it('displays the metric card with isLoading=true', () => {
      expect(findMetricCard().props('isLoading')).toBe(true);
    });
  });

  describe('with data', () => {
    beforeEach(() => {
      createComponent({ data: { counts: countsMockData } });
    });

    it('passes the counts data to the metric card', () => {
      expect(findMetricCard().props('metrics')).toEqual(countsMockData);
    });
  });
});