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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

185 lines
5.4 KiB
JavaScript
Raw Normal View History

2023-04-23 21:23:45 +05:30
import { shallowMount } from '@vue/test-utils';
import { mountExtended } from 'helpers/vue_test_utils_helper';
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;
2023-04-23 21:23:45 +05:30
const findDownstreamColumn = () => wrapper.findByTestId('downstream-pipelines');
2022-10-11 01:57:18 +05:30
const findLinkedColumns = () => wrapper.findAllComponents(LinkedPipelinesColumn);
const findLinksLayer = () => wrapper.findComponent(LinksLayer);
const findStageColumns = () => wrapper.findAllComponents(StageColumnComponent);
2023-04-23 21:23:45 +05:30
const findStageNameInJob = () => wrapper.findByTestId('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
describe('with data', () => {
2021-01-03 14:25:43 +05:30
beforeEach(() => {
2023-04-23 21:23:45 +05:30
createComponent({ mountFn: mountExtended });
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
2023-04-23 21:23:45 +05:30
describe('when column request an update to the retry confirmation modal', () => {
beforeEach(() => {
findStageColumns().at(0).vm.$emit('setSkipRetryModal');
});
it('setSkipRetryModal is emitted', () => {
expect(wrapper.emitted().setSkipRetryModal).toHaveLength(1);
});
});
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({
2023-04-23 21:23:45 +05:30
mountFn: mountExtended,
2021-03-08 18:12:59 +05:30
stubOverride: { 'job-item': false },
data: { hoveredJobName: 'test_a' },
});
findLinksLayer().vm.$emit('highlightedJobsChange', ['test_c', 'build_c']);
});
it('dims unrelated jobs', () => {
2022-10-11 01:57:18 +05:30
const unrelatedJob = wrapper.findComponent(JobItem);
2021-03-08 18:12:59 +05:30
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(() => {
2023-04-23 21:23:45 +05:30
createComponent({ mountFn: mountExtended });
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({
2023-04-23 21:23:45 +05:30
mountFn: mountExtended,
2021-02-22 17:27:13 +05:30
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({
2023-04-23 21:23:45 +05:30
mountFn: mountExtended,
2021-04-29 21:17:54 +05:30
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);
});
});
2023-04-23 21:23:45 +05:30
describe('downstream pipelines', () => {
beforeEach(() => {
createComponent({
mountFn: mountExtended,
props: {
pipeline: pipelineWithUpstreamDownstream(mockPipelineResponse),
},
});
});
it('filters pipelines spawned from the same trigger job', () => {
// The mock data has one downstream with `retried: true and one
// with retried false. We filter the `retried: true` out so we
// should only pass one downstream
expect(findDownstreamColumn().props().linkedPipelines).toHaveLength(1);
});
});
2020-04-22 19:07:51 +05:30
});