diff options
Diffstat (limited to 'spec/frontend/import_projects/store/getters_spec.js')
-rw-r--r-- | spec/frontend/import_projects/store/getters_spec.js | 140 |
1 files changed, 79 insertions, 61 deletions
diff --git a/spec/frontend/import_projects/store/getters_spec.js b/spec/frontend/import_projects/store/getters_spec.js index 93d1ed89783..5c1ea25a684 100644 --- a/spec/frontend/import_projects/store/getters_spec.js +++ b/spec/frontend/import_projects/store/getters_spec.js @@ -1,12 +1,28 @@ import { - namespaceSelectOptions, + isLoading, isImportingAnyRepo, - hasProviderRepos, hasIncompatibleRepos, - hasImportedProjects, + hasImportableRepos, + getImportTarget, } from '~/import_projects/store/getters'; +import { STATUSES } from '~/import_projects/constants'; import state from '~/import_projects/store/state'; +const IMPORTED_REPO = { + importSource: {}, + importedProject: { fullPath: 'some/path' }, +}; + +const IMPORTABLE_REPO = { + importSource: { id: 'some-id', sanitizedName: 'sanitized' }, + importedProject: null, + importStatus: STATUSES.NONE, +}; + +const INCOMPATIBLE_REPO = { + importSource: { incompatible: true }, +}; + describe('import_projects store getters', () => { let localState; @@ -14,85 +30,87 @@ describe('import_projects store getters', () => { localState = state(); }); - describe('namespaceSelectOptions', () => { - const namespaces = [{ fullPath: 'namespace-0' }, { fullPath: 'namespace-1' }]; - const defaultTargetNamespace = 'current-user'; - - it('returns an options array with a "Users" and "Groups" optgroups', () => { - localState.namespaces = namespaces; - localState.defaultTargetNamespace = defaultTargetNamespace; - - const optionsArray = namespaceSelectOptions(localState); - const groupsGroup = optionsArray[0]; - const usersGroup = optionsArray[1]; - - expect(groupsGroup.text).toBe('Groups'); - expect(usersGroup.text).toBe('Users'); - - groupsGroup.children.forEach((child, index) => { - expect(child.id).toBe(namespaces[index].fullPath); - expect(child.text).toBe(namespaces[index].fullPath); + it.each` + isLoadingRepos | isLoadingNamespaces | isLoadingValue + ${false} | ${false} | ${false} + ${true} | ${false} | ${true} + ${false} | ${true} | ${true} + ${true} | ${true} | ${true} + `( + 'isLoading returns $isLoadingValue when isLoadingRepos is $isLoadingRepos and isLoadingNamespaces is $isLoadingNamespaces', + ({ isLoadingRepos, isLoadingNamespaces, isLoadingValue }) => { + Object.assign(localState, { + isLoadingRepos, + isLoadingNamespaces, }); - expect(usersGroup.children.length).toBe(1); - expect(usersGroup.children[0].id).toBe(defaultTargetNamespace); - expect(usersGroup.children[0].text).toBe(defaultTargetNamespace); - }); - }); - - describe('isImportingAnyRepo', () => { - it('returns true if there are any reposBeingImported', () => { - localState.reposBeingImported = new Array(1); - - expect(isImportingAnyRepo(localState)).toBe(true); - }); + expect(isLoading(localState)).toBe(isLoadingValue); + }, + ); + + it.each` + importStatus | value + ${STATUSES.NONE} | ${false} + ${STATUSES.SCHEDULING} | ${true} + ${STATUSES.SCHEDULED} | ${true} + ${STATUSES.STARTED} | ${true} + ${STATUSES.FINISHED} | ${false} + `( + 'isImportingAnyRepo returns $value when repo with $importStatus status is available', + ({ importStatus, value }) => { + localState.repositories = [{ importStatus }]; + + expect(isImportingAnyRepo(localState)).toBe(value); + }, + ); - it('returns false if there are no reposBeingImported', () => { - localState.reposBeingImported = []; - - expect(isImportingAnyRepo(localState)).toBe(false); - }); - }); - - describe('hasProviderRepos', () => { - it('returns true if there are any providerRepos', () => { - localState.providerRepos = new Array(1); + describe('hasIncompatibleRepos', () => { + it('returns true if there are any incompatible projects', () => { + localState.repositories = [IMPORTABLE_REPO, IMPORTED_REPO, INCOMPATIBLE_REPO]; - expect(hasProviderRepos(localState)).toBe(true); + expect(hasIncompatibleRepos(localState)).toBe(true); }); - it('returns false if there are no providerRepos', () => { - localState.providerRepos = []; + it('returns false if there are no incompatible projects', () => { + localState.repositories = [IMPORTABLE_REPO, IMPORTED_REPO]; - expect(hasProviderRepos(localState)).toBe(false); + expect(hasIncompatibleRepos(localState)).toBe(false); }); }); - describe('hasImportedProjects', () => { - it('returns true if there are any importedProjects', () => { - localState.importedProjects = new Array(1); + describe('hasImportableRepos', () => { + it('returns true if there are any importable projects ', () => { + localState.repositories = [IMPORTABLE_REPO, IMPORTED_REPO, INCOMPATIBLE_REPO]; - expect(hasImportedProjects(localState)).toBe(true); + expect(hasImportableRepos(localState)).toBe(true); }); - it('returns false if there are no importedProjects', () => { - localState.importedProjects = []; + it('returns false if there are no importable projects', () => { + localState.repositories = [IMPORTED_REPO, INCOMPATIBLE_REPO]; - expect(hasImportedProjects(localState)).toBe(false); + expect(hasImportableRepos(localState)).toBe(false); }); }); - describe('hasIncompatibleRepos', () => { - it('returns true if there are any incompatibleProjects', () => { - localState.incompatibleRepos = new Array(1); + describe('getImportTarget', () => { + it('returns default value if no custom target available', () => { + localState.defaultTargetNamespace = 'default'; + localState.repositories = [IMPORTABLE_REPO]; - expect(hasIncompatibleRepos(localState)).toBe(true); + expect(getImportTarget(localState)(IMPORTABLE_REPO.importSource.id)).toStrictEqual({ + newName: IMPORTABLE_REPO.importSource.sanitizedName, + targetNamespace: localState.defaultTargetNamespace, + }); }); - it('returns false if there are no incompatibleProjects', () => { - localState.incompatibleRepos = []; + it('returns custom import target if available', () => { + const fakeTarget = { newName: 'something', targetNamespace: 'ns' }; + localState.repositories = [IMPORTABLE_REPO]; + localState.customImportTargets[IMPORTABLE_REPO.importSource.id] = fakeTarget; - expect(hasIncompatibleRepos(localState)).toBe(false); + expect(getImportTarget(localState)(IMPORTABLE_REPO.importSource.id)).toStrictEqual( + fakeTarget, + ); }); }); }); |