Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable "no" option for direct debit #539

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,24 @@
<RadioField
v-model="receiptModel.receiptNeeded"
name="donationReceipt"
:options="[
{ value: true, label: $t( 'yes' ), id: 'donationReceipt-0' },
{ value: false, label: $t( 'no' ), id: 'donationReceipt-1' },
]"
:options="receiptNeededOptions"
:label="$t( 'donation_confirmation_cta_title_alt' )"
:show-error="receiptModel.showReceiptOptionError"
:error-message="$t( 'C24_WMDE_Desktop_DE_01_receipt_error' )"
alignment="row"
aria-describedby="donation-receipt-help-text"
:disabled="disabledReceiptNeededOptions"
>
<template #intro-message>
<div class="form-field-intro" id="donation-receipt-help-text">
{{ $t( 'C24_WMDE_Desktop_DE_01_help_text' ) }}
</div>
</template>
<template #tooltip-false>
<RadioFieldHelpText v-if="isDirectDebitPayment">
{{ $t( 'donation_form_address_choice_direct_debit_disclaimer' ) }}
</RadioFieldHelpText>
</template>
</RadioField>

<AddressFields
Expand All @@ -69,7 +72,7 @@
</template>

<script setup lang="ts">
import { onBeforeMount, toRef } from 'vue';
import { computed, onBeforeMount, toRef } from 'vue';
import AddressFields from '@src/components/pages/donation_form/DonationReceipt/AddressFields.vue';
import AutofillHandler from '@src/components/shared/AutofillHandler.vue';
import EmailField from '@src/components/shared/form_fields/EmailField.vue';
Expand All @@ -89,6 +92,8 @@ import { ReceiptModel } from '@src/components/pages/donation_form/DonationReceip
import { useStore } from 'vuex';
import ScrollTarget from '@src/components/shared/ScrollTarget.vue';
import { AddressTypeModel } from '@src/view_models/AddressTypeModel';
import { useI18n } from 'vue-i18n';
import RadioFieldHelpText from '@src/components/shared/form_elements/RadioFieldTooltip.vue';
interface Props {
countries: Country[];
Expand All @@ -105,10 +110,16 @@ interface Props {
const props = defineProps<Props>();
const store = useStore();
const { t } = useI18n();
const mailingList = useMailingListModel( store );
const receiptModel = toRef<ReceiptModel>( props.receiptModel );
const receiptNeededOptions = [
{ value: true, label: t( 'yes' ), id: 'donationReceipt-0' },
{ value: false, label: t( 'no' ), id: 'donationReceipt-1' },
];
const {
formData,
fieldErrors,
Expand All @@ -121,4 +132,14 @@ useAddressTypeFromReceiptSetter( props.receiptModel.receiptNeeded, toRef( props.
onBeforeMount( initializeDataFromStore );
const disabledReceiptNeededOptions = computed<string[]>( () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is typed as a string[] but the map is returning a boolean[] which I guess is why you cast the CheckboxFormOption to Object. You can simplify this logic by changing it to:

const disabledReceiptNeededOptions = computed<boolean[]>( () => {
    return props.isDirectDebitPayment ? [ false ] : [];
} );

You can also then move the options back into the template.

let disabledOptions: string[] = [];
if ( props.isDirectDebitPayment ) {
disabledOptions = receiptNeededOptions
.filter( ( receiptNeededOption: Object ) => receiptNeededOption.value === false )
.map( ( receiptNeededOption: Object ) => receiptNeededOption.value );
}
return disabledOptions;
} );
</script>
3 changes: 3 additions & 0 deletions src/components/pages/donation_form/Payment.vue
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ const disabledPaymentTypes = computed<string[]>( () => {
if ( store.state.address.addressType === AddressTypeModel.ANON ) {
disabledTypes.push( 'BEZ' );
}
if ( store.state.address.addressType === AddressTypeModel.EMAIL ) {
disabledTypes.push( 'BEZ' );
}
if ( store.state.payment.values.interval !== '0' ) {
disabledTypes.push( 'SUB' );
}
Expand Down
1 change: 1 addition & 0 deletions src/components/shared/form_elements/RadioFieldTooltip.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ defineProps<Props>();
background: colors.$white;
&-text {
z-index: 10;
position: absolute;
display: block;
visibility: hidden;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -445,10 +445,7 @@ describe( 'DonationFormReciept.vue', () => {
submitForm.element.submit = jest.fn();

await wrapper.find( 'input[name="amount"][value="500"]' ).trigger( 'change' );
await wrapper.find( 'input[name="paymentType"][value="BEZ"]' ).trigger( 'change' );

await wrapper.find( '#iban' ).setValue( IBAN );
await wrapper.find( '#iban' ).trigger( 'blur' );
await wrapper.find( 'input[name="paymentType"][value="UEB"]' ).trigger( 'change' );

await wrapper.find( 'input[name="salutation"][value="Mr"]' ).trigger( 'change' );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,22 @@ describe( 'PersonalDataSectionDonationReceipt.vue', () => {

expect( wrapper.find( '.address-section' ).exists() ).toBeTruthy();
} );

it( 'disables NO option on question for full address and shows info icon', async () => {
const wrapper = getWrapper();

await wrapper.setProps( { isDirectDebitPayment: true } );
await nextTick();

expect( wrapper.find( '.radio-field-tooltip' ).isVisible() ).toBe( true );
} );

it( 'NO option is not disabled when direct debit is not selected', async () => {
const wrapper = getWrapper();

await wrapper.setProps( { isDirectDebitPayment: false } );
await nextTick();

expect( wrapper.find( '.radio-field-tooltip' ).exists() ).toBe( false );
} );
} );
10 changes: 9 additions & 1 deletion tests/unit/components/pages/donation_form/Payment.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,19 @@ describe( 'Payment.vue', () => {
expect( wrapper.find( '.radio-field-tooltip' ).isVisible() ).toBe( true );
} );

it( 'does not render tooltip hint if address type is something different than Anonymous', async () => {
it( 'renders tooltip hint if address type is Email-Only', async () => {
const wrapper = getWrapper();

await store.dispatch( action( 'address', 'setAddressType' ), AddressTypeModel.EMAIL );

expect( wrapper.find( '.radio-field-tooltip' ).isVisible() ).toBe( true );
} );

it( 'does not render tooltip hint if address type is something different than Anonymous or Email-only', async () => {
const wrapper = getWrapper();

await store.dispatch( action( 'address', 'setAddressType' ), AddressTypeModel.COMPANY );

expect( wrapper.find( '.radio-field-tooltip' ).exists() ).toBe( false );
} );

Expand Down
Loading