Commit eca1751b authored by Kushal Pandya's avatar Kushal Pandya

Merge branch 'dpisek-use-gl-form-for-primary-sec-provider-selection' into 'master'

Use gl-form-radio for setting primary security training provider

See merge request gitlab-org/gitlab!83563
parents b33962f1 1e180b7e
...@@ -3,6 +3,7 @@ import { ...@@ -3,6 +3,7 @@ import {
GlAlert, GlAlert,
GlTooltipDirective, GlTooltipDirective,
GlCard, GlCard,
GlFormRadio,
GlToggle, GlToggle,
GlLink, GlLink,
GlSkeletonLoader, GlSkeletonLoader,
...@@ -44,6 +45,7 @@ export default { ...@@ -44,6 +45,7 @@ export default {
components: { components: {
GlAlert, GlAlert,
GlCard, GlCard,
GlFormRadio,
GlToggle, GlToggle,
GlLink, GlLink,
GlSkeletonLoader, GlSkeletonLoader,
...@@ -79,6 +81,9 @@ export default { ...@@ -79,6 +81,9 @@ export default {
}; };
}, },
computed: { computed: {
primaryProviderId() {
return this.securityTrainingProviders.find(({ isPrimary }) => isPrimary)?.id;
},
enabledProviders() { enabledProviders() {
return this.securityTrainingProviders.filter(({ isEnabled }) => isEnabled); return this.securityTrainingProviders.filter(({ isEnabled }) => isEnabled);
}, },
...@@ -256,31 +261,19 @@ export default { ...@@ -256,31 +261,19 @@ export default {
{{ __('Learn more.') }} {{ __('Learn more.') }}
</gl-link> </gl-link>
</p> </p>
<!-- Note: The following `div` and it's content will be replaced by 'GlFormRadio' once https://gitlab.com/gitlab-org/gitlab-ui/-/issues/1720#note_857342988 is resolved --> <gl-form-radio
<div :checked="primaryProviderId"
class="gl-form-radio custom-control custom-radio" :disabled="!provider.isEnabled"
data-testid="primary-provider-radio" :value="provider.id"
@change="setPrimaryProvider(provider)"
> >
<input {{ $options.i18n.primaryTraining }}
:id="`security-training-provider-${provider.id}`"
type="radio"
:checked="provider.isPrimary"
class="custom-control-input"
:disabled="!provider.isEnabled"
@change="setPrimaryProvider(provider)"
/>
<label
class="custom-control-label"
:for="`security-training-provider-${provider.id}`"
>
{{ $options.i18n.primaryTraining }}
</label>
<gl-icon <gl-icon
v-gl-tooltip="$options.i18n.primaryTrainingDescription" v-gl-tooltip="$options.i18n.primaryTrainingDescription"
name="information-o" name="information-o"
class="gl-ml-2 gl-cursor-help" class="gl-ml-2 gl-cursor-help"
/> />
</div> </gl-form-radio>
</div> </div>
</div> </div>
</gl-card> </gl-card>
......
import * as Sentry from '@sentry/browser'; import * as Sentry from '@sentry/browser';
import { GlAlert, GlLink, GlToggle, GlCard, GlSkeletonLoader, GlIcon } from '@gitlab/ui'; import {
GlAlert,
GlLink,
GlFormRadio,
GlToggle,
GlCard,
GlSkeletonLoader,
GlIcon,
} from '@gitlab/ui';
import Vue from 'vue'; import Vue from 'vue';
import VueApollo from 'vue-apollo'; import VueApollo from 'vue-apollo';
import { shallowMountExtended } from 'helpers/vue_test_utils_helper'; import { shallowMountExtended } from 'helpers/vue_test_utils_helper';
...@@ -87,7 +95,7 @@ describe('TrainingProviderList component', () => { ...@@ -87,7 +95,7 @@ describe('TrainingProviderList component', () => {
const findLinks = () => wrapper.findAllComponents(GlLink); const findLinks = () => wrapper.findAllComponents(GlLink);
const findToggles = () => wrapper.findAllComponents(GlToggle); const findToggles = () => wrapper.findAllComponents(GlToggle);
const findFirstToggle = () => findToggles().at(0); const findFirstToggle = () => findToggles().at(0);
const findPrimaryProviderRadios = () => wrapper.findAllByTestId('primary-provider-radio'); const findPrimaryProviderRadios = () => wrapper.findAllComponents(GlFormRadio);
const findLoader = () => wrapper.findComponent(GlSkeletonLoader); const findLoader = () => wrapper.findComponent(GlSkeletonLoader);
const findErrorAlert = () => wrapper.findComponent(GlAlert); const findErrorAlert = () => wrapper.findComponent(GlAlert);
const findLogos = () => wrapper.findAllByTestId('provider-logo'); const findLogos = () => wrapper.findAllByTestId('provider-logo');
...@@ -177,8 +185,8 @@ describe('TrainingProviderList component', () => { ...@@ -177,8 +185,8 @@ describe('TrainingProviderList component', () => {
const primaryProviderRadioForCurrentCard = findPrimaryProviderRadios().at(index); const primaryProviderRadioForCurrentCard = findPrimaryProviderRadios().at(index);
// if the given provider is not enabled it should not be possible select it as primary // if the given provider is not enabled it should not be possible select it as primary
expect(primaryProviderRadioForCurrentCard.find('input').attributes('disabled')).toBe( expect(primaryProviderRadioForCurrentCard.attributes('disabled')).toBe(
isEnabled ? undefined : 'disabled', isEnabled ? undefined : 'true',
); );
expect(primaryProviderRadioForCurrentCard.text()).toBe( expect(primaryProviderRadioForCurrentCard.text()).toBe(
......
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