debian-mirror-gitlab/spec/frontend/pipelines/pipeline_graph/pipeline_graph_spec.js

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

105 lines
3.3 KiB
JavaScript
Raw Normal View History

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