diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-04-27 06:09:18 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-04-27 06:09:18 +0300 |
commit | 0e1350d51ca2135e37743dfb7af98eae43c72892 (patch) | |
tree | 10a5c3f27cebc539b5b8fe42d4907aec767949b1 /spec/frontend/ci/pipeline_editor | |
parent | 417ef56d244c6c22016fda7c78e69071d14887c3 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend/ci/pipeline_editor')
2 files changed, 118 insertions, 8 deletions
diff --git a/spec/frontend/ci/pipeline_editor/components/job_assistant_drawer/accordion_items/services_item_spec.js b/spec/frontend/ci/pipeline_editor/components/job_assistant_drawer/accordion_items/services_item_spec.js new file mode 100644 index 00000000000..07b3526f5fa --- /dev/null +++ b/spec/frontend/ci/pipeline_editor/components/job_assistant_drawer/accordion_items/services_item_spec.js @@ -0,0 +1,79 @@ +import ServicesItem from '~/ci/pipeline_editor/components/job_assistant_drawer/accordion_items/services_item.vue'; +import { shallowMountExtended } from 'helpers/vue_test_utils_helper'; +import { JOB_TEMPLATE } from '~/ci/pipeline_editor/components/job_assistant_drawer/constants'; + +describe('Services item', () => { + let wrapper; + + const findServiceNameInputByIndex = (index) => + wrapper.findByTestId(`service-name-input-${index}`); + const findServiceEntrypointInputByIndex = (index) => + wrapper.findByTestId(`service-entrypoint-input-${index}`); + const findDeleteItemButtonByIndex = (index) => + wrapper.findByTestId(`delete-job-service-button-${index}`); + const findAddItemButton = () => wrapper.findByTestId('add-job-service-button'); + + const dummyServiceName = 'a'; + const dummyServiceEntrypoint = ['b', 'c']; + + const createComponent = ({ job = JSON.parse(JSON.stringify(JOB_TEMPLATE)) } = {}) => { + wrapper = shallowMountExtended(ServicesItem, { + propsData: { + job, + }, + }); + }; + + it('should emit update job event when filling inputs', () => { + createComponent(); + + expect(wrapper.emitted('update-job')).toBeUndefined(); + + findServiceNameInputByIndex(0).vm.$emit('input', dummyServiceName); + + expect(wrapper.emitted('update-job')).toHaveLength(1); + expect(wrapper.emitted('update-job')[0]).toEqual(['services[0].name', dummyServiceName]); + + findServiceEntrypointInputByIndex(0).vm.$emit('input', dummyServiceEntrypoint.join(',')); + + expect(wrapper.emitted('update-job')).toHaveLength(2); + expect(wrapper.emitted('update-job')[1]).toEqual([ + 'services[0].entrypoint', + dummyServiceEntrypoint, + ]); + }); + + it('should emit update job event when click add item button', () => { + createComponent(); + + findAddItemButton().vm.$emit('click'); + + expect(wrapper.emitted('update-job')).toHaveLength(1); + expect(wrapper.emitted('update-job')[0]).toEqual([ + 'services[1]', + { name: '', entrypoint: [''] }, + ]); + }); + + it('should emit update job event when click delete item button', () => { + createComponent({ + job: { + services: [ + { name: 'a', entrypoint: ['a'] }, + { name: 'b', entrypoint: ['b'] }, + ], + }, + }); + + findDeleteItemButtonByIndex(0).vm.$emit('click'); + + expect(wrapper.emitted('update-job')).toHaveLength(1); + expect(wrapper.emitted('update-job')[0]).toEqual(['services[0]']); + }); + + it('should not show delete item button when there is only one service', () => { + createComponent(); + + expect(findDeleteItemButtonByIndex(0).exists()).toBe(false); + }); +}); 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 08aa7e3a11a..0258a1a8c7f 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,7 @@ 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 ServicesItem from '~/ci/pipeline_editor/components/job_assistant_drawer/accordion_items/services_item.vue'; 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'; @@ -22,14 +23,16 @@ describe('Job assistant drawer', () => { let wrapper; let mockApollo; - const dummyJobName = 'a'; - const dummyJobScript = 'b'; - const dummyImageName = 'c'; - const dummyImageEntrypoint = 'd'; - const dummyArtifactsPath = 'e'; - const dummyArtifactsExclude = 'f'; - const dummyCachePath = 'g'; - const dummyCacheKey = 'h'; + const dummyJobName = 'dummyJobName'; + const dummyJobScript = 'dummyJobScript'; + const dummyImageName = 'dummyImageName'; + const dummyImageEntrypoint = 'dummyImageEntrypoint'; + const dummyServicesName = 'dummyServicesName'; + const dummyServicesEntrypoint = 'dummyServicesEntrypoint'; + const dummyArtifactsPath = 'dummyArtifactsPath'; + const dummyArtifactsExclude = 'dummyArtifactsExclude'; + const dummyCachePath = 'dummyCachePath'; + const dummyCacheKey = 'dummyCacheKey'; const dummyRulesWhen = JOB_RULES_WHEN.delayed.value; const dummyRulesStartIn = '1 second'; const dummyRulesAllowFailure = true; @@ -37,6 +40,7 @@ describe('Job assistant drawer', () => { const findDrawer = () => wrapper.findComponent(GlDrawer); const findJobSetupItem = () => wrapper.findComponent(JobSetupItem); const findImageItem = () => wrapper.findComponent(ImageItem); + const findServicesItem = () => wrapper.findComponent(ServicesItem); const findArtifactsAndCacheItem = () => wrapper.findComponent(ArtifactsAndCacheItem); const findRulesItem = () => wrapper.findComponent(RulesItem); @@ -80,6 +84,10 @@ describe('Job assistant drawer', () => { expect(findImageItem().exists()).toBe(true); }); + it('should contain services accordion', () => { + expect(findServicesItem().exists()).toBe(true); + }); + it('should contain artifacts and cache item accordion', () => { expect(findArtifactsAndCacheItem().exists()).toBe(true); }); @@ -131,6 +139,10 @@ 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]); + findServicesItem().vm.$emit('update-job', 'services[0].name', dummyServicesName); + findServicesItem().vm.$emit('update-job', 'services[0].entrypoint', [ + dummyServicesEntrypoint, + ]); findArtifactsAndCacheItem().vm.$emit('update-job', 'artifacts.paths', [dummyArtifactsPath]); findArtifactsAndCacheItem().vm.$emit('update-job', 'artifacts.exclude', [ dummyArtifactsExclude, @@ -146,6 +158,7 @@ describe('Job assistant drawer', () => { const accordions = [ findJobSetupItem(), findImageItem(), + findServicesItem(), findArtifactsAndCacheItem(), findRulesItem(), ]; @@ -157,6 +170,12 @@ describe('Job assistant drawer', () => { name: dummyImageName, entrypoint: [dummyImageEntrypoint], }, + services: [ + { + name: dummyServicesName, + entrypoint: [dummyServicesEntrypoint], + }, + ], artifacts: { paths: [dummyArtifactsPath], exclude: [dummyArtifactsExclude], @@ -209,6 +228,12 @@ describe('Job assistant drawer', () => { [dummyJobName]: { script: dummyJobScript, image: { name: dummyImageName, entrypoint: [dummyImageEntrypoint] }, + services: [ + { + name: dummyServicesName, + entrypoint: [dummyServicesEntrypoint], + }, + ], artifacts: { paths: [dummyArtifactsPath], exclude: [dummyArtifactsExclude], @@ -232,6 +257,12 @@ describe('Job assistant drawer', () => { [dummyJobName]: { script: dummyJobScript, image: { name: dummyImageName, entrypoint: [dummyImageEntrypoint] }, + services: [ + { + name: dummyServicesName, + entrypoint: [dummyServicesEntrypoint], + }, + ], artifacts: { paths: [dummyArtifactsPath], exclude: [dummyArtifactsExclude], |