diff options
Diffstat (limited to 'spec/frontend/pipelines/pipeline_graph')
3 files changed, 52 insertions, 20 deletions
diff --git a/spec/frontend/pipelines/pipeline_graph/mock_data.js b/spec/frontend/pipelines/pipeline_graph/mock_data.js index a77973b293c..7d1a7a79c7f 100644 --- a/spec/frontend/pipelines/pipeline_graph/mock_data.js +++ b/spec/frontend/pipelines/pipeline_graph/mock_data.js @@ -1,4 +1,4 @@ -import { createUniqueLinkId } from '~/pipelines/utils'; +import { createUniqueLinkId } from '~/pipelines/components/graph_shared/drawing_utils'; export const yamlString = `stages: - empty @@ -78,18 +78,12 @@ export const pipelineData = { groups: [ { name: 'deploy_1', - jobs: [{ script: 'yarn magick', stage: 'deploy' }], + jobs: [{ script: 'yarn magick', stage: 'deploy', needs: ['test_1'] }], id: jobId4, }, ], }, ], - jobs: { - [jobId1]: {}, - [jobId2]: {}, - [jobId3]: {}, - [jobId4]: {}, - }, }; export const singleStageData = { diff --git a/spec/frontend/pipelines/pipeline_graph/pipeline_graph_spec.js b/spec/frontend/pipelines/pipeline_graph/pipeline_graph_spec.js index 6704ee06c1a..b6b0a964383 100644 --- a/spec/frontend/pipelines/pipeline_graph/pipeline_graph_spec.js +++ b/spec/frontend/pipelines/pipeline_graph/pipeline_graph_spec.js @@ -1,7 +1,7 @@ import { shallowMount } from '@vue/test-utils'; import { GlAlert } from '@gitlab/ui'; import { pipelineData, singleStageData } from './mock_data'; -import { CI_CONFIG_STATUS_INVALID } from '~/pipeline_editor/constants'; +import { CI_CONFIG_STATUS_INVALID, CI_CONFIG_STATUS_VALID } from '~/pipeline_editor/constants'; import { DRAW_FAILURE, EMPTY_PIPELINE_DATA, INVALID_CI_CONFIG } from '~/pipelines/constants'; import PipelineGraph from '~/pipelines/components/pipeline_graph/pipeline_graph.vue'; import StagePill from '~/pipelines/components/pipeline_graph/stage_pill.vue'; @@ -23,7 +23,7 @@ describe('pipeline graph component', () => { const findAlert = () => wrapper.find(GlAlert); const findAllStagePills = () => wrapper.findAll(StagePill); const findAllStageBackgroundElements = () => wrapper.findAll('[data-testid="stage-background"]'); - const findStageBackgroundElementAt = index => findAllStageBackgroundElements().at(index); + const findStageBackgroundElementAt = (index) => findAllStageBackgroundElements().at(index); const findAllJobPills = () => wrapper.findAll(JobPill); afterEach(() => { @@ -37,7 +37,7 @@ describe('pipeline graph component', () => { }); it('renders an empty section', () => { - expect(wrapper.text()).toBe(wrapper.vm.$options.warningTexts[EMPTY_PIPELINE_DATA]); + expect(wrapper.text()).toBe(wrapper.vm.$options.errorTexts[EMPTY_PIPELINE_DATA]); expect(findPipelineGraph().exists()).toBe(false); expect(findAllStagePills()).toHaveLength(0); expect(findAllJobPills()).toHaveLength(0); @@ -51,23 +51,25 @@ describe('pipeline graph component', () => { it('renders an error message and does not render the graph', () => { expect(findAlert().exists()).toBe(true); - expect(findAlert().text()).toBe(wrapper.vm.$options.warningTexts[INVALID_CI_CONFIG]); + expect(findAlert().text()).toBe(wrapper.vm.$options.errorTexts[INVALID_CI_CONFIG]); expect(findPipelineGraph().exists()).toBe(false); }); }); - describe('without `INVALID` status', () => { + describe('with `VALID` status', () => { beforeEach(() => { - wrapper = createComponent(); + wrapper = createComponent({ + pipelineData: { status: CI_CONFIG_STATUS_VALID, stages: [{ name: 'hello', groups: [] }] }, + }); }); it('renders the graph with no status error', () => { - expect(findAlert().text()).not.toBe(wrapper.vm.$options.warningTexts[INVALID_CI_CONFIG]); + expect(findAlert().exists()).toBe(false); expect(findPipelineGraph().exists()).toBe(true); }); }); - describe('with error while rendering the links', () => { + describe('with error while rendering the links with needs', () => { beforeEach(() => { wrapper = createComponent(); }); diff --git a/spec/frontend/pipelines/pipeline_graph/utils_spec.js b/spec/frontend/pipelines/pipeline_graph/utils_spec.js index 12154df6fcf..070d3bf7dac 100644 --- a/spec/frontend/pipelines/pipeline_graph/utils_spec.js +++ b/spec/frontend/pipelines/pipeline_graph/utils_spec.js @@ -68,10 +68,10 @@ describe('utils functions', () => { it('returns a hash with the jobname as key and all its data as value', () => { const jobs = { - [jobName1]: job1, - [jobName2]: job2, - [jobName3]: job3, - [jobName4]: job4, + [jobName1]: { jobs: [job1], name: jobName1, needs: [] }, + [jobName2]: { jobs: [job2], name: jobName2, needs: [] }, + [jobName3]: { jobs: [job3], name: jobName3, needs: job3.needs }, + [jobName4]: { jobs: [job4], name: jobName4, needs: job4.needs }, }; expect(createJobsHash(pipelineGraphData.stages)).toEqual(jobs); @@ -110,5 +110,41 @@ describe('utils functions', () => { [jobName4]: [jobName3, jobName1, jobName2], }); }); + + it('handles parallel jobs by adding the group name as a need', () => { + const size = 3; + const jobOptimize1 = 'optimize_1'; + const jobPrepareA = 'prepare_a'; + const jobPrepareA1 = `${jobPrepareA} 1/${size}`; + const jobPrepareA2 = `${jobPrepareA} 2/${size}`; + const jobPrepareA3 = `${jobPrepareA} 3/${size}`; + + const jobsParallel = { + [jobOptimize1]: { + jobs: [job1], + name: [jobOptimize1], + needs: [jobPrepareA1, jobPrepareA2, jobPrepareA3], + }, + [jobPrepareA]: { jobs: [], name: jobPrepareA, needs: [], size }, + [jobPrepareA1]: { jobs: [], name: jobPrepareA, needs: [], size }, + [jobPrepareA2]: { jobs: [], name: jobPrepareA, needs: [], size }, + [jobPrepareA3]: { jobs: [], name: jobPrepareA, needs: [], size }, + }; + + expect(generateJobNeedsDict(jobsParallel)).toEqual({ + [jobOptimize1]: [ + jobPrepareA1, + // This is the important part, the `jobPrepareA` group name has been + // added to our list of needs. + jobPrepareA, + jobPrepareA2, + jobPrepareA3, + ], + [jobPrepareA]: [], + [jobPrepareA1]: [], + [jobPrepareA2]: [], + [jobPrepareA3]: [], + }); + }); }); }); |