From c1f98d9590def61ad2fca09cc06a7a9d52cdebc5 Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Thu, 16 Feb 2023 15:07:53 +0000 Subject: Add latest changes from gitlab-org/gitlab@master --- .../import_groups/components/import_table_spec.js | 1 + .../components/provider_repo_table_row_spec.js | 67 ++++++++++++++++++++-- .../import_projects/store/mutations_spec.js | 26 ++++----- .../import_entities/import_projects/utils_spec.js | 2 +- 4 files changed, 74 insertions(+), 22 deletions(-) (limited to 'spec/frontend/import_entities') diff --git a/spec/frontend/import_entities/import_groups/components/import_table_spec.js b/spec/frontend/import_entities/import_groups/components/import_table_spec.js index 00b69948bfb..c7bda5a60ec 100644 --- a/spec/frontend/import_entities/import_groups/components/import_table_spec.js +++ b/spec/frontend/import_entities/import_groups/components/import_table_spec.js @@ -40,6 +40,7 @@ describe('import table', () => { generateFakeEntry({ id: 2, status: STATUSES.FINISHED }), generateFakeEntry({ id: 3, status: STATUSES.NONE }), ]; + const FAKE_PAGE_INFO = { page: 1, perPage: 20, total: 40, totalPages: 2 }; const FAKE_VERSION_VALIDATION = { features: { 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 d686036781f..e613b9756af 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 @@ -1,4 +1,4 @@ -import { GlBadge, GlButton, GlDropdown } from '@gitlab/ui'; +import { GlBadge, GlButton } from '@gitlab/ui'; import { shallowMount } from '@vue/test-utils'; import Vue, { nextTick } from 'vue'; import Vuex from 'vuex'; @@ -31,12 +31,16 @@ describe('ProviderRepoTableRow', () => { return store; } - const findImportButton = () => { - const buttons = wrapper.findAllComponents(GlButton).filter((node) => node.text() === 'Import'); + const findButton = (text) => { + const buttons = wrapper.findAllComponents(GlButton).filter((node) => node.text() === text); return buttons.length ? buttons.at(0) : buttons; }; + const findImportButton = () => findButton('Import'); + const findReimportButton = () => findButton('Re-import'); + const findGroupDropdown = () => wrapper.findComponent(ImportGroupDropdown); + const findCancelButton = () => { const buttons = wrapper .findAllComponents(GlButton) @@ -117,6 +121,10 @@ describe('ProviderRepoTableRow', () => { optionalStages: OPTIONAL_STAGES, }); }); + + it('does not render re-import button', () => { + expect(findReimportButton().exists()).toBe(false); + }); }); describe('when rendering importing project', () => { @@ -200,19 +208,68 @@ describe('ProviderRepoTableRow', () => { ); }); - it('does not renders a namespace select', () => { - expect(wrapper.findComponent(GlDropdown).exists()).toBe(false); + it('does not render a namespace select', () => { + expect(findGroupDropdown().exists()).toBe(false); }); it('does not render import button', () => { expect(findImportButton().exists()).toBe(false); }); + it('renders re-import button', () => { + expect(findReimportButton().exists()).toBe(true); + }); + + it('renders namespace select after clicking re-import', async () => { + findReimportButton().vm.$emit('click'); + + await nextTick(); + + expect(findGroupDropdown().exists()).toBe(true); + }); + + it('imports repo when clicking re-import button', async () => { + findReimportButton().vm.$emit('click'); + + await nextTick(); + + findReimportButton().vm.$emit('click'); + + expect(fetchImport).toHaveBeenCalledWith(expect.anything(), { + repoId: repo.importSource.id, + optionalStages: {}, + }); + }); + it('passes stats to import status component', () => { expect(wrapper.findComponent(ImportStatus).props().stats).toBe(FAKE_STATS); }); }); + describe('when rendering failed project', () => { + const repo = { + importSource: { + id: 'remote-1', + fullName: 'fullName', + providerLink: 'providerLink', + }, + importedProject: { + id: 1, + fullPath: 'fullPath', + importSource: 'importSource', + importStatus: STATUSES.FAILED, + }, + }; + + beforeEach(() => { + mountComponent({ repo }); + }); + + it('render import button', () => { + expect(findImportButton().exists()).toBe(true); + }); + }); + describe('when rendering incompatible project', () => { const repo = { importSource: { diff --git a/spec/frontend/import_entities/import_projects/store/mutations_spec.js b/spec/frontend/import_entities/import_projects/store/mutations_spec.js index 7884e9b4307..514a168553a 100644 --- a/spec/frontend/import_entities/import_projects/store/mutations_spec.js +++ b/spec/frontend/import_entities/import_projects/store/mutations_spec.js @@ -8,14 +8,14 @@ describe('import_projects store mutations', () => { const SOURCE_PROJECT = { id: 1, - full_name: 'full/name', - sanitized_name: 'name', - provider_link: 'https://demo.link/full/name', + fullName: 'full/name', + sanitizedName: 'name', + providerLink: 'https://demo.link/full/name', }; const IMPORTED_PROJECT = { name: 'demo', importSource: 'something', - providerLink: 'custom-link', + providerLink: 'https://demo.link/full/name', importStatus: 'status', fullName: 'fullName', }; @@ -64,21 +64,15 @@ describe('import_projects store mutations', () => { describe('for imported projects', () => { const response = { importedProjects: [IMPORTED_PROJECT], - providerRepos: [], + providerRepos: [SOURCE_PROJECT], }; - it('recreates importSource from response', () => { + it('adds importedProject to relevant provider repo', () => { state = getInitialState(); mutations[types.RECEIVE_REPOS_SUCCESS](state, response); - expect(state.repositories[0].importSource).toStrictEqual( - expect.objectContaining({ - fullName: IMPORTED_PROJECT.importSource, - sanitizedName: IMPORTED_PROJECT.name, - providerLink: IMPORTED_PROJECT.providerLink, - }), - ); + expect(state.repositories[0].importedProject).toStrictEqual(IMPORTED_PROJECT); }); it('passes project to importProject', () => { @@ -216,13 +210,13 @@ describe('import_projects store mutations', () => { describe(`${types.RECEIVE_IMPORT_ERROR}`, () => { beforeEach(() => { const REPO_ID = 1; - state = { repositories: [{ importSource: { id: REPO_ID } }] }; + state = { repositories: [{ importSource: { id: REPO_ID }, importedProject: {} }] }; mutations[types.RECEIVE_IMPORT_ERROR](state, REPO_ID); }); - it(`removes importedProject entry`, () => { - expect(state.repositories[0].importedProject).toBeNull(); + it('sets status to failed', () => { + expect(state.repositories[0].importedProject.importStatus).toBe(STATUSES.FAILED); }); }); diff --git a/spec/frontend/import_entities/import_projects/utils_spec.js b/spec/frontend/import_entities/import_projects/utils_spec.js index d705f0acbfe..42cdf0f5a19 100644 --- a/spec/frontend/import_entities/import_projects/utils_spec.js +++ b/spec/frontend/import_entities/import_projects/utils_spec.js @@ -19,7 +19,7 @@ describe('import_projects utils', () => { it.each` status | result ${STATUSES.FINISHED} | ${false} - ${STATUSES.FAILED} | ${false} + ${STATUSES.FAILED} | ${true} ${STATUSES.SCHEDULED} | ${false} ${STATUSES.STARTED} | ${false} ${STATUSES.NONE} | ${true} -- cgit v1.2.1