Commit e488d70c authored by Coung Ngo's avatar Coung Ngo

Refactor Jira importer code

Improve code as a result of reviewer comments
parent 62a0a5dc
...@@ -16,9 +16,13 @@ import { ...@@ -16,9 +16,13 @@ import {
} from '@gitlab/ui'; } from '@gitlab/ui';
import { debounce } from 'lodash'; import { debounce } from 'lodash';
import axios from '~/lib/utils/axios_utils'; import axios from '~/lib/utils/axios_utils';
import { __ } from '~/locale'; import {
debounceWait,
const debounceWait = 500; dropdownLabel,
previousImportsMessage,
tableConfig,
userMappingMessage,
} from '../utils/constants';
export default { export default {
name: 'JiraImportForm', name: 'JiraImportForm',
...@@ -38,26 +42,10 @@ export default { ...@@ -38,26 +42,10 @@ export default {
GlTable, GlTable,
}, },
currentUsername: gon.current_username, currentUsername: gon.current_username,
dropdownLabel: __('The GitLab user to which the Jira user %{jiraDisplayName} will be mapped'), dropdownLabel,
previousImportsMessage: __(`You have imported from this project %{numberOfPreviousImports} times previousImportsMessage,
before. Each new import will create duplicate issues.`), tableConfig,
tableConfig: [ userMappingMessage,
{
key: 'jiraDisplayName',
label: __('Jira display name'),
},
{
key: 'arrow',
label: '',
},
{
key: 'gitlabUsername',
label: __('GitLab username'),
},
],
userMappingMessage: __(`Jira users have been imported from the configured Jira instance.
They can be mapped by selecting a GitLab user from the dropdown in the "GitLab username" column.
When the form appears, the dropdown defaults to the user conducting the import.`),
props: { props: {
isSubmitting: { isSubmitting: {
type: Boolean, type: Boolean,
......
import { __ } from '~/locale';
export const debounceWait = 500;
export const dropdownLabel = __(
'The GitLab user to which the Jira user %{jiraDisplayName} will be mapped',
);
export const previousImportsMessage = __(`You have imported from this project
%{numberOfPreviousImports} times before. Each new import will create duplicate issues.`);
export const tableConfig = [
{
key: 'jiraDisplayName',
label: __('Jira display name'),
},
{
key: 'arrow',
label: '',
},
{
key: 'gitlabUsername',
label: __('GitLab username'),
},
];
export const userMappingMessage = __(`Jira users have been imported from the configured Jira
instance. They can be mapped by selecting a GitLab user from the dropdown in the "GitLab username"
column. When the form appears, the dropdown defaults to the user conducting the import.`);
...@@ -228,20 +228,19 @@ describe('JiraImportApp', () => { ...@@ -228,20 +228,19 @@ describe('JiraImportApp', () => {
expect(mutateSpy).toHaveBeenCalledWith(expect.objectContaining(mutationArguments)); expect(mutateSpy).toHaveBeenCalledWith(expect.objectContaining(mutationArguments));
}); });
it('shows alert message with error message on error', async () => { describe('when there is an error', () => {
beforeEach(() => {
const mutate = jest.fn(() => Promise.reject()); const mutate = jest.fn(() => Promise.reject());
wrapper = mountComponent({ mutate }); wrapper = mountComponent({ mutate });
getFormComponent().vm.$emit('initiateJiraImport', 'MTG'); getFormComponent().vm.$emit('initiateJiraImport', 'MTG');
});
// One tick doesn't update the dom to the desired state so we have two ticks here it('shows alert message with error message', async () => {
await Vue.nextTick();
await Vue.nextTick();
expect(getAlert().text()).toBe('There was an error importing the Jira project.'); expect(getAlert().text()).toBe('There was an error importing the Jira project.');
}); });
}); });
});
describe('alert', () => { describe('alert', () => {
it('can be dismissed', async () => { it('can be dismissed', async () => {
...@@ -261,8 +260,8 @@ describe('JiraImportApp', () => { ...@@ -261,8 +260,8 @@ describe('JiraImportApp', () => {
}); });
}); });
describe('on mount', () => { describe('on mount GraphQL user mapping mutation', () => {
it('makes a GraphQL mutation call to get user mappings', () => { it('is called with the expected arguments', () => {
wrapper = mountComponent(); wrapper = mountComponent();
const mutationArguments = { const mutationArguments = {
...@@ -277,22 +276,23 @@ describe('JiraImportApp', () => { ...@@ -277,22 +276,23 @@ describe('JiraImportApp', () => {
expect(mutateSpy).toHaveBeenCalledWith(expect.objectContaining(mutationArguments)); expect(mutateSpy).toHaveBeenCalledWith(expect.objectContaining(mutationArguments));
}); });
it('does not make a GraphQL mutation call to get user mappings when Jira is not configured', () => { describe('when Jira is not configured', () => {
it('is not called', () => {
wrapper = mountComponent({ isJiraConfigured: false }); wrapper = mountComponent({ isJiraConfigured: false });
expect(mutateSpy).not.toHaveBeenCalled(); expect(mutateSpy).not.toHaveBeenCalled();
}); });
});
it('shows error message when there is an error with the GraphQL mutation call', async () => { describe('when there is an error when called', () => {
beforeEach(() => {
const mutate = jest.fn(() => Promise.reject()); const mutate = jest.fn(() => Promise.reject());
wrapper = mountComponent({ mutate }); wrapper = mountComponent({ mutate });
});
// One tick doesn't update the dom to the desired state so we have two ticks here it('shows error message', () => {
await Vue.nextTick();
await Vue.nextTick();
expect(getAlert().exists()).toBe(true); expect(getAlert().exists()).toBe(true);
}); });
}); });
});
}); });
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment