Commit a26c6fae authored by Kushal Pandya's avatar Kushal Pandya

Merge branch '207455-frontend-fix-epic-blform' into 'master'

Remove blocking issue radio inputs from "Add an epic" form

Closes #207455

See merge request gitlab-org/gitlab!26003
parents c7b7c67f d93de22a
---
title: Fix "Add an epic" form
merge_request: 26003
author:
type: fixed
...@@ -83,6 +83,9 @@ export default { ...@@ -83,6 +83,9 @@ export default {
}; };
}, },
computed: { computed: {
isIssue() {
return this.issuableType === issuableTypesMap.ISSUE;
},
isSubmitButtonDisabled() { isSubmitButtonDisabled() {
return ( return (
(this.inputValue.length === 0 && this.pendingReferences.length === 0) || this.isSubmitting (this.inputValue.length === 0 && this.pendingReferences.length === 0) || this.isSubmitting
...@@ -123,22 +126,24 @@ export default { ...@@ -123,22 +126,24 @@ export default {
<template> <template>
<form @submit.prevent="onFormSubmit"> <form @submit.prevent="onFormSubmit">
<gl-form-group <template v-if="isIssue">
:label="__('The current issue')" <gl-form-group
label-for="linked-issue-type-radio" :label="__('The current issue')"
label-class="label-bold" label-for="linked-issue-type-radio"
class="mb-2" label-class="label-bold"
> class="mb-2"
<gl-form-radio-group >
id="linked-issue-type-radio" <gl-form-radio-group
v-model="linkedIssueType" id="linked-issue-type-radio"
:options="linkedIssueTypes" v-model="linkedIssueType"
:checked="linkedIssueType" :options="linkedIssueTypes"
/> :checked="linkedIssueType"
</gl-form-group> />
<p class="bold"> </gl-form-group>
{{ __('the following issue(s)') }} <p class="bold">
</p> {{ __('the following issue(s)') }}
</p>
</template>
<related-issuable-input <related-issuable-input
ref="relatedIssuableInput" ref="relatedIssuableInput"
:focus-on-mount="true" :focus-on-mount="true"
......
import { mount } from '@vue/test-utils'; import { mount, shallowMount } from '@vue/test-utils';
import { linkedIssueTypesMap, PathIdSeparator } from 'ee/related_issues/constants'; import {
issuableTypesMap,
linkedIssueTypesMap,
PathIdSeparator,
} from 'ee/related_issues/constants';
import AddIssuableForm from 'ee/related_issues/components/add_issuable_form.vue'; import AddIssuableForm from 'ee/related_issues/components/add_issuable_form.vue';
const issuable1 = { const issuable1 = {
...@@ -26,6 +30,8 @@ const findFormInput = wrapper => wrapper.find('.js-add-issuable-form-input').ele ...@@ -26,6 +30,8 @@ const findFormInput = wrapper => wrapper.find('.js-add-issuable-form-input').ele
const findRadioInput = (inputs, value) => inputs.filter(input => input.element.value === value)[0]; const findRadioInput = (inputs, value) => inputs.filter(input => input.element.value === value)[0];
const findRadioInputs = wrapper => wrapper.findAll('[name="linked-issue-type-radio"]');
describe('AddIssuableForm', () => { describe('AddIssuableForm', () => {
let wrapper; let wrapper;
...@@ -37,7 +43,7 @@ describe('AddIssuableForm', () => { ...@@ -37,7 +43,7 @@ describe('AddIssuableForm', () => {
describe('without references', () => { describe('without references', () => {
describe('without any input text', () => { describe('without any input text', () => {
beforeEach(() => { beforeEach(() => {
wrapper = mount(AddIssuableForm, { wrapper = shallowMount(AddIssuableForm, {
propsData: { propsData: {
inputValue: '', inputValue: '',
pendingReferences: [], pendingReferences: [],
...@@ -54,7 +60,7 @@ describe('AddIssuableForm', () => { ...@@ -54,7 +60,7 @@ describe('AddIssuableForm', () => {
describe('with input text', () => { describe('with input text', () => {
beforeEach(() => { beforeEach(() => {
wrapper = mount(AddIssuableForm, { wrapper = shallowMount(AddIssuableForm, {
propsData: { propsData: {
inputValue: 'foo', inputValue: 'foo',
pendingReferences: [], pendingReferences: [],
...@@ -95,99 +101,123 @@ describe('AddIssuableForm', () => { ...@@ -95,99 +101,123 @@ describe('AddIssuableForm', () => {
}); });
}); });
describe('form radio buttons', () => { describe('when issuable type is "issue"', () => {
let radioInputs;
beforeEach(() => { beforeEach(() => {
radioInputs = wrapper.findAll('[name="linked-issue-type-radio"]'); wrapper = mount(AddIssuableForm, {
propsData: {
inputValue: '',
issuableType: issuableTypesMap.ISSUE,
pathIdSeparator,
pendingReferences: [],
},
});
}); });
it('shows "relates to" option', () => { it('shows radio inputs to allow categorisation of blocking issues', () => {
expect(findRadioInput(radioInputs, linkedIssueTypesMap.RELATES_TO)).not.toBeNull(); expect(findRadioInputs(wrapper).length).toBeGreaterThan(0);
}); });
it('shows "blocks" option', () => { describe('form radio buttons', () => {
expect(findRadioInput(radioInputs, linkedIssueTypesMap.BLOCKS)).not.toBeNull(); let radioInputs;
});
it('shows "is blocked by" option', () => { beforeEach(() => {
expect(findRadioInput(radioInputs, linkedIssueTypesMap.IS_BLOCKED_BY)).not.toBeNull(); radioInputs = findRadioInputs(wrapper);
}); });
it('shows 3 options in total', () => { it('shows "relates to" option', () => {
expect(radioInputs.length).toBe(3); expect(findRadioInput(radioInputs, linkedIssueTypesMap.RELATES_TO)).not.toBeNull();
}); });
});
describe('when the form is submitted', () => { it('shows "blocks" option', () => {
beforeEach(() => { expect(findRadioInput(radioInputs, linkedIssueTypesMap.BLOCKS)).not.toBeNull();
wrapper = mount(AddIssuableForm, { });
propsData: {
inputValue: '', it('shows "is blocked by" option', () => {
pendingReferences: [], expect(findRadioInput(radioInputs, linkedIssueTypesMap.IS_BLOCKED_BY)).not.toBeNull();
pathIdSeparator, });
},
it('shows 3 options in total', () => {
expect(radioInputs.length).toBe(3);
}); });
}); });
it('emits an event with a "relates_to" link type when the "relates to" radio input selected', done => { describe('when the form is submitted', () => {
spyOn(wrapper.vm, '$emit'); it('emits an event with a "relates_to" link type when the "relates to" radio input selected', done => {
spyOn(wrapper.vm, '$emit');
wrapper.vm.linkedIssueType = linkedIssueTypesMap.RELATES_TO; wrapper.vm.linkedIssueType = linkedIssueTypesMap.RELATES_TO;
wrapper.vm.onFormSubmit(); wrapper.vm.onFormSubmit();
wrapper.vm.$nextTick(() => { wrapper.vm.$nextTick(() => {
expect(wrapper.vm.$emit).toHaveBeenCalledWith('addIssuableFormSubmit', { expect(wrapper.vm.$emit).toHaveBeenCalledWith('addIssuableFormSubmit', {
pendingReferences: '', pendingReferences: '',
linkedIssueType: linkedIssueTypesMap.RELATES_TO, linkedIssueType: linkedIssueTypesMap.RELATES_TO,
});
done();
}); });
done();
}); });
});
it('emits an event with a "blocks" link type when the "blocks" radio input selected', done => { it('emits an event with a "blocks" link type when the "blocks" radio input selected', done => {
spyOn(wrapper.vm, '$emit'); spyOn(wrapper.vm, '$emit');
wrapper.vm.linkedIssueType = linkedIssueTypesMap.BLOCKS; wrapper.vm.linkedIssueType = linkedIssueTypesMap.BLOCKS;
wrapper.vm.onFormSubmit(); wrapper.vm.onFormSubmit();
wrapper.vm.$nextTick(() => { wrapper.vm.$nextTick(() => {
expect(wrapper.vm.$emit).toHaveBeenCalledWith('addIssuableFormSubmit', { expect(wrapper.vm.$emit).toHaveBeenCalledWith('addIssuableFormSubmit', {
pendingReferences: '', pendingReferences: '',
linkedIssueType: linkedIssueTypesMap.BLOCKS, linkedIssueType: linkedIssueTypesMap.BLOCKS,
});
done();
}); });
done();
}); });
});
it('emits an event with a "is_blocked_by" link type when the "is blocked by" radio input selected', done => { it('emits an event with a "is_blocked_by" link type when the "is blocked by" radio input selected', done => {
spyOn(wrapper.vm, '$emit'); spyOn(wrapper.vm, '$emit');
wrapper.vm.linkedIssueType = linkedIssueTypesMap.IS_BLOCKED_BY; wrapper.vm.linkedIssueType = linkedIssueTypesMap.IS_BLOCKED_BY;
wrapper.vm.onFormSubmit(); wrapper.vm.onFormSubmit();
wrapper.vm.$nextTick(() => { wrapper.vm.$nextTick(() => {
expect(wrapper.vm.$emit).toHaveBeenCalledWith('addIssuableFormSubmit', { expect(wrapper.vm.$emit).toHaveBeenCalledWith('addIssuableFormSubmit', {
pendingReferences: '', pendingReferences: '',
linkedIssueType: linkedIssueTypesMap.IS_BLOCKED_BY, linkedIssueType: linkedIssueTypesMap.IS_BLOCKED_BY,
});
done();
}); });
done();
}); });
});
it('shows error message when error is present', done => { it('shows error message when error is present', done => {
const itemAddFailureMessage = 'Something went wrong while submitting.'; const itemAddFailureMessage = 'Something went wrong while submitting.';
wrapper.setProps({ wrapper.setProps({
hasError: true, hasError: true,
itemAddFailureMessage, itemAddFailureMessage,
});
wrapper.vm.$nextTick(() => {
expect(wrapper.find('.gl-field-error').exists()).toBe(true);
expect(wrapper.find('.gl-field-error').text()).toContain(itemAddFailureMessage);
done();
});
}); });
});
});
wrapper.vm.$nextTick(() => { describe('when issuable type is "epic"', () => {
expect(wrapper.find('.gl-field-error').exists()).toBe(true); beforeEach(() => {
expect(wrapper.find('.gl-field-error').text()).toContain(itemAddFailureMessage); wrapper = shallowMount(AddIssuableForm, {
done(); propsData: {
inputValue: '',
issuableType: issuableTypesMap.EPIC,
pathIdSeparator,
pendingReferences: [],
},
}); });
}); });
it('does not show radio inputs', () => {
expect(findRadioInputs(wrapper).length).toBe(0);
});
}); });
}); });
}); });
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