debian-mirror-gitlab/spec/frontend/import_entities/import_projects/store/getters_spec.js

136 lines
4.1 KiB
JavaScript
Raw Normal View History

2021-03-11 19:13:27 +05:30
import { STATUSES } from '~/import_entities/constants';
2019-07-07 11:18:12 +05:30
import {
2020-10-24 23:57:45 +05:30
isLoading,
2019-07-07 11:18:12 +05:30
isImportingAnyRepo,
2020-06-23 00:09:42 +05:30
hasIncompatibleRepos,
2020-10-24 23:57:45 +05:30
hasImportableRepos,
2020-11-24 15:15:51 +05:30
importAllCount,
2020-10-24 23:57:45 +05:30
getImportTarget,
2021-02-22 17:27:13 +05:30
} from '~/import_entities/import_projects/store/getters';
import state from '~/import_entities/import_projects/store/state';
2019-07-07 11:18:12 +05:30
2020-10-24 23:57:45 +05:30
const IMPORTED_REPO = {
importSource: {},
2020-11-24 15:15:51 +05:30
importedProject: { fullPath: 'some/path', importStatus: STATUSES.FINISHED },
2020-10-24 23:57:45 +05:30
};
const IMPORTABLE_REPO = {
importSource: { id: 'some-id', sanitizedName: 'sanitized' },
importedProject: null,
};
const INCOMPATIBLE_REPO = {
importSource: { incompatible: true },
};
2019-07-07 11:18:12 +05:30
describe('import_projects store getters', () => {
let localState;
beforeEach(() => {
localState = state();
});
2020-10-24 23:57:45 +05:30
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,
2019-07-07 11:18:12 +05:30
});
2020-10-24 23:57:45 +05:30
expect(isLoading(localState)).toBe(isLoadingValue);
},
);
it.each`
importStatus | value
${STATUSES.NONE} | ${false}
${STATUSES.SCHEDULING} | ${true}
${STATUSES.SCHEDULED} | ${true}
${STATUSES.STARTED} | ${true}
${STATUSES.FINISHED} | ${false}
`(
2020-11-24 15:15:51 +05:30
'isImportingAnyRepo returns $value when project with $importStatus status is available',
2020-10-24 23:57:45 +05:30
({ importStatus, value }) => {
2020-11-24 15:15:51 +05:30
localState.repositories = [{ importedProject: { importStatus } }];
2020-10-24 23:57:45 +05:30
expect(isImportingAnyRepo(localState)).toBe(value);
},
);
2019-07-07 11:18:12 +05:30
2020-11-24 15:15:51 +05:30
it('isImportingAnyRepo returns false when project with no defined importStatus status is available', () => {
localState.repositories = [{ importSource: {} }];
expect(isImportingAnyRepo(localState)).toBe(false);
});
2020-10-24 23:57:45 +05:30
describe('hasIncompatibleRepos', () => {
it('returns true if there are any incompatible projects', () => {
localState.repositories = [IMPORTABLE_REPO, IMPORTED_REPO, INCOMPATIBLE_REPO];
2019-07-07 11:18:12 +05:30
2020-10-24 23:57:45 +05:30
expect(hasIncompatibleRepos(localState)).toBe(true);
2019-07-07 11:18:12 +05:30
});
2020-10-24 23:57:45 +05:30
it('returns false if there are no incompatible projects', () => {
localState.repositories = [IMPORTABLE_REPO, IMPORTED_REPO];
2019-07-07 11:18:12 +05:30
2020-10-24 23:57:45 +05:30
expect(hasIncompatibleRepos(localState)).toBe(false);
2019-07-07 11:18:12 +05:30
});
});
2020-10-24 23:57:45 +05:30
describe('hasImportableRepos', () => {
it('returns true if there are any importable projects ', () => {
localState.repositories = [IMPORTABLE_REPO, IMPORTED_REPO, INCOMPATIBLE_REPO];
2019-07-07 11:18:12 +05:30
2020-10-24 23:57:45 +05:30
expect(hasImportableRepos(localState)).toBe(true);
2019-07-07 11:18:12 +05:30
});
2020-10-24 23:57:45 +05:30
it('returns false if there are no importable projects', () => {
localState.repositories = [IMPORTED_REPO, INCOMPATIBLE_REPO];
2019-07-07 11:18:12 +05:30
2020-10-24 23:57:45 +05:30
expect(hasImportableRepos(localState)).toBe(false);
2019-07-07 11:18:12 +05:30
});
});
2020-06-23 00:09:42 +05:30
2020-11-24 15:15:51 +05:30
describe('importAllCount', () => {
it('returns count of available importable projects ', () => {
localState.repositories = [
IMPORTABLE_REPO,
IMPORTABLE_REPO,
IMPORTED_REPO,
INCOMPATIBLE_REPO,
];
expect(importAllCount(localState)).toBe(2);
});
});
2020-10-24 23:57:45 +05:30
describe('getImportTarget', () => {
it('returns default value if no custom target available', () => {
localState.defaultTargetNamespace = 'default';
localState.repositories = [IMPORTABLE_REPO];
2020-06-23 00:09:42 +05:30
2020-10-24 23:57:45 +05:30
expect(getImportTarget(localState)(IMPORTABLE_REPO.importSource.id)).toStrictEqual({
newName: IMPORTABLE_REPO.importSource.sanitizedName,
targetNamespace: localState.defaultTargetNamespace,
});
2020-06-23 00:09:42 +05:30
});
2020-10-24 23:57:45 +05:30
it('returns custom import target if available', () => {
const fakeTarget = { newName: 'something', targetNamespace: 'ns' };
localState.repositories = [IMPORTABLE_REPO];
localState.customImportTargets[IMPORTABLE_REPO.importSource.id] = fakeTarget;
2020-06-23 00:09:42 +05:30
2020-10-24 23:57:45 +05:30
expect(getImportTarget(localState)(IMPORTABLE_REPO.importSource.id)).toStrictEqual(
fakeTarget,
);
2020-06-23 00:09:42 +05:30
});
});
2019-07-07 11:18:12 +05:30
});