diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-04-03 21:08:58 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-04-03 21:08:58 +0300 |
commit | 7c8468c5ba828e1c1afe6ba0b25c77c130a69413 (patch) | |
tree | 3104d62bff9040a19756b9d407003eed14314f77 /spec/frontend/ci | |
parent | 2a7fd3827b0838a900399b0c3440942cdaa09c75 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend/ci')
2 files changed, 126 insertions, 1 deletions
diff --git a/spec/frontend/ci/pipeline_editor/components/job_assistant_drawer/accordion_items/rules_item_spec.js b/spec/frontend/ci/pipeline_editor/components/job_assistant_drawer/accordion_items/rules_item_spec.js new file mode 100644 index 00000000000..659ccb25996 --- /dev/null +++ b/spec/frontend/ci/pipeline_editor/components/job_assistant_drawer/accordion_items/rules_item_spec.js @@ -0,0 +1,70 @@ +import RulesItem from '~/ci/pipeline_editor/components/job_assistant_drawer/accordion_items/rules_item.vue'; +import { shallowMountExtended } from 'helpers/vue_test_utils_helper'; +import { + JOB_TEMPLATE, + JOB_RULES_WHEN, + JOB_RULES_START_IN, +} from '~/ci/pipeline_editor/components/job_assistant_drawer/constants'; + +describe('Rules item', () => { + let wrapper; + + const findRulesWhenSelect = () => wrapper.findByTestId('rules-when-select'); + const findRulesStartInNumberInput = () => wrapper.findByTestId('rules-start-in-number-input'); + const findRulesStartInUnitSelect = () => wrapper.findByTestId('rules-start-in-unit-select'); + const findRulesAllowFailureCheckBox = () => wrapper.findByTestId('rules-allow-failure-checkbox'); + + const dummyRulesWhen = JOB_RULES_WHEN.delayed.value; + const dummyRulesStartInNumber = 2; + const dummyRulesStartInUnit = JOB_RULES_START_IN.week.value; + const dummyRulesAllowFailure = true; + + const createComponent = () => { + wrapper = shallowMountExtended(RulesItem, { + propsData: { + isStartValid: true, + job: JSON.parse(JSON.stringify(JOB_TEMPLATE)), + }, + }); + }; + + beforeEach(() => { + createComponent(); + }); + + it('should emit update job event when filling inputs', () => { + expect(wrapper.emitted('update-job')).toBeUndefined(); + + findRulesWhenSelect().vm.$emit('input', dummyRulesWhen); + + expect(wrapper.emitted('update-job')).toHaveLength(1); + expect(wrapper.emitted('update-job')[0]).toEqual([ + 'rules[0].when', + JOB_RULES_WHEN.delayed.value, + ]); + + findRulesStartInNumberInput().vm.$emit('input', dummyRulesStartInNumber); + + expect(wrapper.emitted('update-job')).toHaveLength(2); + expect(wrapper.emitted('update-job')[1]).toEqual([ + 'rules[0].start_in', + `2 ${JOB_RULES_START_IN.second.value}s`, + ]); + + findRulesStartInUnitSelect().vm.$emit('input', dummyRulesStartInUnit); + + expect(wrapper.emitted('update-job')).toHaveLength(3); + expect(wrapper.emitted('update-job')[2]).toEqual([ + 'rules[0].start_in', + `2 ${dummyRulesStartInUnit}s`, + ]); + + findRulesAllowFailureCheckBox().vm.$emit('input', dummyRulesAllowFailure); + + expect(wrapper.emitted('update-job')).toHaveLength(4); + expect(wrapper.emitted('update-job')[3]).toEqual([ + 'rules[0].allow_failure', + dummyRulesAllowFailure, + ]); + }); +}); 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 356de5b11e9..e03cd19da65 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,6 +5,8 @@ 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 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'; @@ -23,10 +25,14 @@ describe('Job assistant drawer', () => { const dummyJobScript = 'b'; const dummyImageName = 'c'; const dummyImageEntrypoint = 'd'; + 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 findRulesItem = () => wrapper.findComponent(RulesItem); const findConfirmButton = () => wrapper.findByTestId('confirm-button'); const findCancelButton = () => wrapper.findByTestId('cancel-button'); @@ -68,6 +74,10 @@ describe('Job assistant drawer', () => { expect(findImageItem().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(); @@ -84,7 +94,7 @@ describe('Job assistant drawer', () => { expect(wrapper.emitted('close-job-assistant-drawer')).toHaveLength(1); }); - it('trigger validate if job name is empty', async () => { + it('should block submit if job name is empty', async () => { findJobSetupItem().vm.$emit('update-job', 'script', 'b'); findConfirmButton().trigger('click'); @@ -95,12 +105,25 @@ describe('Job assistant drawer', () => { 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', () => { beforeEach(() => { findJobSetupItem().vm.$emit('update-job', 'name', dummyJobName); findJobSetupItem().vm.$emit('update-job', 'script', dummyJobScript); findImageItem().vm.$emit('update-job', 'image.name', dummyImageName); findImageItem().vm.$emit('update-job', 'image.entrypoint', [dummyImageEntrypoint]); + 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', () => { @@ -113,6 +136,13 @@ describe('Job assistant drawer', () => { name: dummyImageName, entrypoint: [dummyImageEntrypoint], }, + rules: [ + { + allow_failure: dummyRulesAllowFailure, + when: dummyRulesWhen, + start_in: dummyRulesStartIn, + }, + ], }); }); }); @@ -138,6 +168,24 @@ describe('Job assistant drawer', () => { expect(findJobSetupItem().props('job')).toMatchObject({ name: '', script: '' }); }); + 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] }, + }, + })}`, + ], + ]); + }); + it('should update correct ci content when click add button', () => { findConfirmButton().trigger('click'); @@ -147,6 +195,13 @@ describe('Job assistant drawer', () => { [dummyJobName]: { script: dummyJobScript, image: { name: dummyImageName, entrypoint: [dummyImageEntrypoint] }, + rules: [ + { + allow_failure: dummyRulesAllowFailure, + when: dummyRulesWhen, + start_in: dummyRulesStartIn, + }, + ], }, })}`, ], |