2020-12-16 10:10:18 -05:00
|
|
|
import { GlAlert } from '@gitlab/ui';
|
2021-02-14 13:09:20 -05:00
|
|
|
import { shallowMount } from '@vue/test-utils';
|
2021-05-03 20:10:16 -04:00
|
|
|
import { setHTMLFixture } from 'helpers/fixtures';
|
2021-04-19 08:09:04 -04:00
|
|
|
import { CI_CONFIG_STATUS_VALID } from '~/pipeline_editor/constants';
|
2021-04-07 14:09:45 -04:00
|
|
|
import LinksInner from '~/pipelines/components/graph_shared/links_inner.vue';
|
|
|
|
import LinksLayer from '~/pipelines/components/graph_shared/links_layer.vue';
|
2021-02-14 13:09:20 -05:00
|
|
|
import JobPill from '~/pipelines/components/pipeline_graph/job_pill.vue';
|
2020-09-16 08:10:15 -04:00
|
|
|
import PipelineGraph from '~/pipelines/components/pipeline_graph/pipeline_graph.vue';
|
2021-06-23 14:07:10 -04:00
|
|
|
import StageName from '~/pipelines/components/pipeline_graph/stage_name.vue';
|
2021-05-03 20:10:16 -04:00
|
|
|
import { pipelineData, singleStageData } from './mock_data';
|
2020-09-16 08:10:15 -04:00
|
|
|
|
|
|
|
describe('pipeline graph component', () => {
|
|
|
|
const defaultProps = { pipelineData };
|
|
|
|
let wrapper;
|
|
|
|
|
2021-05-03 20:10:16 -04:00
|
|
|
const containerId = 'pipeline-graph-container-0';
|
|
|
|
setHTMLFixture(`<div id="${containerId}"></div>`);
|
|
|
|
|
2020-12-16 10:10:18 -05:00
|
|
|
const createComponent = (props = defaultProps) => {
|
2020-09-16 08:10:15 -04:00
|
|
|
return shallowMount(PipelineGraph, {
|
|
|
|
propsData: {
|
|
|
|
...props,
|
|
|
|
},
|
2021-04-07 14:09:45 -04:00
|
|
|
stubs: { LinksLayer, LinksInner },
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
measurements: {
|
|
|
|
width: 1000,
|
|
|
|
height: 1000,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
},
|
2020-09-16 08:10:15 -04:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2021-04-07 14:09:45 -04:00
|
|
|
const findAlert = () => wrapper.findComponent(GlAlert);
|
2022-09-13 14:12:21 -04:00
|
|
|
const findAllJobPills = () => wrapper.findAllComponents(JobPill);
|
2021-06-23 14:07:10 -04:00
|
|
|
const findAllStageNames = () => wrapper.findAllComponents(StageName);
|
2021-04-07 14:09:45 -04:00
|
|
|
const findLinksLayer = () => wrapper.findComponent(LinksLayer);
|
|
|
|
const findPipelineGraph = () => wrapper.find('[data-testid="graph-container"]');
|
2020-09-16 08:10:15 -04:00
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
wrapper.destroy();
|
|
|
|
});
|
|
|
|
|
2020-12-17 16:09:57 -05:00
|
|
|
describe('with `VALID` status', () => {
|
2020-12-16 10:10:18 -05:00
|
|
|
beforeEach(() => {
|
2020-12-17 16:09:57 -05:00
|
|
|
wrapper = createComponent({
|
2021-03-22 17:08:59 -04:00
|
|
|
pipelineData: {
|
|
|
|
status: CI_CONFIG_STATUS_VALID,
|
|
|
|
stages: [{ name: 'hello', groups: [] }],
|
|
|
|
},
|
2020-12-17 16:09:57 -05:00
|
|
|
});
|
2020-12-16 10:10:18 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
it('renders the graph with no status error', () => {
|
2020-12-17 16:09:57 -05:00
|
|
|
expect(findAlert().exists()).toBe(false);
|
2020-12-16 10:10:18 -05:00
|
|
|
expect(findPipelineGraph().exists()).toBe(true);
|
2021-04-07 14:09:45 -04:00
|
|
|
expect(findLinksLayer().exists()).toBe(true);
|
2020-12-16 10:10:18 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('with only one stage', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
wrapper = createComponent({ pipelineData: singleStageData });
|
|
|
|
});
|
|
|
|
|
2021-06-23 14:07:10 -04:00
|
|
|
it('renders the right number of stage titles', () => {
|
2020-12-16 10:10:18 -05:00
|
|
|
const expectedStagesLength = singleStageData.stages.length;
|
2020-09-16 08:10:15 -04:00
|
|
|
|
2021-06-23 14:07:10 -04:00
|
|
|
expect(findAllStageNames()).toHaveLength(expectedStagesLength);
|
2020-09-16 08:10:15 -04:00
|
|
|
});
|
|
|
|
|
2020-12-16 10:10:18 -05:00
|
|
|
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);
|
|
|
|
});
|
|
|
|
});
|
2020-11-04 10:08:41 -05:00
|
|
|
|
2020-12-16 10:10:18 -05:00
|
|
|
describe('with multiple stages and jobs', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
wrapper = createComponent();
|
|
|
|
});
|
|
|
|
|
2021-06-23 14:07:10 -04:00
|
|
|
it('renders the right number of stage titles', () => {
|
2020-12-16 10:10:18 -05:00
|
|
|
const expectedStagesLength = pipelineData.stages.length;
|
|
|
|
|
2021-06-23 14:07:10 -04:00
|
|
|
expect(findAllStageNames()).toHaveLength(expectedStagesLength);
|
2020-12-16 10:10:18 -05:00
|
|
|
});
|
2020-11-04 10:08:41 -05:00
|
|
|
|
2020-09-16 08:10:15 -04:00
|
|
|
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);
|
|
|
|
});
|
2020-11-04 10:08:41 -05:00
|
|
|
});
|
2020-09-16 08:10:15 -04:00
|
|
|
});
|