diff options
Diffstat (limited to 'spec/frontend/import_entities/import_projects')
4 files changed, 119 insertions, 15 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, + }); }); }); diff --git a/spec/frontend/import_entities/import_projects/store/actions_spec.js b/spec/frontend/import_entities/import_projects/store/actions_spec.js index 0ebe8525b5a..e154863f339 100644 --- a/spec/frontend/import_entities/import_projects/store/actions_spec.js +++ b/spec/frontend/import_entities/import_projects/store/actions_spec.js @@ -1,7 +1,7 @@ import MockAdapter from 'axios-mock-adapter'; import { TEST_HOST } from 'helpers/test_constants'; import testAction from 'helpers/vuex_action_helper'; -import createFlash from '~/flash'; +import { createAlert } from '~/flash'; import { STATUSES } from '~/import_entities/constants'; import actionsFactory from '~/import_entities/import_projects/store/actions'; import { getImportTarget } from '~/import_entities/import_projects/store/getters'; @@ -155,7 +155,7 @@ describe('import_projects store actions', () => { [], ); - expect(createFlash).toHaveBeenCalledWith({ + expect(createAlert).toHaveBeenCalledWith({ message: 'Provider rate limit exceeded. Try again later', }); }); @@ -198,7 +198,7 @@ describe('import_projects store actions', () => { return testAction( fetchImport, - importRepoId, + { repoId: importRepoId, optionalStages: {} }, localState, [ { @@ -222,7 +222,7 @@ describe('import_projects store actions', () => { await testAction( fetchImport, - importRepoId, + { repoId: importRepoId, optionalStages: {} }, localState, [ { @@ -234,7 +234,7 @@ describe('import_projects store actions', () => { [], ); - expect(createFlash).toHaveBeenCalledWith({ + expect(createAlert).toHaveBeenCalledWith({ message: 'Importing the project failed', }); }); @@ -245,7 +245,7 @@ describe('import_projects store actions', () => { await testAction( fetchImport, - importRepoId, + { repoId: importRepoId, optionalStages: {} }, localState, [ { @@ -257,7 +257,7 @@ describe('import_projects store actions', () => { [], ); - expect(createFlash).toHaveBeenCalledWith({ + expect(createAlert).toHaveBeenCalledWith({ message: `Importing the project failed: ${ERROR_MESSAGE}`, }); }); @@ -358,7 +358,7 @@ describe('import_projects store actions', () => { [], ); - expect(createFlash).toHaveBeenCalledWith({ + expect(createAlert).toHaveBeenCalledWith({ message: 'Requesting namespaces failed', }); }); @@ -366,14 +366,22 @@ describe('import_projects store actions', () => { describe('importAll', () => { it('dispatches multiple fetchImport actions', async () => { + const OPTIONAL_STAGES = { stage1: true, stage2: false }; + await testAction( importAll, - null, + { optionalStages: OPTIONAL_STAGES }, localState, [], [ - { type: 'fetchImport', payload: importRepoId }, - { type: 'fetchImport', payload: otherImportRepoId }, + { + type: 'fetchImport', + payload: { repoId: importRepoId, optionalStages: OPTIONAL_STAGES }, + }, + { + type: 'fetchImport', + payload: { repoId: otherImportRepoId, optionalStages: OPTIONAL_STAGES }, + }, ], ); }); |