diff options
Diffstat (limited to 'spec/frontend/import_entities/import_projects/components')
3 files changed, 100 insertions, 4 deletions
diff --git a/spec/frontend/import_entities/import_projects/components/advanced_settings_spec.js b/spec/frontend/import_entities/import_projects/components/advanced_settings_spec.js new file mode 100644 index 00000000000..68716600592 --- /dev/null +++ b/spec/frontend/import_entities/import_projects/components/advanced_settings_spec.js @@ -0,0 +1,60 @@ +import { mount } from '@vue/test-utils'; +import { GlFormCheckbox } from '@gitlab/ui'; +import AdvancedSettingsPanel from '~/import_entities/import_projects/components/advanced_settings.vue'; + +describe('Import Advanced Settings', () => { + let wrapper; + const OPTIONAL_STAGES = [ + { name: 'stage1', label: 'Stage 1' }, + { name: 'stage2', label: 'Stage 2', details: 'Extra details' }, + ]; + + const createComponent = () => { + wrapper = mount(AdvancedSettingsPanel, { + propsData: { + stages: OPTIONAL_STAGES, + value: { + stage1: false, + stage2: false, + }, + }, + }); + }; + + beforeEach(() => { + createComponent(); + }); + + afterEach(() => { + wrapper.destroy(); + }); + + it('renders GLFormCheckbox for each optional stage', () => { + expect(wrapper.findAllComponents(GlFormCheckbox)).toHaveLength(OPTIONAL_STAGES.length); + }); + + it('renders label for each optional stage', () => { + wrapper.findAllComponents(GlFormCheckbox).wrappers.forEach((w, idx) => { + expect(w.text()).toContain(OPTIONAL_STAGES[idx].label); + }); + }); + + it('renders details for stage with details', () => { + expect(wrapper.findAllComponents(GlFormCheckbox).at(1).text()).toContain( + OPTIONAL_STAGES[1].details, + ); + }); + + it('emits new stages selection state when checkbox is changed', () => { + const firstCheckbox = wrapper.findComponent(GlFormCheckbox); + + firstCheckbox.vm.$emit('change', true); + + expect(wrapper.emitted('input')[0]).toStrictEqual([ + { + stage1: true, + stage2: false, + }, + ]); + }); +}); diff --git a/spec/frontend/import_entities/import_projects/components/import_projects_table_spec.js b/spec/frontend/import_entities/import_projects/components/import_projects_table_spec.js index c0ae4294e3d..53807167fe8 100644 --- a/spec/frontend/import_entities/import_projects/components/import_projects_table_spec.js +++ b/spec/frontend/import_entities/import_projects/components/import_projects_table_spec.js @@ -5,6 +5,7 @@ import Vuex from 'vuex'; import { STATUSES } from '~/import_entities/constants'; import ImportProjectsTable from '~/import_entities/import_projects/components/import_projects_table.vue'; import ProviderRepoTableRow from '~/import_entities/import_projects/components/provider_repo_table_row.vue'; +import AdvancedSettingsPanel from '~/import_entities/import_projects/components/advanced_settings.vue'; import * as getters from '~/import_entities/import_projects/store/getters'; import state from '~/import_entities/import_projects/store/state'; @@ -45,6 +46,7 @@ describe('ImportProjectsTable', () => { slots, filterable, paginatable, + optionalStages, } = {}) { Vue.use(Vuex); @@ -71,6 +73,7 @@ describe('ImportProjectsTable', () => { providerTitle, filterable, paginatable, + optionalStages, }, slots, stubs: { @@ -271,4 +274,23 @@ describe('ImportProjectsTable', () => { expect(wrapper.text().includes(INCOMPATIBLE_TEXT)).toBe(shouldRenderSlot); }, ); + + it('should not render advanced settings panel when no optional steps are passed', () => { + createComponent({ state: { providerRepos: [providerRepo] } }); + + expect(wrapper.findComponent(AdvancedSettingsPanel).exists()).toBe(false); + }); + + it('should render advanced settings panel when no optional steps are passed', () => { + const OPTIONAL_STAGES = [{ name: 'step1', label: 'Step 1' }]; + createComponent({ state: { providerRepos: [providerRepo] }, optionalStages: OPTIONAL_STAGES }); + + expect(wrapper.findComponent(AdvancedSettingsPanel).exists()).toBe(true); + expect(wrapper.findComponent(AdvancedSettingsPanel).props('stages')).toStrictEqual( + OPTIONAL_STAGES, + ); + expect(wrapper.findComponent(AdvancedSettingsPanel).props('value')).toStrictEqual({ + step1: false, + }); + }); }); diff --git a/spec/frontend/import_entities/import_projects/components/provider_repo_table_row_spec.js b/spec/frontend/import_entities/import_projects/components/provider_repo_table_row_spec.js index 17a07b1e9f9..40934e90b78 100644 --- a/spec/frontend/import_entities/import_projects/components/provider_repo_table_row_spec.js +++ b/spec/frontend/import_entities/import_projects/components/provider_repo_table_row_spec.js @@ -44,7 +44,7 @@ describe('ProviderRepoTableRow', () => { wrapper = shallowMount(ProviderRepoTableRow, { store, - propsData: { availableNamespaces, userNamespace, ...props }, + propsData: { availableNamespaces, userNamespace, optionalStages: {}, ...props }, }); } @@ -92,10 +92,24 @@ describe('ProviderRepoTableRow', () => { await nextTick(); - const { calls } = fetchImport.mock; + expect(fetchImport).toHaveBeenCalledWith(expect.anything(), { + repoId: repo.importSource.id, + optionalStages: {}, + }); + }); + + it('includes optionalStages to import', async () => { + const OPTIONAL_STAGES = { stage1: true, stage2: false }; + await wrapper.setProps({ optionalStages: OPTIONAL_STAGES }); + + findImportButton().vm.$emit('click'); + + await nextTick(); - expect(calls).toHaveLength(1); - expect(calls[0][1]).toBe(repo.importSource.id); + expect(fetchImport).toHaveBeenCalledWith(expect.anything(), { + repoId: repo.importSource.id, + optionalStages: OPTIONAL_STAGES, + }); }); }); |