Commit 13977e57 authored by Miguel Rincon's avatar Miguel Rincon

Merge branch '334863-modal-checkbox' into 'master'

Show invalid checkbox state in Activation Modal

See merge request gitlab-org/gitlab!65120
parents 1774f349 2dc1ff79
...@@ -11,7 +11,6 @@ import { ...@@ -11,7 +11,6 @@ import {
import validation from '~/vue_shared/directives/validation'; import validation from '~/vue_shared/directives/validation';
import { import {
activateLabel, activateLabel,
fieldRequiredMessage,
INVALID_CODE_ERROR, INVALID_CODE_ERROR,
INVALID_CODE_ERROR_MESSAGE, INVALID_CODE_ERROR_MESSAGE,
subscriptionActivationForm, subscriptionActivationForm,
...@@ -37,7 +36,6 @@ export default { ...@@ -37,7 +36,6 @@ export default {
acceptTerms: subscriptionActivationForm.acceptTerms, acceptTerms: subscriptionActivationForm.acceptTerms,
activateLabel, activateLabel,
activationCode: subscriptionActivationForm.activationCode, activationCode: subscriptionActivationForm.activationCode,
fieldRequiredMessage,
pasteActivationCode: subscriptionActivationForm.pasteActivationCode, pasteActivationCode: subscriptionActivationForm.pasteActivationCode,
}, },
directives: { directives: {
...@@ -74,6 +72,10 @@ export default { ...@@ -74,6 +72,10 @@ export default {
}; };
}, },
computed: { computed: {
checkboxLabelClass() {
// by default, if the value is not false the text will look green, therefore we force it to gray-900
return this.form.fields.terms.state === false ? '' : 'gl-text-gray-900!';
},
isRequestingActivation() { isRequestingActivation() {
return this.isLoading; return this.isLoading;
}, },
...@@ -142,11 +144,7 @@ export default { ...@@ -142,11 +144,7 @@ export default {
/> />
</gl-form-group> </gl-form-group>
<gl-form-group <gl-form-group class="gl-mb-0" data-testid="form-group-terms">
class="gl-mb-0"
:invalid-feedback="$options.i18n.fieldRequiredMessage"
data-testid="form-group-terms"
>
<gl-form-checkbox <gl-form-checkbox
id="subscription-form-terms-check" id="subscription-form-terms-check"
v-model="form.fields.terms.value" v-model="form.fields.terms.value"
...@@ -155,7 +153,7 @@ export default { ...@@ -155,7 +153,7 @@ export default {
name="terms" name="terms"
required required
> >
<span class="gl-text-gray-900!"> <span :class="checkboxLabelClass">
<gl-sprintf :message="$options.i18n.acceptTerms"> <gl-sprintf :message="$options.i18n.acceptTerms">
<template #link="{ content }"> <template #link="{ content }">
<gl-link href="https://about.gitlab.com/terms/" target="_blank">{{ <gl-link href="https://about.gitlab.com/terms/" target="_blank">{{
......
...@@ -3,7 +3,6 @@ import activateSubscriptionMutation from './graphql/mutations/activate_subscript ...@@ -3,7 +3,6 @@ import activateSubscriptionMutation from './graphql/mutations/activate_subscript
import getCurrentLicense from './graphql/queries/get_current_license.query.graphql'; import getCurrentLicense from './graphql/queries/get_current_license.query.graphql';
import getLicenseHistory from './graphql/queries/get_license_history.query.graphql'; import getLicenseHistory from './graphql/queries/get_license_history.query.graphql';
export const fieldRequiredMessage = s__('SuperSonics|This field is required.');
export const subscriptionMainTitle = s__('SuperSonics|Your subscription'); export const subscriptionMainTitle = s__('SuperSonics|Your subscription');
export const subscriptionActivationNotificationText = s__( export const subscriptionActivationNotificationText = s__(
`SuperSonics|Your subscription was successfully activated. You can see the details below.`, `SuperSonics|Your subscription was successfully activated. You can see the details below.`,
......
...@@ -7,7 +7,6 @@ import SubscriptionActivationForm, { ...@@ -7,7 +7,6 @@ import SubscriptionActivationForm, {
} from 'ee/admin/subscriptions/show/components/subscription_activation_form.vue'; } from 'ee/admin/subscriptions/show/components/subscription_activation_form.vue';
import { import {
CONNECTIVITY_ERROR, CONNECTIVITY_ERROR,
fieldRequiredMessage,
INVALID_CODE_ERROR, INVALID_CODE_ERROR,
subscriptionQueries, subscriptionQueries,
} from 'ee/admin/subscriptions/show/constants'; } from 'ee/admin/subscriptions/show/constants';
...@@ -20,11 +19,11 @@ import { activateLicenseMutationResponse } from '../mock_data'; ...@@ -20,11 +19,11 @@ import { activateLicenseMutationResponse } from '../mock_data';
const localVue = createLocalVue(); const localVue = createLocalVue();
localVue.use(VueApollo); localVue.use(VueApollo);
describe('CloudLicenseApp', () => { describe('SubscriptionActivationForm', () => {
let wrapper; let wrapper;
const fakeActivationCode = 'gEg959hDCkvM2d4Der5RyktT '; const fakeActivationCodeTrimmed = 'aaasddfffdddas';
const fakeActivationCodeTrimmed = 'gEg959hDCkvM2d4Der5RyktT'; const fakeActivationCode = `${fakeActivationCodeTrimmed} `;
const createMockApolloProvider = (resolverMock) => { const createMockApolloProvider = (resolverMock) => {
localVue.use(VueApollo); localVue.use(VueApollo);
...@@ -34,7 +33,8 @@ describe('CloudLicenseApp', () => { ...@@ -34,7 +33,8 @@ describe('CloudLicenseApp', () => {
const findActivateButton = () => wrapper.findByTestId('activate-button'); const findActivateButton = () => wrapper.findByTestId('activate-button');
const findAgreementCheckbox = () => wrapper.findComponent(GlFormCheckbox); const findAgreementCheckbox = () => wrapper.findComponent(GlFormCheckbox);
const findAgreementCheckboxInput = () => findAgreementCheckbox().find('input'); const findAgreementCheckboxInput = () => findAgreementCheckbox().find('input');
const findAgreementCheckboxFormGroup = () => wrapper.findByTestId('form-group-terms'); const findAgreementCheckboxFormGroupSpan = () =>
wrapper.findByTestId('form-group-terms').find('span');
const findActivationCodeFormGroup = () => wrapper.findByTestId('form-group-activation-code'); const findActivationCodeFormGroup = () => wrapper.findByTestId('form-group-activation-code');
const findActivationCodeInput = () => wrapper.findComponent(GlFormInput); const findActivationCodeInput = () => wrapper.findComponent(GlFormInput);
const findActivateSubscriptionForm = () => wrapper.findComponent(GlForm); const findActivateSubscriptionForm = () => wrapper.findComponent(GlForm);
...@@ -67,7 +67,7 @@ describe('CloudLicenseApp', () => { ...@@ -67,7 +67,7 @@ describe('CloudLicenseApp', () => {
wrapper.destroy(); wrapper.destroy();
}); });
describe('Subscription Activation Form', () => { describe('component setup', () => {
beforeEach(() => createComponentWithApollo()); beforeEach(() => createComponentWithApollo());
it('presents a form', () => { it('presents a form', () => {
...@@ -78,6 +78,10 @@ describe('CloudLicenseApp', () => { ...@@ -78,6 +78,10 @@ describe('CloudLicenseApp', () => {
expect(findActivationCodeInput().exists()).toBe(true); expect(findActivationCodeInput().exists()).toBe(true);
}); });
it('applies a class to the checkbox', () => {
expect(findAgreementCheckboxFormGroupSpan().attributes('class')).toBe('gl-text-gray-900!');
});
it('has an `Activate` button', () => { it('has an `Activate` button', () => {
expect(findActivateButton().text()).toBe('Activate'); expect(findActivateButton().text()).toBe('Activate');
}); });
...@@ -91,26 +95,20 @@ describe('CloudLicenseApp', () => { ...@@ -91,26 +95,20 @@ describe('CloudLicenseApp', () => {
}); });
}); });
describe('form errors', () => { describe('form validation', () => {
const mutationMock = jest.fn(); const mutationMock = jest.fn();
beforeEach(() => { beforeEach(async () => {
createComponentWithApollo({ mutationMock }); createComponentWithApollo({ mutationMock, mountMethod: mount });
await findAgreementCheckbox().vm.$emit('input', false);
findActivateSubscriptionForm().vm.$emit('submit', createFakeEvent());
}); });
it('shows an error for the text field', async () => { it('shows an error for the text field', () => {
await findActivateSubscriptionForm().vm.$emit('submit', createFakeEvent()); expect(findActivationCodeFormGroup().text()).toContain('Please fill out this field.');
expect(findActivationCodeFormGroup().attributes('invalid-feedback')).toBe(
'Please fill out this field.',
);
}); });
it('shows an error for the checkbox field', async () => { it('applies the correct class', () => {
await findActivationCodeInput().vm.$emit('input', fakeActivationCode); expect(findAgreementCheckboxFormGroupSpan().attributes('class')).toBe('');
expect(findAgreementCheckboxFormGroup().attributes('invalid-feedback')).toBe(
fieldRequiredMessage,
);
}); });
it('does not perform any mutation', () => { it('does not perform any mutation', () => {
......
...@@ -31521,9 +31521,6 @@ msgstr "" ...@@ -31521,9 +31521,6 @@ msgstr ""
msgid "SuperSonics|There is a connectivity issue." msgid "SuperSonics|There is a connectivity issue."
msgstr "" msgstr ""
msgid "SuperSonics|This field is required."
msgstr ""
msgid "SuperSonics|This is the highest peak of users on your installation since the license started." msgid "SuperSonics|This is the highest peak of users on your installation since the license started."
msgstr "" msgstr ""
......
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