diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-12-17 11:59:07 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-12-17 11:59:07 +0000 |
commit | 8b573c94895dc0ac0e1d9d59cf3e8745e8b539ca (patch) | |
tree | 544930fb309b30317ae9797a9683768705d664c4 /spec/frontend/import_entities/import_projects/store/getters_spec.js | |
parent | 4b1de649d0168371549608993deac953eb692019 (diff) | |
download | gitlab-ce-8b573c94895dc0ac0e1d9d59cf3e8745e8b539ca.tar.gz |
Add latest changes from gitlab-org/gitlab@13-7-stable-eev13.7.0-rc42
Diffstat (limited to 'spec/frontend/import_entities/import_projects/store/getters_spec.js')
-rw-r--r-- | spec/frontend/import_entities/import_projects/store/getters_spec.js | 135 |
1 files changed, 135 insertions, 0 deletions
diff --git a/spec/frontend/import_entities/import_projects/store/getters_spec.js b/spec/frontend/import_entities/import_projects/store/getters_spec.js new file mode 100644 index 00000000000..f0ccffc19f2 --- /dev/null +++ b/spec/frontend/import_entities/import_projects/store/getters_spec.js @@ -0,0 +1,135 @@ +import { + isLoading, + isImportingAnyRepo, + hasIncompatibleRepos, + hasImportableRepos, + importAllCount, + getImportTarget, +} from '~/import_entities/import_projects/store/getters'; +import { STATUSES } from '~/import_entities/constants'; +import state from '~/import_entities/import_projects/store/state'; + +const IMPORTED_REPO = { + importSource: {}, + importedProject: { fullPath: 'some/path', importStatus: STATUSES.FINISHED }, +}; + +const IMPORTABLE_REPO = { + importSource: { id: 'some-id', sanitizedName: 'sanitized' }, + importedProject: null, +}; + +const INCOMPATIBLE_REPO = { + importSource: { incompatible: true }, +}; + +describe('import_projects store getters', () => { + let localState; + + beforeEach(() => { + localState = state(); + }); + + 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(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 project with $importStatus status is available', + ({ importStatus, value }) => { + localState.repositories = [{ importedProject: { importStatus } }]; + + expect(isImportingAnyRepo(localState)).toBe(value); + }, + ); + + it('isImportingAnyRepo returns false when project with no defined importStatus status is available', () => { + localState.repositories = [{ importSource: {} }]; + + expect(isImportingAnyRepo(localState)).toBe(false); + }); + + describe('hasIncompatibleRepos', () => { + it('returns true if there are any incompatible projects', () => { + localState.repositories = [IMPORTABLE_REPO, IMPORTED_REPO, INCOMPATIBLE_REPO]; + + expect(hasIncompatibleRepos(localState)).toBe(true); + }); + + it('returns false if there are no incompatible projects', () => { + localState.repositories = [IMPORTABLE_REPO, IMPORTED_REPO]; + + expect(hasIncompatibleRepos(localState)).toBe(false); + }); + }); + + describe('hasImportableRepos', () => { + it('returns true if there are any importable projects ', () => { + localState.repositories = [IMPORTABLE_REPO, IMPORTED_REPO, INCOMPATIBLE_REPO]; + + expect(hasImportableRepos(localState)).toBe(true); + }); + + it('returns false if there are no importable projects', () => { + localState.repositories = [IMPORTED_REPO, INCOMPATIBLE_REPO]; + + expect(hasImportableRepos(localState)).toBe(false); + }); + }); + + describe('importAllCount', () => { + it('returns count of available importable projects ', () => { + localState.repositories = [ + IMPORTABLE_REPO, + IMPORTABLE_REPO, + IMPORTED_REPO, + INCOMPATIBLE_REPO, + ]; + + expect(importAllCount(localState)).toBe(2); + }); + }); + + describe('getImportTarget', () => { + it('returns default value if no custom target available', () => { + localState.defaultTargetNamespace = 'default'; + localState.repositories = [IMPORTABLE_REPO]; + + expect(getImportTarget(localState)(IMPORTABLE_REPO.importSource.id)).toStrictEqual({ + newName: IMPORTABLE_REPO.importSource.sanitizedName, + targetNamespace: localState.defaultTargetNamespace, + }); + }); + + 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(getImportTarget(localState)(IMPORTABLE_REPO.importSource.id)).toStrictEqual( + fakeTarget, + ); + }); + }); +}); |