diff options
Diffstat (limited to 'spec/frontend/jira_import/components/jira_import_app_spec.js')
-rw-r--r-- | spec/frontend/jira_import/components/jira_import_app_spec.js | 208 |
1 files changed, 119 insertions, 89 deletions
diff --git a/spec/frontend/jira_import/components/jira_import_app_spec.js b/spec/frontend/jira_import/components/jira_import_app_spec.js index a21b89f6517..074f9842512 100644 --- a/spec/frontend/jira_import/components/jira_import_app_spec.js +++ b/spec/frontend/jira_import/components/jira_import_app_spec.js @@ -1,88 +1,19 @@ import { GlAlert, GlLoadingIcon } from '@gitlab/ui'; import { mount, shallowMount } from '@vue/test-utils'; +import AxiosMockAdapter from 'axios-mock-adapter'; import Vue from 'vue'; +import axios from '~/lib/utils/axios_utils'; import JiraImportApp from '~/jira_import/components/jira_import_app.vue'; import JiraImportForm from '~/jira_import/components/jira_import_form.vue'; import JiraImportProgress from '~/jira_import/components/jira_import_progress.vue'; import JiraImportSetup from '~/jira_import/components/jira_import_setup.vue'; import initiateJiraImportMutation from '~/jira_import/queries/initiate_jira_import.mutation.graphql'; - -const mountComponent = ({ - isJiraConfigured = true, - errorMessage = '', - selectedProject = 'MTG', - showAlert = false, - isInProgress = false, - loading = false, - mutate = jest.fn(() => Promise.resolve()), - mountType, -} = {}) => { - const mountFunction = mountType === 'mount' ? mount : shallowMount; - - return mountFunction(JiraImportApp, { - propsData: { - inProgressIllustration: 'in-progress-illustration.svg', - isJiraConfigured, - issuesPath: 'gitlab-org/gitlab-test/-/issues', - jiraIntegrationPath: 'gitlab-org/gitlab-test/-/services/jira/edit', - projectPath: 'gitlab-org/gitlab-test', - setupIllustration: 'setup-illustration.svg', - }, - data() { - return { - errorMessage, - showAlert, - selectedProject, - jiraImportDetails: { - isInProgress, - imports: [ - { - jiraProjectKey: 'MTG', - scheduledAt: '2020-04-08T10:11:12+00:00', - scheduledBy: { - name: 'John Doe', - }, - }, - { - jiraProjectKey: 'MSJP', - scheduledAt: '2020-04-09T13:14:15+00:00', - scheduledBy: { - name: 'Jimmy Doe', - }, - }, - { - jiraProjectKey: 'MTG', - scheduledAt: '2020-04-09T16:17:18+00:00', - scheduledBy: { - name: 'Jane Doe', - }, - }, - ], - mostRecentImport: { - jiraProjectKey: 'MTG', - scheduledAt: '2020-04-09T16:17:18+00:00', - scheduledBy: { - name: 'Jane Doe', - }, - }, - projects: [ - { text: 'My Jira Project (MJP)', value: 'MJP' }, - { text: 'My Second Jira Project (MSJP)', value: 'MSJP' }, - { text: 'Migrate to GitLab (MTG)', value: 'MTG' }, - ], - }, - }; - }, - mocks: { - $apollo: { - loading, - mutate, - }, - }, - }); -}; +import getJiraUserMappingMutation from '~/jira_import/queries/get_jira_user_mapping.mutation.graphql'; +import { imports, issuesPath, jiraIntegrationPath, jiraProjects, userMappings } from '../mock_data'; describe('JiraImportApp', () => { + let axiosMock; + let mutateSpy; let wrapper; const getFormComponent = () => wrapper.find(JiraImportForm); @@ -95,7 +26,64 @@ describe('JiraImportApp', () => { const getLoadingIcon = () => wrapper.find(GlLoadingIcon); + const mountComponent = ({ + isJiraConfigured = true, + errorMessage = '', + selectedProject = 'MTG', + showAlert = false, + isInProgress = false, + loading = false, + mutate = mutateSpy, + mountFunction = shallowMount, + } = {}) => + mountFunction(JiraImportApp, { + propsData: { + inProgressIllustration: 'in-progress-illustration.svg', + isJiraConfigured, + issuesPath, + jiraIntegrationPath, + projectId: '5', + projectPath: 'gitlab-org/gitlab-test', + setupIllustration: 'setup-illustration.svg', + }, + data() { + return { + isSubmitting: false, + selectedProject, + userMappings, + errorMessage, + showAlert, + jiraImportDetails: { + isInProgress, + imports, + mostRecentImport: imports[imports.length - 1], + projects: jiraProjects, + }, + }; + }, + mocks: { + $apollo: { + loading, + mutate, + }, + }, + }); + + beforeEach(() => { + axiosMock = new AxiosMockAdapter(axios); + mutateSpy = jest.fn(() => + Promise.resolve({ + data: { + jiraImportStart: { errors: [] }, + jiraImportUsers: { jiraUsers: [], errors: [] }, + }, + }), + ); + }); + afterEach(() => { + axiosMock.restore(); + mutateSpy.mockRestore(); wrapper.destroy(); wrapper = null; }); @@ -223,7 +211,7 @@ describe('JiraImportApp', () => { }); it('shows warning alert to explain project MTG has been imported 2 times before', () => { - wrapper = mountComponent({ mountType: 'mount' }); + wrapper = mountComponent({ mountFunction: mount }); expect(getAlert().text()).toBe( 'You have imported from this project 2 times before. Each new import will create duplicate issues.', @@ -248,9 +236,7 @@ describe('JiraImportApp', () => { describe('initiating a Jira import', () => { it('calls the mutation with the expected arguments', () => { - const mutate = jest.fn(() => Promise.resolve()); - - wrapper = mountComponent({ mutate }); + wrapper = mountComponent(); const mutationArguments = { mutation: initiateJiraImportMutation, @@ -258,13 +244,23 @@ describe('JiraImportApp', () => { input: { jiraProjectKey: 'MTG', projectPath: 'gitlab-org/gitlab-test', + usersMapping: [ + { + jiraAccountId: 'aei23f98f-q23fj98qfj', + gitlabId: 15, + }, + { + jiraAccountId: 'fu39y8t34w-rq3u289t3h4i', + gitlabId: undefined, + }, + ], }, }, }; getFormComponent().vm.$emit('initiateJiraImport', 'MTG'); - expect(mutate).toHaveBeenCalledWith(expect.objectContaining(mutationArguments)); + expect(mutateSpy).toHaveBeenCalledWith(expect.objectContaining(mutationArguments)); }); it('shows alert message with error message on error', () => { @@ -283,19 +279,53 @@ describe('JiraImportApp', () => { }); }); - it('can dismiss alert message', () => { - wrapper = mountComponent({ - errorMessage: 'There was an error importing the Jira project.', - showAlert: true, - selectedProject: null, + describe('alert', () => { + it('can be dismissed', () => { + wrapper = mountComponent({ + errorMessage: 'There was an error importing the Jira project.', + showAlert: true, + selectedProject: null, + }); + + expect(getAlert().exists()).toBe(true); + + getAlert().vm.$emit('dismiss'); + + return Vue.nextTick().then(() => { + expect(getAlert().exists()).toBe(false); + }); }); + }); - expect(getAlert().exists()).toBe(true); + describe('on mount', () => { + it('makes a GraphQL mutation call to get user mappings', () => { + wrapper = mountComponent(); - getAlert().vm.$emit('dismiss'); + const mutationArguments = { + mutation: getJiraUserMappingMutation, + variables: { + input: { + projectPath: 'gitlab-org/gitlab-test', + startAt: 1, + }, + }, + }; + + expect(mutateSpy).toHaveBeenCalledWith(expect.objectContaining(mutationArguments)); + }); + + it('does not make a GraphQL mutation call to get user mappings when Jira is not configured', () => { + wrapper = mountComponent({ isJiraConfigured: false }); + + expect(mutateSpy).not.toHaveBeenCalled(); + }); + + it('shows error message when there is an error with the GraphQL mutation call', () => { + const mutate = jest.fn(() => Promise.reject()); + + wrapper = mountComponent({ mutate }); - return Vue.nextTick().then(() => { - expect(getAlert().exists()).toBe(false); + expect(getAlert().exists()).toBe(true); }); }); }); |