Commit e345840a authored by Kushal Pandya's avatar Kushal Pandya

Merge branch 'dj-refactor-licenses' into 'master'

Refactor License Form to use GlFormRadio

See merge request gitlab-org/gitlab!45661
parents 2cef38b2 1ecfc673
<script> <script>
import { GlButton } from '@gitlab/ui'; import { GlButton, GlFormRadioGroup, GlFormRadio } from '@gitlab/ui';
import glFeatureFlagsMixin from '~/vue_shared/mixins/gl_feature_flags_mixin'; import glFeatureFlagsMixin from '~/vue_shared/mixins/gl_feature_flags_mixin';
import { LICENSE_APPROVAL_STATUS } from '../constants'; import { LICENSE_APPROVAL_STATUS } from '../constants';
import AddLicenseFormDropdown from './add_license_form_dropdown.vue'; import AddLicenseFormDropdown from './add_license_form_dropdown.vue';
...@@ -10,6 +10,8 @@ export default { ...@@ -10,6 +10,8 @@ export default {
components: { components: {
AddLicenseFormDropdown, AddLicenseFormDropdown,
GlButton, GlButton,
GlFormRadioGroup,
GlFormRadio,
}, },
mixins: [glFeatureFlagsMixin()], mixins: [glFeatureFlagsMixin()],
LICENSE_APPROVAL_STATUS, LICENSE_APPROVAL_STATUS,
...@@ -90,28 +92,21 @@ export default { ...@@ -90,28 +92,21 @@ export default {
</div> </div>
</div> </div>
<div class="form-group"> <div class="form-group">
<div <gl-form-radio-group v-model="approvalStatus" name="approvalStatus">
v-for="option in $options.approvalStatusOptions" <gl-form-radio
:key="option.value" v-for="option in $options.approvalStatusOptions"
class="form-check" :key="option.value"
:class="{ 'mb-3': isDescriptionEnabled }"
>
<input
:id="`js-${option.value}-license-radio`"
v-model="approvalStatus"
class="form-check-input"
type="radio"
:data-qa-selector="`${option.value}_license_radio`"
:value="option.value" :value="option.value"
:data-qa-selector="`${option.value}_license_radio`"
:aria-describedby="`js-${option.value}-license-radio`" :aria-describedby="`js-${option.value}-license-radio`"
/> :class="{ 'mb-3': isDescriptionEnabled }"
<label :for="`js-${option.value}-license-radio`" class="form-check-label pt-1"> >
{{ option.label }} <template>{{ option.label }}</template>
</label> <div v-if="isDescriptionEnabled" class="text-secondary">
<div v-if="isDescriptionEnabled" class="text-secondary"> {{ option.description }}
{{ option.description }} </div>
</div> </gl-form-radio>
</div> </gl-form-radio-group>
</div> </div>
<div class="gl-display-flex"> <div class="gl-display-flex">
<gl-button <gl-button
......
// Jest Snapshot v1, https://goo.gl/fbAQLP // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`AddLicenseForm template does not show radio button descriptions, if licenseComplianceDeniesMr feature flag is disabled 1`] = ` exports[`AddLicenseForm template does not show radio button descriptions, if licenseComplianceDeniesMr feature flag is disabled 1`] = `
<div <gl-form-radio-stub
class="form-check" aria-describedby="js-approved-license-radio"
class=""
data-qa-selector="approved_license_radio"
value="approved"
> >
<input Allow
aria-describedby="js-approved-license-radio"
class="form-check-input"
data-qa-selector="approved_license_radio"
id="js-approved-license-radio"
type="radio"
value="approved"
/>
<label
class="form-check-label pt-1"
for="js-approved-license-radio"
>
Allow
</label>
<!----> <!---->
</div> </gl-form-radio-stub>
`; `;
exports[`AddLicenseForm template does not show radio button descriptions, if licenseComplianceDeniesMr feature flag is disabled 2`] = ` exports[`AddLicenseForm template does not show radio button descriptions, if licenseComplianceDeniesMr feature flag is disabled 2`] = `
<div <gl-form-radio-stub
class="form-check" aria-describedby="js-blacklisted-license-radio"
class=""
data-qa-selector="blacklisted_license_radio"
value="blacklisted"
> >
<input Deny
aria-describedby="js-blacklisted-license-radio"
class="form-check-input"
data-qa-selector="blacklisted_license_radio"
id="js-blacklisted-license-radio"
type="radio"
value="blacklisted"
/>
<label
class="form-check-label pt-1"
for="js-blacklisted-license-radio"
>
Deny
</label>
<!----> <!---->
</div> </gl-form-radio-stub>
`; `;
import Vue from 'vue'; import Vue from 'vue';
import { GlFormRadio, GlFormRadioGroup } from '@gitlab/ui';
import { shallowMount, mount } from '@vue/test-utils'; import { shallowMount, mount } from '@vue/test-utils';
import LicenseIssueBody from 'ee/vue_shared/license_compliance/components/add_license_form.vue'; import LicenseIssueBody from 'ee/vue_shared/license_compliance/components/add_license_form.vue';
import { LICENSE_APPROVAL_STATUS } from 'ee/vue_shared/license_compliance/constants'; import { LICENSE_APPROVAL_STATUS } from 'ee/vue_shared/license_compliance/constants';
...@@ -16,6 +17,7 @@ const createComponent = (props = {}, mountFn = shallowMount) => { ...@@ -16,6 +17,7 @@ const createComponent = (props = {}, mountFn = shallowMount) => {
describe('AddLicenseForm', () => { describe('AddLicenseForm', () => {
const findSubmitButton = () => wrapper.find('.js-submit'); const findSubmitButton = () => wrapper.find('.js-submit');
const findCancelButton = () => wrapper.find('.js-cancel'); const findCancelButton = () => wrapper.find('.js-cancel');
const findRadioInputs = () => wrapper.find(GlFormRadioGroup).findAll(GlFormRadio);
beforeEach(() => { beforeEach(() => {
createComponent(); createComponent();
...@@ -102,23 +104,11 @@ describe('AddLicenseForm', () => { ...@@ -102,23 +104,11 @@ describe('AddLicenseForm', () => {
}); });
it('renders the license approval radio buttons dropdown', () => { it('renders the license approval radio buttons dropdown', () => {
const radioButtonParents = wrapper.findAll('.form-check'); const approvalOptions = findRadioInputs();
expect(radioButtonParents).toHaveLength(2); expect(approvalOptions).toHaveLength(2);
expect(radioButtonParents.at(0).text()).toBe('Allow'); expect(approvalOptions.at(0).text()).toBe('Allow');
expect( expect(approvalOptions.at(1).text()).toBe('Deny');
radioButtonParents
.at(0)
.find('.form-check-input')
.exists(),
).toBe(true);
expect(radioButtonParents.at(1).text()).toBe('Deny');
expect(
radioButtonParents
.at(1)
.find('.form-check-input')
.exists(),
).toBe(true);
}); });
it('renders error text, if there is a duplicate license', async () => { it('renders error text, if there is a duplicate license', async () => {
...@@ -159,10 +149,8 @@ describe('AddLicenseForm', () => { ...@@ -159,10 +149,8 @@ describe('AddLicenseForm', () => {
createComponent({ managedLicenses: [{ name: 'FOO' }] }); createComponent({ managedLicenses: [{ name: 'FOO' }] });
wrapper.setData({ licenseName: 'FOO' }); wrapper.setData({ licenseName: 'FOO' });
return Vue.nextTick().then(() => { return Vue.nextTick().then(() => {
const formCheckElements = wrapper.findAll('.form-check'); expect(findRadioInputs().at(0).element).toMatchSnapshot();
expect(findRadioInputs().at(1).element).toMatchSnapshot();
expect(formCheckElements.at(0).element).toMatchSnapshot();
expect(formCheckElements.at(1).element).toMatchSnapshot();
}); });
}); });
......
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