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

160 lines
4.4 KiB
JavaScript
Raw Normal View History

2021-02-22 17:27:13 +05:30
import { mount, shallowMount } from '@vue/test-utils';
2021-11-11 11:23:49 +05:30
import { LAYER_VIEW, STAGE_VIEW } from '~/pipelines/components/graph/constants';
2021-02-22 17:27:13 +05:30
import PipelineGraph from '~/pipelines/components/graph/graph_component.vue';
2021-03-08 18:12:59 +05:30
import JobItem from '~/pipelines/components/graph/job_item.vue';
2021-02-22 17:27:13 +05:30
import LinkedPipelinesColumn from '~/pipelines/components/graph/linked_pipelines_column.vue';
2021-03-11 19:13:27 +05:30
import StageColumnComponent from '~/pipelines/components/graph/stage_column_component.vue';
2021-10-27 15:23:28 +05:30
import { calculatePipelineLayersInfo } from '~/pipelines/components/graph/utils';
2021-03-08 18:12:59 +05:30
import LinksLayer from '~/pipelines/components/graph_shared/links_layer.vue';
2021-02-22 17:27:13 +05:30
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-03-08 18:12:59 +05:30
const findLinksLayer = () => wrapper.find(LinksLayer);
2021-01-03 14:25:43 +05:30
const findStageColumns = () => wrapper.findAll(StageColumnComponent);
2021-04-29 21:17:54 +05:30
const findStageNameInJob = () => wrapper.find('[data-testid="stage-name-in-job"]');
2020-11-24 15:15:51 +05:30
2021-02-22 17:27:13 +05:30
const defaultProps = {
pipeline: generateResponse(mockPipelineResponse, 'root/fungi-xoxo'),
2021-06-08 01:23:25 +05:30
showLinks: false,
2021-04-29 21:17:54 +05:30
viewType: STAGE_VIEW,
2021-04-17 20:07:23 +05:30
configPaths: {
metricsPath: '',
graphqlResourceEtag: 'this/is/a/path',
},
2021-02-22 17:27:13 +05:30
};
2021-03-11 19:13:27 +05:30
const defaultData = {
measurements: {
width: 800,
height: 800,
},
};
2021-03-08 18:12:59 +05:30
const createComponent = ({
data = {},
mountFn = shallowMount,
props = {},
stubOverride = {},
} = {}) => {
2021-02-22 17:27:13 +05:30
wrapper = mountFn(PipelineGraph, {
propsData: {
...defaultProps,
...props,
},
2021-03-08 18:12:59 +05:30
data() {
2021-03-11 19:13:27 +05:30
return {
...defaultData,
...data,
};
2021-03-08 18:12:59 +05:30
},
stubs: {
'links-inner': true,
'linked-pipeline': true,
'job-item': true,
'job-group-dropdown': true,
...stubOverride,
},
2021-02-22 17:27:13 +05:30
});
};
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-03-08 18:12:59 +05:30
it('renders the links layer', () => {
expect(findLinksLayer().exists()).toBe(true);
});
2021-04-29 21:17:54 +05:30
it('does not display stage name on the job in default (stage) mode', () => {
expect(findStageNameInJob().exists()).toBe(false);
});
2021-02-22 17:27:13 +05:30
describe('when column requests a refresh', () => {
2020-04-22 19:07:51 +05:30
beforeEach(() => {
2021-03-08 18:12:59 +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
});
});
2021-03-08 18:12:59 +05:30
describe('when links are present', () => {
2021-04-29 21:17:54 +05:30
beforeEach(() => {
2021-03-08 18:12:59 +05:30
createComponent({
mountFn: mount,
stubOverride: { 'job-item': false },
data: { hoveredJobName: 'test_a' },
});
findLinksLayer().vm.$emit('highlightedJobsChange', ['test_c', 'build_c']);
});
it('dims unrelated jobs', () => {
const unrelatedJob = wrapper.find(JobItem);
expect(findLinksLayer().emitted().highlightedJobsChange).toHaveLength(1);
expect(unrelatedJob.classes('gl-opacity-3')).toBe(true);
});
});
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
});
});
2021-04-29 21:17:54 +05:30
describe('in layers mode', () => {
beforeEach(() => {
createComponent({
mountFn: mount,
stubOverride: {
'job-item': false,
'job-group-dropdown': false,
},
props: {
viewType: LAYER_VIEW,
2021-10-27 15:23:28 +05:30
computedPipelineInfo: calculatePipelineLayersInfo(defaultProps.pipeline, 'layer', ''),
2021-04-29 21:17:54 +05:30
},
});
});
it('displays the stage name on the job', () => {
expect(findStageNameInJob().exists()).toBe(true);
});
});
2020-04-22 19:07:51 +05:30
});