debian-mirror-gitlab/spec/frontend/pipelines/graph/graph_component_spec.js

84 lines
2.3 KiB
JavaScript
Raw Normal View History

2021-02-22 17:27:13 +05:30
import { mount, shallowMount } from '@vue/test-utils';
import PipelineGraph from '~/pipelines/components/graph/graph_component.vue';
2021-01-03 14:25:43 +05:30
import StageColumnComponent from '~/pipelines/components/graph/stage_column_component.vue';
2021-02-22 17:27:13 +05:30
import LinkedPipelinesColumn from '~/pipelines/components/graph/linked_pipelines_column.vue';
import { GRAPHQL } from '~/pipelines/components/graph/constants';
import {
generateResponse,
mockPipelineResponse,
pipelineWithUpstreamDownstream,
} from './mock_data';
2020-04-22 19:07:51 +05:30
describe('graph component', () => {
let wrapper;
2021-02-22 17:27:13 +05:30
const findLinkedColumns = () => wrapper.findAll(LinkedPipelinesColumn);
2021-01-03 14:25:43 +05:30
const findStageColumns = () => wrapper.findAll(StageColumnComponent);
2020-11-24 15:15:51 +05:30
2021-02-22 17:27:13 +05:30
const defaultProps = {
pipeline: generateResponse(mockPipelineResponse, 'root/fungi-xoxo'),
};
const createComponent = ({ mountFn = shallowMount, props = {} } = {}) => {
wrapper = mountFn(PipelineGraph, {
propsData: {
...defaultProps,
...props,
},
provide: {
dataMethod: GRAPHQL,
},
});
};
2020-06-23 00:09:42 +05:30
2020-04-22 19:07:51 +05:30
afterEach(() => {
wrapper.destroy();
wrapper = null;
});
describe('with data', () => {
2021-01-03 14:25:43 +05:30
beforeEach(() => {
2021-02-22 17:27:13 +05:30
createComponent({ mountFn: mount });
2021-01-03 14:25:43 +05:30
});
2020-04-22 19:07:51 +05:30
2021-02-22 17:27:13 +05:30
it('renders the main columns in the graph', () => {
expect(findStageColumns()).toHaveLength(defaultProps.pipeline.stages.length);
2020-04-22 19:07:51 +05:30
});
2021-02-22 17:27:13 +05:30
describe('when column requests a refresh', () => {
2020-04-22 19:07:51 +05:30
beforeEach(() => {
2021-02-22 17:27:13 +05:30
findStageColumns()
.at(0)
.vm.$emit('refreshPipelineGraph');
2020-04-22 19:07:51 +05:30
});
2021-02-22 17:27:13 +05:30
it('refreshPipelineGraph is emitted', () => {
expect(wrapper.emitted().refreshPipelineGraph).toHaveLength(1);
2020-04-22 19:07:51 +05:30
});
});
});
describe('when linked pipelines are not present', () => {
beforeEach(() => {
2021-02-22 17:27:13 +05:30
createComponent({ mountFn: mount });
2020-04-22 19:07:51 +05:30
});
2021-02-22 17:27:13 +05:30
it('should not render a linked pipelines column', () => {
expect(findLinkedColumns()).toHaveLength(0);
2020-04-22 19:07:51 +05:30
});
});
2021-02-22 17:27:13 +05:30
describe('when linked pipelines are present', () => {
beforeEach(() => {
createComponent({
mountFn: mount,
props: { pipeline: pipelineWithUpstreamDownstream(mockPipelineResponse) },
2020-04-22 19:07:51 +05:30
});
2021-02-22 17:27:13 +05:30
});
2020-04-22 19:07:51 +05:30
2021-02-22 17:27:13 +05:30
it('should render linked pipelines columns', () => {
expect(findLinkedColumns()).toHaveLength(2);
2020-04-22 19:07:51 +05:30
});
});
});