diff options
Diffstat (limited to 'spec/frontend/ci/pipeline_editor/components/job_assistant_drawer/job_assistant_drawer_spec.js')
-rw-r--r-- | spec/frontend/ci/pipeline_editor/components/job_assistant_drawer/job_assistant_drawer_spec.js | 147 |
1 files changed, 128 insertions, 19 deletions
diff --git a/spec/frontend/ci/pipeline_editor/components/job_assistant_drawer/job_assistant_drawer_spec.js b/spec/frontend/ci/pipeline_editor/components/job_assistant_drawer/job_assistant_drawer_spec.js index b293805d653..08aa7e3a11a 100644 --- a/spec/frontend/ci/pipeline_editor/components/job_assistant_drawer/job_assistant_drawer_spec.js +++ b/spec/frontend/ci/pipeline_editor/components/job_assistant_drawer/job_assistant_drawer_spec.js @@ -5,13 +5,16 @@ import { stringify } from 'yaml'; import JobAssistantDrawer from '~/ci/pipeline_editor/components/job_assistant_drawer/job_assistant_drawer.vue'; import JobSetupItem from '~/ci/pipeline_editor/components/job_assistant_drawer/accordion_items/job_setup_item.vue'; import ImageItem from '~/ci/pipeline_editor/components/job_assistant_drawer/accordion_items/image_item.vue'; -import getAllRunners from '~/ci/runner/graphql/list/all_runners.query.graphql'; +import ArtifactsAndCacheItem from '~/ci/pipeline_editor/components/job_assistant_drawer/accordion_items/artifacts_and_cache_item.vue'; +import RulesItem from '~/ci/pipeline_editor/components/job_assistant_drawer/accordion_items/rules_item.vue'; +import { JOB_RULES_WHEN } from '~/ci/pipeline_editor/components/job_assistant_drawer/constants'; +import getRunnerTags from '~/ci/pipeline_editor/graphql/queries/runner_tags.query.graphql'; import createMockApollo from 'helpers/mock_apollo_helper'; import waitForPromises from 'helpers/wait_for_promises'; -import createStore from '~/ci/pipeline_editor/store'; -import { mockAllRunnersQueryResponse } from 'jest/ci/pipeline_editor/mock_data'; + import { mountExtended } from 'helpers/vue_test_utils_helper'; import eventHub, { SCROLL_EDITOR_TO_BOTTOM } from '~/ci/pipeline_editor/event_hub'; +import { mockRunnersTagsQueryResponse, mockLintResponse, mockCiYml } from '../../mock_data'; Vue.use(VueApollo); @@ -23,22 +26,32 @@ describe('Job assistant drawer', () => { const dummyJobScript = 'b'; const dummyImageName = 'c'; const dummyImageEntrypoint = 'd'; + const dummyArtifactsPath = 'e'; + const dummyArtifactsExclude = 'f'; + const dummyCachePath = 'g'; + const dummyCacheKey = 'h'; + const dummyRulesWhen = JOB_RULES_WHEN.delayed.value; + const dummyRulesStartIn = '1 second'; + const dummyRulesAllowFailure = true; const findDrawer = () => wrapper.findComponent(GlDrawer); const findJobSetupItem = () => wrapper.findComponent(JobSetupItem); const findImageItem = () => wrapper.findComponent(ImageItem); + const findArtifactsAndCacheItem = () => wrapper.findComponent(ArtifactsAndCacheItem); + const findRulesItem = () => wrapper.findComponent(RulesItem); const findConfirmButton = () => wrapper.findByTestId('confirm-button'); const findCancelButton = () => wrapper.findByTestId('cancel-button'); const createComponent = () => { mockApollo = createMockApollo([ - [getAllRunners, jest.fn().mockResolvedValue(mockAllRunnersQueryResponse)], + [getRunnerTags, jest.fn().mockResolvedValue(mockRunnersTagsQueryResponse)], ]); wrapper = mountExtended(JobAssistantDrawer, { - store: createStore(), propsData: { + ciConfigData: mockLintResponse, + ciFileContent: mockCiYml, isVisible: true, }, apolloProvider: mockApollo, @@ -54,10 +67,27 @@ describe('Job assistant drawer', () => { expect(findJobSetupItem().exists()).toBe(true); }); + it('job setup item should have tag options', () => { + expect(findJobSetupItem().props('tagOptions')).toEqual([ + { id: 'tag1', name: 'tag1' }, + { id: 'tag2', name: 'tag2' }, + { id: 'tag3', name: 'tag3' }, + { id: 'tag4', name: 'tag4' }, + ]); + }); + it('should contain image accordion', () => { expect(findImageItem().exists()).toBe(true); }); + it('should contain artifacts and cache item accordion', () => { + expect(findArtifactsAndCacheItem().exists()).toBe(true); + }); + + it('should contain rules accordion', () => { + expect(findRulesItem().exists()).toBe(true); + }); + it('should emit close job assistant drawer event when closing the drawer', () => { expect(wrapper.emitted('close-job-assistant-drawer')).toBeUndefined(); @@ -74,8 +104,7 @@ describe('Job assistant drawer', () => { expect(wrapper.emitted('close-job-assistant-drawer')).toHaveLength(1); }); - it('trigger validate if job name is empty', async () => { - const updateCiConfigSpy = jest.spyOn(wrapper.vm, 'updateCiConfig'); + it('should block submit if job name is empty', async () => { findJobSetupItem().vm.$emit('update-job', 'script', 'b'); findConfirmButton().trigger('click'); @@ -83,7 +112,17 @@ describe('Job assistant drawer', () => { expect(findJobSetupItem().props('isNameValid')).toBe(false); expect(findJobSetupItem().props('isScriptValid')).toBe(true); - expect(updateCiConfigSpy).toHaveBeenCalledTimes(0); + expect(wrapper.emitted('updateCiConfig')).toBeUndefined(); + }); + + it('should block submit if rules when is delayed and start in is out of range', async () => { + findRulesItem().vm.$emit('update-job', 'rules[0].when', JOB_RULES_WHEN.delayed.value); + findRulesItem().vm.$emit('update-job', 'rules[0].start_in', '2 weeks'); + findConfirmButton().trigger('click'); + + await nextTick(); + + expect(wrapper.emitted('updateCiConfig')).toBeUndefined(); }); describe('when enter valid input', () => { @@ -92,10 +131,24 @@ describe('Job assistant drawer', () => { findJobSetupItem().vm.$emit('update-job', 'script', dummyJobScript); findImageItem().vm.$emit('update-job', 'image.name', dummyImageName); findImageItem().vm.$emit('update-job', 'image.entrypoint', [dummyImageEntrypoint]); + findArtifactsAndCacheItem().vm.$emit('update-job', 'artifacts.paths', [dummyArtifactsPath]); + findArtifactsAndCacheItem().vm.$emit('update-job', 'artifacts.exclude', [ + dummyArtifactsExclude, + ]); + findArtifactsAndCacheItem().vm.$emit('update-job', 'cache.paths', [dummyCachePath]); + findArtifactsAndCacheItem().vm.$emit('update-job', 'cache.key', dummyCacheKey); + findRulesItem().vm.$emit('update-job', 'rules[0].allow_failure', dummyRulesAllowFailure); + findRulesItem().vm.$emit('update-job', 'rules[0].when', dummyRulesWhen); + findRulesItem().vm.$emit('update-job', 'rules[0].start_in', dummyRulesStartIn); }); it('passes correct prop to accordions', () => { - const accordions = [findJobSetupItem(), findImageItem()]; + const accordions = [ + findJobSetupItem(), + findImageItem(), + findArtifactsAndCacheItem(), + findRulesItem(), + ]; accordions.forEach((accordion) => { expect(accordion.props('job')).toMatchObject({ name: dummyJobName, @@ -104,6 +157,21 @@ describe('Job assistant drawer', () => { name: dummyImageName, entrypoint: [dummyImageEntrypoint], }, + artifacts: { + paths: [dummyArtifactsPath], + exclude: [dummyArtifactsExclude], + }, + cache: { + paths: [dummyCachePath], + key: dummyCacheKey, + }, + rules: [ + { + allow_failure: dummyRulesAllowFailure, + when: dummyRulesWhen, + start_in: dummyRulesStartIn, + }, + ], }); }); }); @@ -129,19 +197,60 @@ describe('Job assistant drawer', () => { expect(findJobSetupItem().props('job')).toMatchObject({ name: '', script: '' }); }); - it('should update correct ci content when click add button', () => { - const updateCiConfigSpy = jest.spyOn(wrapper.vm, 'updateCiConfig'); + it('should omit keys with default value when click add button', () => { + findRulesItem().vm.$emit('update-job', 'rules[0].allow_failure', false); + findRulesItem().vm.$emit('update-job', 'rules[0].when', JOB_RULES_WHEN.onSuccess.value); + findRulesItem().vm.$emit('update-job', 'rules[0].start_in', dummyRulesStartIn); + findConfirmButton().trigger('click'); + + expect(wrapper.emitted('updateCiConfig')).toStrictEqual([ + [ + `${wrapper.props('ciFileContent')}\n${stringify({ + [dummyJobName]: { + script: dummyJobScript, + image: { name: dummyImageName, entrypoint: [dummyImageEntrypoint] }, + artifacts: { + paths: [dummyArtifactsPath], + exclude: [dummyArtifactsExclude], + }, + cache: { + paths: [dummyCachePath], + key: dummyCacheKey, + }, + }, + })}`, + ], + ]); + }); + it('should update correct ci content when click add button', () => { findConfirmButton().trigger('click'); - expect(updateCiConfigSpy).toHaveBeenCalledWith( - `\n${stringify({ - [dummyJobName]: { - script: dummyJobScript, - image: { name: dummyImageName, entrypoint: [dummyImageEntrypoint] }, - }, - })}`, - ); + expect(wrapper.emitted('updateCiConfig')).toStrictEqual([ + [ + `${wrapper.props('ciFileContent')}\n${stringify({ + [dummyJobName]: { + script: dummyJobScript, + image: { name: dummyImageName, entrypoint: [dummyImageEntrypoint] }, + artifacts: { + paths: [dummyArtifactsPath], + exclude: [dummyArtifactsExclude], + }, + cache: { + paths: [dummyCachePath], + key: dummyCacheKey, + }, + rules: [ + { + allow_failure: dummyRulesAllowFailure, + when: dummyRulesWhen, + start_in: dummyRulesStartIn, + }, + ], + }, + })}`, + ], + ]); }); it('should emit scroll editor to button event when click add button', () => { |