Commit 887d1391 authored by Jacques Erasmus's avatar Jacques Erasmus

Merge branch '331154-dismiss-cc-validation' into 'master'

Make the credit card validation alert dismissible

See merge request gitlab-org/gitlab!69245
parents 25697fb4 bebd27c3
...@@ -123,6 +123,7 @@ export default { ...@@ -123,6 +123,7 @@ export default {
isWarningDismissed: false, isWarningDismissed: false,
isLoading: false, isLoading: false,
submitted: false, submitted: false,
ccAlertDismissed: false,
}; };
}, },
computed: { computed: {
...@@ -151,7 +152,7 @@ export default { ...@@ -151,7 +152,7 @@ export default {
return this.form[this.refFullName]?.descriptions ?? {}; return this.form[this.refFullName]?.descriptions ?? {};
}, },
ccRequiredError() { ccRequiredError() {
return this.error === CC_VALIDATION_REQUIRED_ERROR; return this.error === CC_VALIDATION_REQUIRED_ERROR && !this.ccAlertDismissed;
}, },
}, },
watch: { watch: {
...@@ -292,6 +293,7 @@ export default { ...@@ -292,6 +293,7 @@ export default {
}, },
createPipeline() { createPipeline() {
this.submitted = true; this.submitted = true;
this.ccAlertDismissed = false;
return axios return axios
.post(this.pipelinesPath, { .post(this.pipelinesPath, {
...@@ -333,13 +335,17 @@ export default { ...@@ -333,13 +335,17 @@ export default {
this.warnings = warnings; this.warnings = warnings;
this.totalWarnings = totalWarnings; this.totalWarnings = totalWarnings;
}, },
dismissError() {
this.ccAlertDismissed = true;
this.error = null;
},
}, },
}; };
</script> </script>
<template> <template>
<gl-form @submit.prevent="createPipeline"> <gl-form @submit.prevent="createPipeline">
<cc-validation-required-alert v-if="ccRequiredError" class="gl-pb-5" /> <cc-validation-required-alert v-if="ccRequiredError" class="gl-pb-5" @dismiss="dismissError" />
<gl-alert <gl-alert
v-else-if="error" v-else-if="error"
:title="errorTitle" :title="errorTitle"
......
...@@ -43,6 +43,7 @@ export default { ...@@ -43,6 +43,7 @@ export default {
isSharedRunnerEnabled: this.isEnabled, isSharedRunnerEnabled: this.isEnabled,
errorMessage: null, errorMessage: null,
successfulValidation: false, successfulValidation: false,
ccAlertDismissed: false,
}; };
}, },
computed: { computed: {
...@@ -50,7 +51,8 @@ export default { ...@@ -50,7 +51,8 @@ export default {
return ( return (
this.isCreditCardValidationRequired && this.isCreditCardValidationRequired &&
!this.isSharedRunnerEnabled && !this.isSharedRunnerEnabled &&
!this.successfulValidation !this.successfulValidation &&
!this.ccAlertDismissed
); );
}, },
}, },
...@@ -89,6 +91,7 @@ export default { ...@@ -89,6 +91,7 @@ export default {
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"
@dismiss="ccAlertDismissed = true"
/> />
<gl-toggle <gl-toggle
......
...@@ -75,10 +75,10 @@ export default { ...@@ -75,10 +75,10 @@ export default {
<gl-alert <gl-alert
v-else v-else
variant="danger" variant="danger"
:dismissible="false"
:title="$options.i18n.dangerAlert.title" :title="$options.i18n.dangerAlert.title"
:primary-button-text="$options.i18n.dangerAlert.primaryButtonText" :primary-button-text="$options.i18n.dangerAlert.primaryButtonText"
@primaryAction="showModal" @primaryAction="showModal"
@dismiss="$emit('dismiss')"
> >
<template v-if="customMessage"> <template v-if="customMessage">
{{ customMessage }} {{ customMessage }}
......
...@@ -58,4 +58,10 @@ describe('CreditCardValidationRequiredAlert', () => { ...@@ -58,4 +58,10 @@ describe('CreditCardValidationRequiredAlert', () => {
expect(wrapper.vm.$refs.modal.hide).toHaveBeenCalled(); expect(wrapper.vm.$refs.modal.hide).toHaveBeenCalled();
expect(wrapper.emitted('verifiedCreditCard')).toBeDefined(); expect(wrapper.emitted('verifiedCreditCard')).toBeDefined();
}); });
it('danger alert emits dismiss event on dismiss', () => {
findGlAlert().vm.$emit('dismiss');
expect(wrapper.emitted('dismiss')).toBeDefined();
});
}); });
...@@ -64,6 +64,14 @@ describe('projects/settings/components/shared_runners', () => { ...@@ -64,6 +64,14 @@ describe('projects/settings/components/shared_runners', () => {
); );
}); });
it('credit card alert should be hidden after dismiss', async () => {
findCcValidationRequiredAlert().vm.$emit('dismiss');
await wrapper.vm.$nextTick();
expect(findCcValidationRequiredAlert().exists()).toBe(false);
});
describe('when credit card is validated', () => { describe('when credit card is validated', () => {
beforeEach(() => { beforeEach(() => {
findCcValidationRequiredAlert().vm.$emit('verifiedCreditCard'); findCcValidationRequiredAlert().vm.$emit('verifiedCreditCard');
......
...@@ -45,6 +45,7 @@ describe('Pipeline New Form', () => { ...@@ -45,6 +45,7 @@ describe('Pipeline New Form', () => {
const findWarningAlertSummary = () => findWarningAlert().find(GlSprintf); const findWarningAlertSummary = () => findWarningAlert().find(GlSprintf);
const findWarnings = () => wrapper.findAll('[data-testid="run-pipeline-warning"]'); const findWarnings = () => wrapper.findAll('[data-testid="run-pipeline-warning"]');
const findLoadingIcon = () => wrapper.find(GlLoadingIcon); const findLoadingIcon = () => wrapper.find(GlLoadingIcon);
const findCCAlert = () => wrapper.findComponent(CreditCardValidationRequiredAlert);
const getFormPostParams = () => JSON.parse(mock.history.post[0].data); const getFormPostParams = () => JSON.parse(mock.history.post[0].data);
const selectBranch = (branch) => { const selectBranch = (branch) => {
...@@ -387,7 +388,7 @@ describe('Pipeline New Form', () => { ...@@ -387,7 +388,7 @@ describe('Pipeline New Form', () => {
}); });
it('does not show the credit card validation required alert', () => { it('does not show the credit card validation required alert', () => {
expect(wrapper.findComponent(CreditCardValidationRequiredAlert).exists()).toBe(false); expect(findCCAlert().exists()).toBe(false);
}); });
describe('when the error response is credit card validation required', () => { describe('when the error response is credit card validation required', () => {
...@@ -408,7 +409,19 @@ describe('Pipeline New Form', () => { ...@@ -408,7 +409,19 @@ describe('Pipeline New Form', () => {
it('shows credit card validation required alert', () => { it('shows credit card validation required alert', () => {
expect(findErrorAlert().exists()).toBe(false); expect(findErrorAlert().exists()).toBe(false);
expect(wrapper.findComponent(CreditCardValidationRequiredAlert).exists()).toBe(true); expect(findCCAlert().exists()).toBe(true);
});
it('clears error and hides the alert on dismiss', async () => {
expect(findCCAlert().exists()).toBe(true);
expect(wrapper.vm.$data.error).toBe(mockCreditCardValidationRequiredError.errors[0]);
findCCAlert().vm.$emit('dismiss');
await wrapper.vm.$nextTick();
expect(findCCAlert().exists()).toBe(false);
expect(wrapper.vm.$data.error).toBe(null);
}); });
}); });
}); });
......
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