diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-06-18 14:18:50 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-06-18 14:18:50 +0300 |
commit | 8c7f4e9d5f36cff46365a7f8c4b9c21578c1e781 (patch) | |
tree | a77e7fe7a93de11213032ed4ab1f33a3db51b738 /spec/frontend/jira_import/utils | |
parent | 00b35af3db1abfe813a778f643dad221aad51fca (diff) |
Add latest changes from gitlab-org/gitlab@13-1-stable-ee
Diffstat (limited to 'spec/frontend/jira_import/utils')
-rw-r--r-- | spec/frontend/jira_import/utils/cache_update_spec.js | 64 | ||||
-rw-r--r-- | spec/frontend/jira_import/utils/jira_import_utils_spec.js | 91 |
2 files changed, 155 insertions, 0 deletions
diff --git a/spec/frontend/jira_import/utils/cache_update_spec.js b/spec/frontend/jira_import/utils/cache_update_spec.js new file mode 100644 index 00000000000..4812510f9b8 --- /dev/null +++ b/spec/frontend/jira_import/utils/cache_update_spec.js @@ -0,0 +1,64 @@ +import { addInProgressImportToStore } from '~/jira_import/utils/cache_update'; +import { IMPORT_STATE } from '~/jira_import/utils/jira_import_utils'; +import { + fullPath, + queryDetails, + jiraImportDetailsQueryResponse, + jiraImportMutationResponse, +} from '../mock_data'; + +describe('addInProgressImportToStore', () => { + const store = { + readQuery: jest.fn(() => jiraImportDetailsQueryResponse), + writeQuery: jest.fn(), + }; + + describe('when updating the cache', () => { + beforeEach(() => { + addInProgressImportToStore(store, jiraImportMutationResponse.jiraImportStart, fullPath); + }); + + it('reads the cache with the correct query', () => { + expect(store.readQuery).toHaveBeenCalledWith(queryDetails); + }); + + it('writes to the cache with the expected arguments', () => { + const expected = { + ...queryDetails, + data: { + project: { + ...jiraImportDetailsQueryResponse.project, + jiraImportStatus: IMPORT_STATE.SCHEDULED, + jiraImports: { + ...jiraImportDetailsQueryResponse.project.jiraImports, + nodes: jiraImportDetailsQueryResponse.project.jiraImports.nodes.concat( + jiraImportMutationResponse.jiraImportStart.jiraImport, + ), + }, + }, + }, + }; + + expect(store.writeQuery).toHaveBeenCalledWith(expected); + }); + }); + + describe('when there are errors', () => { + beforeEach(() => { + const jiraImportStart = { + ...jiraImportMutationResponse.jiraImportStart, + errors: ['There was an error'], + }; + + addInProgressImportToStore(store, jiraImportStart, fullPath); + }); + + it('does not read from the store', () => { + expect(store.readQuery).not.toHaveBeenCalled(); + }); + + it('does not write to the store', () => { + expect(store.writeQuery).not.toHaveBeenCalled(); + }); + }); +}); diff --git a/spec/frontend/jira_import/utils/jira_import_utils_spec.js b/spec/frontend/jira_import/utils/jira_import_utils_spec.js new file mode 100644 index 00000000000..504d399217a --- /dev/null +++ b/spec/frontend/jira_import/utils/jira_import_utils_spec.js @@ -0,0 +1,91 @@ +import { + calculateJiraImportLabel, + extractJiraProjectsOptions, + IMPORT_STATE, + isFinished, + isInProgress, +} from '~/jira_import/utils/jira_import_utils'; + +describe('isInProgress', () => { + it.each` + state | result + ${IMPORT_STATE.SCHEDULED} | ${true} + ${IMPORT_STATE.STARTED} | ${true} + ${IMPORT_STATE.FAILED} | ${false} + ${IMPORT_STATE.FINISHED} | ${false} + ${IMPORT_STATE.NONE} | ${false} + ${undefined} | ${false} + `('returns $result when state is $state', ({ state, result }) => { + expect(isInProgress(state)).toBe(result); + }); +}); + +describe('isFinished', () => { + it.each` + state | result + ${IMPORT_STATE.SCHEDULED} | ${false} + ${IMPORT_STATE.STARTED} | ${false} + ${IMPORT_STATE.FAILED} | ${false} + ${IMPORT_STATE.FINISHED} | ${true} + ${IMPORT_STATE.NONE} | ${false} + ${undefined} | ${false} + `('returns $result when state is $state', ({ state, result }) => { + expect(isFinished(state)).toBe(result); + }); +}); + +describe('extractJiraProjectsOptions', () => { + const jiraProjects = [ + { + key: 'MJP', + name: 'My Jira project', + }, + { + key: 'MTG', + name: 'Migrate to GitLab', + }, + ]; + + const expected = [ + { + text: 'My Jira project (MJP)', + value: 'MJP', + }, + { + text: 'Migrate to GitLab (MTG)', + value: 'MTG', + }, + ]; + + it('returns a list of Jira projects in a format suitable for GlFormSelect', () => { + expect(extractJiraProjectsOptions(jiraProjects)).toEqual(expected); + }); +}); + +describe('calculateJiraImportLabel', () => { + const jiraImports = [ + { jiraProjectKey: 'MTG' }, + { jiraProjectKey: 'MJP' }, + { jiraProjectKey: 'MTG' }, + { jiraProjectKey: 'MSJP' }, + { jiraProjectKey: 'MTG' }, + ]; + + const labels = [ + { color: '#111', title: 'jira-import::MTG-1' }, + { color: '#222', title: 'jira-import::MTG-2' }, + { color: '#333', title: 'jira-import::MTG-3' }, + ]; + + it('returns a label with the Jira project key and correct import count in the title', () => { + const label = calculateJiraImportLabel(jiraImports, labels); + + expect(label.title).toBe('jira-import::MTG-3'); + }); + + it('returns a label with the correct color', () => { + const label = calculateJiraImportLabel(jiraImports, labels); + + expect(label.color).toBe('#333'); + }); +}); |