Welcome to mirror list, hosted at ThFree Co, Russian Federation.

pipeline_graph_spec.js « pipeline_graph « pipelines « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 6704ee06c1a86cef7d20b04ac10b1f4c94d08e35 (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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
import { shallowMount } from '@vue/test-utils';
import { GlAlert } from '@gitlab/ui';
import { pipelineData, singleStageData } from './mock_data';
import { CI_CONFIG_STATUS_INVALID } from '~/pipeline_editor/constants';
import { DRAW_FAILURE, EMPTY_PIPELINE_DATA, INVALID_CI_CONFIG } from '~/pipelines/constants';
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 = defaultProps) => {
    return shallowMount(PipelineGraph, {
      propsData: {
        ...props,
      },
    });
  };

  const findPipelineGraph = () => wrapper.find('[data-testid="graph-container"]');
  const findAlert = () => wrapper.find(GlAlert);
  const findAllStagePills = () => wrapper.findAll(StagePill);
  const findAllStageBackgroundElements = () => wrapper.findAll('[data-testid="stage-background"]');
  const findStageBackgroundElementAt = index => findAllStageBackgroundElements().at(index);
  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()).toBe(wrapper.vm.$options.warningTexts[EMPTY_PIPELINE_DATA]);
      expect(findPipelineGraph().exists()).toBe(false);
      expect(findAllStagePills()).toHaveLength(0);
      expect(findAllJobPills()).toHaveLength(0);
    });
  });

  describe('with `INVALID` status', () => {
    beforeEach(() => {
      wrapper = createComponent({ pipelineData: { status: CI_CONFIG_STATUS_INVALID } });
    });

    it('renders an error message and does not render the graph', () => {
      expect(findAlert().exists()).toBe(true);
      expect(findAlert().text()).toBe(wrapper.vm.$options.warningTexts[INVALID_CI_CONFIG]);
      expect(findPipelineGraph().exists()).toBe(false);
    });
  });

  describe('without `INVALID` status', () => {
    beforeEach(() => {
      wrapper = createComponent();
    });

    it('renders the graph with no status error', () => {
      expect(findAlert().text()).not.toBe(wrapper.vm.$options.warningTexts[INVALID_CI_CONFIG]);
      expect(findPipelineGraph().exists()).toBe(true);
    });
  });

  describe('with error while rendering the links', () => {
    beforeEach(() => {
      wrapper = createComponent();
    });

    it('renders the error that link could not be drawn', () => {
      expect(findAlert().exists()).toBe(true);
      expect(findAlert().text()).toBe(wrapper.vm.$options.errorTexts[DRAW_FAILURE]);
    });
  });

  describe('with only one stage', () => {
    beforeEach(() => {
      wrapper = createComponent({ pipelineData: singleStageData });
    });

    it('renders the right number of stage pills', () => {
      const expectedStagesLength = singleStageData.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 = singleStageData.stages.reduce((acc, val) => {
        return acc + val.groups.length;
      }, 0);

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

    describe('rounds corner', () => {
      it.each`
        cssClass                       | expectedState
        ${'gl-rounded-bottom-left-6'}  | ${true}
        ${'gl-rounded-top-left-6'}     | ${true}
        ${'gl-rounded-top-right-6'}    | ${true}
        ${'gl-rounded-bottom-right-6'} | ${true}
      `('$cssClass should be $expectedState on the only element', ({ cssClass, expectedState }) => {
        const classes = findStageBackgroundElementAt(0).classes();

        expect(classes.includes(cssClass)).toBe(expectedState);
      });
    });
  });

  describe('with multiple stages and jobs', () => {
    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);
    });

    describe('rounds corner', () => {
      it.each`
        cssClass                       | expectedState
        ${'gl-rounded-bottom-left-6'}  | ${true}
        ${'gl-rounded-top-left-6'}     | ${true}
        ${'gl-rounded-top-right-6'}    | ${false}
        ${'gl-rounded-bottom-right-6'} | ${false}
      `(
        '$cssClass should be $expectedState on the first element',
        ({ cssClass, expectedState }) => {
          const classes = findStageBackgroundElementAt(0).classes();

          expect(classes.includes(cssClass)).toBe(expectedState);
        },
      );

      it.each`
        cssClass                       | expectedState
        ${'gl-rounded-bottom-left-6'}  | ${false}
        ${'gl-rounded-top-left-6'}     | ${false}
        ${'gl-rounded-top-right-6'}    | ${true}
        ${'gl-rounded-bottom-right-6'} | ${true}
      `('$cssClass should be $expectedState on the last element', ({ cssClass, expectedState }) => {
        const classes = findStageBackgroundElementAt(pipelineData.stages.length - 1).classes();

        expect(classes.includes(cssClass)).toBe(expectedState);
      });
    });
  });
});