Commit 696f4c28 authored by Olena Horal-Koretska's avatar Olena Horal-Koretska

Merge branch...

Merge branch '327113-jira-integration-inherited-instance-config-do-not-allow-enabling-issues-list-at-project-level' into 'master'

Fix Jira issue fields not disabled when inheriting

See merge request gitlab-org/gitlab!62364
parents 9b1de7c9 87b32c15
<script> <script>
import { GlFormGroup, GlFormCheckbox, GlFormInput, GlSprintf, GlLink } from '@gitlab/ui'; import { GlFormGroup, GlFormCheckbox, GlFormInput, GlSprintf, GlLink } from '@gitlab/ui';
import { mapGetters } from 'vuex';
import eventHub from '../event_hub'; import eventHub from '../event_hub';
import JiraUpgradeCta from './jira_upgrade_cta.vue'; import JiraUpgradeCta from './jira_upgrade_cta.vue';
...@@ -70,6 +71,7 @@ export default { ...@@ -70,6 +71,7 @@ export default {
}; };
}, },
computed: { computed: {
...mapGetters(['isInheriting']),
validProjectKey() { validProjectKey() {
return !this.enableJiraIssues || Boolean(this.projectKey) || !this.validated; return !this.enableJiraIssues || Boolean(this.projectKey) || !this.validated;
}, },
...@@ -116,7 +118,7 @@ export default { ...@@ -116,7 +118,7 @@ export default {
</p> </p>
<template v-if="showJiraIssuesIntegration"> <template v-if="showJiraIssuesIntegration">
<input name="service[issues_enabled]" type="hidden" :value="enableJiraIssues || false" /> <input name="service[issues_enabled]" type="hidden" :value="enableJiraIssues || false" />
<gl-form-checkbox v-model="enableJiraIssues"> <gl-form-checkbox v-model="enableJiraIssues" :disabled="isInheriting">
{{ s__('JiraService|Enable Jira issues') }} {{ s__('JiraService|Enable Jira issues') }}
<template #help> <template #help>
{{ {{
...@@ -161,6 +163,7 @@ export default { ...@@ -161,6 +163,7 @@ export default {
:required="enableJiraIssues" :required="enableJiraIssues"
:state="validProjectKey" :state="validProjectKey"
:disabled="!enableJiraIssues" :disabled="!enableJiraIssues"
:readonly="isInheriting"
/> />
</gl-form-group> </gl-form-group>
<p v-if="gitlabIssuesEnabled"> <p v-if="gitlabIssuesEnabled">
......
...@@ -10,7 +10,7 @@ import { ...@@ -10,7 +10,7 @@ import {
GlIcon, GlIcon,
GlTooltipDirective, GlTooltipDirective,
} from '@gitlab/ui'; } from '@gitlab/ui';
import { mapState } from 'vuex'; import { mapGetters, mapState } from 'vuex';
import { s__ } from '~/locale'; import { s__ } from '~/locale';
import { defaultJiraIssueTypeId } from '../constants'; import { defaultJiraIssueTypeId } from '../constants';
...@@ -80,12 +80,16 @@ export default { ...@@ -80,12 +80,16 @@ export default {
}; };
}, },
computed: { computed: {
...mapGetters(['isInheriting']),
...mapState([ ...mapState([
'isTesting', 'isTesting',
'jiraIssueTypes', 'jiraIssueTypes',
'isLoadingJiraIssueTypes', 'isLoadingJiraIssueTypes',
'loadingJiraIssueTypesErrorMessage', 'loadingJiraIssueTypesErrorMessage',
]), ]),
checkboxDisabled() {
return !this.showFullFeature || this.isInheriting;
},
initialJiraIssueType() { initialJiraIssueType() {
return this.jiraIssueTypes?.find(({ id }) => id === this.initialIssueTypeId) || {}; return this.jiraIssueTypes?.find(({ id }) => id === this.initialIssueTypeId) || {};
}, },
...@@ -134,7 +138,7 @@ export default { ...@@ -134,7 +138,7 @@ export default {
<gl-form-checkbox <gl-form-checkbox
v-model="isJiraVulnerabilitiesEnabled" v-model="isJiraVulnerabilitiesEnabled"
data-testid="enable-jira-vulnerabilities" data-testid="enable-jira-vulnerabilities"
:disabled="!showFullFeature" :disabled="checkboxDisabled"
> >
{{ $options.i18n.checkbox.label }} {{ $options.i18n.checkbox.label }}
<template #help> <template #help>
......
...@@ -22,7 +22,11 @@ describe('JiraIssuesFields', () => { ...@@ -22,7 +22,11 @@ describe('JiraIssuesFields', () => {
{ id: '3', name: 'epic', description: 'epic' }, { id: '3', name: 'epic', description: 'epic' },
]; ];
const createComponent = (mountFn) => ({ props } = {}) => { const createComponent = (mountFn) => ({ isInheriting = false, props } = {}) => {
store = createStore({
defaultState: isInheriting ? {} : undefined,
});
return extendedWrapper( return extendedWrapper(
mountFn(JiraIssueCreationVulnerabilities, { mountFn(JiraIssueCreationVulnerabilities, {
store, store,
...@@ -45,10 +49,6 @@ describe('JiraIssuesFields', () => { ...@@ -45,10 +49,6 @@ describe('JiraIssuesFields', () => {
const setEnableJiraVulnerabilitiesChecked = (isChecked) => const setEnableJiraVulnerabilitiesChecked = (isChecked) =>
findEnableJiraVulnerabilities().vm.$emit('input', isChecked); findEnableJiraVulnerabilities().vm.$emit('input', isChecked);
beforeEach(() => {
store = createStore();
});
afterEach(() => { afterEach(() => {
wrapper.destroy(); wrapper.destroy();
}); });
...@@ -98,6 +98,16 @@ describe('JiraIssuesFields', () => { ...@@ -98,6 +98,16 @@ describe('JiraIssuesFields', () => {
await setEnableJiraVulnerabilitiesChecked(isChecked); await setEnableJiraVulnerabilitiesChecked(isChecked);
expect(findIssueTypeSection().exists()).toBe(isChecked); expect(findIssueTypeSection().exists()).toBe(isChecked);
}); });
describe('when isInheriting = true', () => {
beforeEach(() => {
wrapper = createShallowComponent({ isInheriting: true });
});
it('disables the checkbox', () => {
expect(findEnableJiraVulnerabilities().attributes('disabled')).toBe('true');
});
});
}); });
describe('when showFullFeature is off', () => { describe('when showFullFeature is off', () => {
...@@ -132,8 +142,8 @@ describe('JiraIssuesFields', () => { ...@@ -132,8 +142,8 @@ describe('JiraIssuesFields', () => {
describe('with Jira issues fetching in progress', () => { describe('with Jira issues fetching in progress', () => {
beforeEach(async () => { beforeEach(async () => {
store.state.isLoadingJiraIssueTypes = true;
wrapper = createShallowComponent(); wrapper = createShallowComponent();
store.state.isLoadingJiraIssueTypes = true;
await setEnableJiraVulnerabilitiesChecked(true); await setEnableJiraVulnerabilitiesChecked(true);
}); });
...@@ -147,8 +157,8 @@ describe('JiraIssuesFields', () => { ...@@ -147,8 +157,8 @@ describe('JiraIssuesFields', () => {
describe('with Jira issues fetched', () => { describe('with Jira issues fetched', () => {
beforeEach(async () => { beforeEach(async () => {
store.state.jiraIssueTypes = TEST_JIRA_ISSUE_TYPES;
wrapper = createShallowComponent({ props: { projectKey: 'TES' } }); wrapper = createShallowComponent({ props: { projectKey: 'TES' } });
store.state.jiraIssueTypes = TEST_JIRA_ISSUE_TYPES;
await setEnableJiraVulnerabilitiesChecked(true); await setEnableJiraVulnerabilitiesChecked(true);
}); });
...@@ -173,8 +183,8 @@ describe('JiraIssuesFields', () => { ...@@ -173,8 +183,8 @@ describe('JiraIssuesFields', () => {
describe('with Jira issue fetch failure', () => { describe('with Jira issue fetch failure', () => {
beforeEach(async () => { beforeEach(async () => {
store.state.loadingJiraIssueTypesErrorMessage = 'something went wrong';
wrapper = createShallowComponent(); wrapper = createShallowComponent();
store.state.loadingJiraIssueTypesErrorMessage = 'something went wrong';
await setEnableJiraVulnerabilitiesChecked(true); await setEnableJiraVulnerabilitiesChecked(true);
}); });
......
...@@ -3,8 +3,10 @@ import { mount } from '@vue/test-utils'; ...@@ -3,8 +3,10 @@ import { mount } from '@vue/test-utils';
import JiraIssuesFields from '~/integrations/edit/components/jira_issues_fields.vue'; import JiraIssuesFields from '~/integrations/edit/components/jira_issues_fields.vue';
import JiraUpgradeCta from '~/integrations/edit/components/jira_upgrade_cta.vue'; import JiraUpgradeCta from '~/integrations/edit/components/jira_upgrade_cta.vue';
import eventHub from '~/integrations/edit/event_hub'; import eventHub from '~/integrations/edit/event_hub';
import { createStore } from '~/integrations/edit/store';
describe('JiraIssuesFields', () => { describe('JiraIssuesFields', () => {
let store;
let wrapper; let wrapper;
const defaultProps = { const defaultProps = {
...@@ -13,22 +15,26 @@ describe('JiraIssuesFields', () => { ...@@ -13,22 +15,26 @@ describe('JiraIssuesFields', () => {
showJiraVulnerabilitiesIntegration: true, showJiraVulnerabilitiesIntegration: true,
}; };
const createComponent = ({ props, ...options } = {}) => { const createComponent = ({ isInheriting = false, props, ...options } = {}) => {
store = createStore({
defaultState: isInheriting ? {} : undefined,
});
wrapper = mount(JiraIssuesFields, { wrapper = mount(JiraIssuesFields, {
propsData: { ...defaultProps, ...props }, propsData: { ...defaultProps, ...props },
store,
stubs: ['jira-issue-creation-vulnerabilities'], stubs: ['jira-issue-creation-vulnerabilities'],
...options, ...options,
}); });
}; };
afterEach(() => { afterEach(() => {
if (wrapper) { wrapper.destroy();
wrapper.destroy();
wrapper = null;
}
}); });
const findEnableCheckbox = () => wrapper.findComponent(GlFormCheckbox); const findEnableCheckbox = () => wrapper.findComponent(GlFormCheckbox);
const findEnableCheckboxDisabled = () =>
findEnableCheckbox().find('[type=checkbox]').attributes('disabled');
const findProjectKey = () => wrapper.findComponent(GlFormInput); const findProjectKey = () => wrapper.findComponent(GlFormInput);
const findJiraUpgradeCta = () => wrapper.findComponent(JiraUpgradeCta); const findJiraUpgradeCta = () => wrapper.findComponent(JiraUpgradeCta);
const findJiraForVulnerabilities = () => wrapper.find('[data-testid="jira-for-vulnerabilities"]'); const findJiraForVulnerabilities = () => wrapper.find('[data-testid="jira-for-vulnerabilities"]');
...@@ -79,6 +85,19 @@ describe('JiraIssuesFields', () => { ...@@ -79,6 +85,19 @@ describe('JiraIssuesFields', () => {
createComponent({ props: { initialProjectKey: '' } }); createComponent({ props: { initialProjectKey: '' } });
}); });
it('renders enabled checkbox', () => {
expect(findEnableCheckbox().exists()).toBe(true);
expect(findEnableCheckboxDisabled()).toBeUndefined();
});
it('renders disabled project_key input', () => {
const projectKey = findProjectKey();
expect(projectKey.exists()).toBe(true);
expect(projectKey.attributes('disabled')).toBe('disabled');
expect(projectKey.attributes('required')).toBeUndefined();
});
it('does not show upgrade banner', () => { it('does not show upgrade banner', () => {
expect(findJiraUpgradeCta().exists()).toBe(false); expect(findJiraUpgradeCta().exists()).toBe(false);
}); });
...@@ -89,24 +108,20 @@ describe('JiraIssuesFields', () => { ...@@ -89,24 +108,20 @@ describe('JiraIssuesFields', () => {
expect(wrapper.find('input[name="service[issues_enabled]"]').exists()).toBe(true); expect(wrapper.find('input[name="service[issues_enabled]"]').exists()).toBe(true);
}); });
it('disables project_key input', () => { describe('when isInheriting = true', () => {
expect(findProjectKey().attributes('disabled')).toBe('disabled'); it('disables checkbox and sets input as readonly', () => {
}); createComponent({ isInheriting: true });
it('does not require project_key', () => { expect(findEnableCheckboxDisabled()).toBe('disabled');
expect(findProjectKey().attributes('required')).toBeUndefined(); expect(findProjectKey().attributes('readonly')).toBe('readonly');
});
}); });
describe('on enable issues', () => { describe('on enable issues', () => {
it('enables project_key input', async () => { it('enables project_key input as required', async () => {
await setEnableCheckbox(true); await setEnableCheckbox(true);
expect(findProjectKey().attributes('disabled')).toBeUndefined(); expect(findProjectKey().attributes('disabled')).toBeUndefined();
});
it('requires project_key input', async () => {
await setEnableCheckbox(true);
expect(findProjectKey().attributes('required')).toBe('required'); expect(findProjectKey().attributes('required')).toBe('required');
}); });
}); });
......
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