summaryrefslogtreecommitdiff
path: root/spec/frontend/commit/commit_box_pipeline_mini_graph_spec.js
blob: b1c8ba48475f7358a18a6227f5e40e194d6993cd (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
import Vue from 'vue';
import VueApollo from 'vue-apollo';
import { shallowMount } from '@vue/test-utils';
import createMockApollo from 'helpers/mock_apollo_helper';
import { extendedWrapper } from 'helpers/vue_test_utils_helper';
import waitForPromises from 'helpers/wait_for_promises';
import createFlash from '~/flash';
import CommitBoxPipelineMiniGraph from '~/projects/commit_box/info/components/commit_box_pipeline_mini_graph.vue';
import getLinkedPipelinesQuery from '~/projects/commit_box/info/graphql/queries/get_linked_pipelines.query.graphql';
import getPipelineStagesQuery from '~/projects/commit_box/info/graphql/queries/get_pipeline_stages.query.graphql';
import { mockPipelineStagesQueryResponse, mockStages } from './mock_data';

jest.mock('~/flash');

Vue.use(VueApollo);

describe('Commit box pipeline mini graph', () => {
  let wrapper;

  const findMiniGraph = () => wrapper.findByTestId('commit-box-mini-graph');
  const findUpstream = () => wrapper.findByTestId('commit-box-mini-graph-upstream');
  const findDownstream = () => wrapper.findByTestId('commit-box-mini-graph-downstream');

  const stagesHandler = jest.fn().mockResolvedValue(mockPipelineStagesQueryResponse);

  const createComponent = ({ props = {} } = {}) => {
    const handlers = [
      [getLinkedPipelinesQuery, {}],
      [getPipelineStagesQuery, stagesHandler],
    ];

    wrapper = extendedWrapper(
      shallowMount(CommitBoxPipelineMiniGraph, {
        propsData: {
          stages: mockStages,
          ...props,
        },
        apolloProvider: createMockApollo(handlers),
      }),
    );

    return waitForPromises();
  };

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

  describe('linked pipelines', () => {
    beforeEach(async () => {
      await createComponent();
    });

    it('should display the mini pipeine graph', () => {
      expect(findMiniGraph().exists()).toBe(true);
    });

    it('should not display linked pipelines', () => {
      expect(findUpstream().exists()).toBe(false);
      expect(findDownstream().exists()).toBe(false);
    });
  });

  describe('when data is mismatched', () => {
    beforeEach(async () => {
      await createComponent({ props: { stages: [] } });
    });

    it('calls create flash with expected arguments', () => {
      expect(createFlash).toHaveBeenCalledWith({
        message: 'There was a problem handling the pipeline data.',
        captureError: true,
        error: new Error('Rest stages and graphQl stages must be the same length'),
      });
    });
  });
});