summaryrefslogtreecommitdiff
path: root/spec/frontend/monitoring/components/charts/stacked_column_spec.js
blob: abb89ac15ef08000a9c49a1088fe2a4f24c38bc7 (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
import { shallowMount } from '@vue/test-utils';
import { GlStackedColumnChart } from '@gitlab/ui/dist/charts';
import StackedColumnChart from '~/monitoring/components/charts/stacked_column.vue';
import { stackedColumnMockedData } from '../../mock_data';

jest.mock('~/lib/utils/icon_utils', () => ({
  getSvgIconPathContent: jest.fn().mockResolvedValue('mockSvgPathContent'),
}));

describe('Stacked column chart component', () => {
  let wrapper;
  const glStackedColumnChart = () => wrapper.find(GlStackedColumnChart);

  beforeEach(() => {
    wrapper = shallowMount(StackedColumnChart, {
      propsData: {
        graphData: stackedColumnMockedData,
      },
    });
  });

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

  describe('with graphData present', () => {
    it('is a Vue instance', () => {
      expect(glStackedColumnChart().exists()).toBe(true);
    });

    it('should contain the same number of elements in the seriesNames computed prop as the graphData metrics prop', () =>
      wrapper.vm
        .$nextTick()
        .then(expect(wrapper.vm.seriesNames).toHaveLength(stackedColumnMockedData.metrics.length)));

    it('should contain the same number of elements in the groupBy computed prop as the graphData result prop', () =>
      wrapper.vm
        .$nextTick()
        .then(
          expect(wrapper.vm.groupBy).toHaveLength(
            stackedColumnMockedData.metrics[0].result[0].values.length,
          ),
        ));
  });
});