summaryrefslogtreecommitdiff
path: root/spec/frontend/pipelines/pipeline_graph/pipeline_graph_spec.js
blob: 30e192e5726c1006117929c27acd919d036a9d06 (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
import { shallowMount } from '@vue/test-utils';
import { pipelineData } from './mock_data';
import PipelineGraph from '~/pipelines/components/pipeline_graph/pipeline_graph.vue';
import StagePill from '~/pipelines/components/pipeline_graph/stage_pill.vue';
import JobPill from '~/pipelines/components/pipeline_graph/job_pill.vue';

describe('pipeline graph component', () => {
  const defaultProps = { pipelineData };
  let wrapper;

  const createComponent = props => {
    return shallowMount(PipelineGraph, {
      propsData: {
        ...defaultProps,
        ...props,
      },
    });
  };

  const findAllStagePills = () => wrapper.findAll(StagePill);
  const findAllJobPills = () => wrapper.findAll(JobPill);

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

  describe('with no data', () => {
    beforeEach(() => {
      wrapper = createComponent({ pipelineData: {} });
    });

    it('renders an empty section', () => {
      expect(wrapper.text()).toContain('No content to show');
      expect(findAllStagePills()).toHaveLength(0);
      expect(findAllJobPills()).toHaveLength(0);
    });
  });

  describe('with data', () => {
    beforeEach(() => {
      wrapper = createComponent();
    });
    it('renders the right number of stage pills', () => {
      const expectedStagesLength = pipelineData.stages.length;

      expect(findAllStagePills()).toHaveLength(expectedStagesLength);
    });

    it('renders the right number of job pills', () => {
      // We count the number of jobs in the mock data
      const expectedJobsLength = pipelineData.stages.reduce((acc, val) => {
        return acc + val.groups.length;
      }, 0);

      expect(findAllJobPills()).toHaveLength(expectedJobsLength);
    });
  });
});