Commit a5514584 authored by Vitaly Slobodin's avatar Vitaly Slobodin

Merge branch 'sh-cc-validation-toggle-fix' into 'master'

Fix toggling of shared runners when credit card is needed

See merge request gitlab-org/gitlab!65100
parents 61b8062a 7bebbd40
...@@ -40,18 +40,23 @@ export default { ...@@ -40,18 +40,23 @@ export default {
data() { data() {
return { return {
isLoading: false, isLoading: false,
isSharedRunnerEnabled: false, isSharedRunnerEnabled: this.isEnabled,
errorMessage: null, errorMessage: null,
isCcValidationRequired: false, successfulValidation: false,
}; };
}, },
created() { computed: {
this.isSharedRunnerEnabled = this.isEnabled; showCreditCardValidation() {
this.isCcValidationRequired = this.isCreditCardValidationRequired; return (
this.isCreditCardValidationRequired &&
!this.isSharedRunnerEnabled &&
!this.successfulValidation
);
},
}, },
methods: { methods: {
creditCardValidated() { creditCardValidated() {
this.isCcValidationRequired = false; this.successfulValidation = true;
}, },
toggleSharedRunners() { toggleSharedRunners() {
this.isLoading = true; this.isLoading = true;
...@@ -62,7 +67,6 @@ export default { ...@@ -62,7 +67,6 @@ export default {
.then(() => { .then(() => {
this.isLoading = false; this.isLoading = false;
this.isSharedRunnerEnabled = !this.isSharedRunnerEnabled; this.isSharedRunnerEnabled = !this.isSharedRunnerEnabled;
this.isCcValidationRequired = this.isCreditCardValidationRequired;
}) })
.catch((error) => { .catch((error) => {
this.isLoading = false; this.isLoading = false;
...@@ -81,7 +85,7 @@ export default { ...@@ -81,7 +85,7 @@ export default {
</gl-alert> </gl-alert>
<cc-validation-required-alert <cc-validation-required-alert
v-if="isCcValidationRequired && !isSharedRunnerEnabled" v-if="showCreditCardValidation"
class="gl-pb-5" class="gl-pb-5"
:custom-message="$options.i18n.REQUIRES_VALIDATION_TEXT" :custom-message="$options.i18n.REQUIRES_VALIDATION_TEXT"
@verifiedCreditCard="creditCardValidated" @verifiedCreditCard="creditCardValidated"
......
import { GlToggle } from '@gitlab/ui'; import { GlToggle } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils'; import { shallowMount } from '@vue/test-utils';
import MockAxiosAdapter from 'axios-mock-adapter';
import CcValidationRequiredAlert from 'ee_component/billings/components/cc_validation_required_alert.vue'; import CcValidationRequiredAlert from 'ee_component/billings/components/cc_validation_required_alert.vue';
import { TEST_HOST } from 'helpers/test_constants'; import { TEST_HOST } from 'helpers/test_constants';
import waitForPromises from 'helpers/wait_for_promises'; import waitForPromises from 'helpers/wait_for_promises';
import axios from '~/lib/utils/axios_utils';
import SharedRunnersToggleComponent from '~/projects/settings/components/shared_runners_toggle.vue'; import SharedRunnersToggleComponent from '~/projects/settings/components/shared_runners_toggle.vue';
const TEST_UPDATE_PATH = '/test/update_shared_runners'; const TEST_UPDATE_PATH = '/test/update_shared_runners';
describe('projects/settings/components/shared_runners', () => { describe('projects/settings/components/shared_runners', () => {
let wrapper; let wrapper;
let mockAxios;
const createComponent = (props = {}) => { const createComponent = (props = {}) => {
wrapper = shallowMount(SharedRunnersToggleComponent, { wrapper = shallowMount(SharedRunnersToggleComponent, {
...@@ -28,6 +31,11 @@ describe('projects/settings/components/shared_runners', () => { ...@@ -28,6 +31,11 @@ describe('projects/settings/components/shared_runners', () => {
const getToggleValue = () => findSharedRunnersToggle().props('value'); const getToggleValue = () => findSharedRunnersToggle().props('value');
const isToggleDisabled = () => findSharedRunnersToggle().props('disabled'); const isToggleDisabled = () => findSharedRunnersToggle().props('disabled');
beforeEach(() => {
mockAxios = new MockAxiosAdapter(axios);
mockAxios.onPost(TEST_UPDATE_PATH).reply(200);
});
afterEach(() => { afterEach(() => {
wrapper.destroy(); wrapper.destroy();
}); });
...@@ -57,14 +65,31 @@ describe('projects/settings/components/shared_runners', () => { ...@@ -57,14 +65,31 @@ describe('projects/settings/components/shared_runners', () => {
}); });
describe('when credit card is validated', () => { describe('when credit card is validated', () => {
it('should show the toggle button', async () => { beforeEach(() => {
findCcValidationRequiredAlert().vm.$emit('verifiedCreditCard'); findCcValidationRequiredAlert().vm.$emit('verifiedCreditCard');
await waitForPromises(); });
it('should show the toggle button', () => {
expect(findSharedRunnersToggle().exists()).toBe(true); expect(findSharedRunnersToggle().exists()).toBe(true);
expect(getToggleValue()).toBe(false); expect(getToggleValue()).toBe(false);
expect(isToggleDisabled()).toBe(false); expect(isToggleDisabled()).toBe(false);
}); });
it('should not show credit card alert after toggling on and off', async () => {
findSharedRunnersToggle().vm.$emit('change', true);
await waitForPromises();
expect(mockAxios.history.post[0].data).toBeUndefined();
expect(mockAxios.history.post).toHaveLength(1);
expect(findCcValidationRequiredAlert().exists()).toBe(false);
findSharedRunnersToggle().vm.$emit('change', false);
await waitForPromises();
expect(mockAxios.history.post[1].data).toBeUndefined();
expect(mockAxios.history.post).toHaveLength(2);
expect(findCcValidationRequiredAlert().exists()).toBe(false);
});
}); });
}); });
}); });
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