Skip to content

Commit

Permalink
Merge pull request #548 from wmde/initialise-receipt
Browse files Browse the repository at this point in the history
Add receipt option handling from backend
  • Loading branch information
Abban authored Dec 19, 2024
2 parents 7a210df + 9c75f0b commit 0c0dbcb
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 8 deletions.
4 changes: 3 additions & 1 deletion src/store/dataInitializers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ export const createInitialDonationAddressValues = ( dataPersister: DataPersister
// reloading the page (and restoring from localStorage) happens less often than coming back from a banner
addressType: replaceInitialValue( dataPersister.getValue( 'addressType' ), initialFormValues.addressType ),
newsletter: replaceInitialValue( MAILING_LIST_ADDRESS_PAGE, dataPersister.getValue( 'newsletter' ) ),
receipt: replaceInitialValue( null, dataPersister.getValue( 'receipt' ) ),
// The receipt chosen by the user in the banner should override the choice made later, assuming that
// reloading the page (and restoring from localStorage) happens less often than coming back from a banner
receipt: replaceInitialValue( dataPersister.getValue( 'receipt' ), initialFormValues.receipt ),
fields: addressPersistItems,
};
};
Expand Down
23 changes: 20 additions & 3 deletions tests/unit/components/pages/donation_form/DonationForm.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { nextTick } from 'vue';
import axios from 'axios';
import { newSucceedingBankValidationResource } from '@test/unit/TestDoubles/SucceedingBankValidationResource';
import { IBAN } from '@test/data/bankdata';
import { action } from '@src/store/util';
import { Store } from 'vuex';

jest.mock( 'axios' );
const mockedAxios = axios as jest.Mocked<typeof axios>;
Expand Down Expand Up @@ -39,8 +41,7 @@ describe( 'DonationForm.vue', () => {
document.getElementsByTagName( 'html' )[ 0 ].innerHTML = '';
} );

const getWrapper = (): VueWrapper<any> => {
const store = createStore();
const getWrapper = ( store: Store<any> = null ): VueWrapper<any> => {
return mount( DonationForm, {
props: {
assetsPath: '',
Expand Down Expand Up @@ -79,7 +80,7 @@ describe( 'DonationForm.vue', () => {
addressValidationPatterns: { postcode: '', country: null } as AddressValidation,
},
global: {
plugins: [ store ],
plugins: [ store ?? createStore() ],
provide: {
bankValidationResource: newSucceedingBankValidationResource(),
},
Expand All @@ -96,6 +97,22 @@ describe( 'DonationForm.vue', () => {
expect( wrapper.find<HTMLInputElement>( '#person-newsletter' ).element.checked ).toBeTruthy();
} );

it( 'sets the correct receipt wanted field', async () => {
const store = createStore();
await store.dispatch( action( 'address', 'initializeAddress' ), { receipt: true, fields: [] } );
const wrapper = getWrapper( store );

expect( wrapper.find<HTMLInputElement>( '#receipt-option-person' ).element.checked ).toBeTruthy();
} );

it( 'sets the correct receipt not wanted field', async () => {
const store = createStore();
await store.dispatch( action( 'address', 'initializeAddress' ), { receipt: false, fields: [] } );
const wrapper = getWrapper( store );

expect( wrapper.find<HTMLInputElement>( '#receipt-option-person' ).element.checked ).toBeFalsy();
} );

it( 'handles the error summary when no address type was selected before submitting', async () => {
const wrapper = getWrapper();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { nextTick } from 'vue';
import axios from 'axios';
import { newSucceedingBankValidationResource } from '@test/unit/TestDoubles/SucceedingBankValidationResource';
import { IBAN } from '@test/data/bankdata';
import { Store } from 'vuex';
import { action } from '@src/store/util';

jest.mock( 'axios' );
const mockedAxios = axios as jest.Mocked<typeof axios>;
Expand Down Expand Up @@ -39,8 +41,7 @@ describe( 'DonationFormReciept.vue', () => {
document.getElementsByTagName( 'html' )[ 0 ].innerHTML = '';
} );

const getWrapper = (): VueWrapper<any> => {
const store = createStore();
const getWrapper = ( store: Store<any> = null ): VueWrapper<any> => {
return mount( DonationForm, {
props: {
assetsPath: '',
Expand Down Expand Up @@ -79,7 +80,7 @@ describe( 'DonationFormReciept.vue', () => {
addressValidationPatterns: { postcode: '', country: null } as AddressValidation,
},
global: {
plugins: [ store ],
plugins: [ store ?? createStore() ],
provide: {
bankValidationResource: newSucceedingBankValidationResource(),
},
Expand All @@ -97,6 +98,24 @@ describe( 'DonationFormReciept.vue', () => {
expect( wrapper.find<HTMLInputElement>( '#donationReceipt-1' ).element.checked ).toBeFalsy();
} );

it( 'sets the correct receipt wanted field', async () => {
const store = createStore();
await store.dispatch( action( 'address', 'initializeAddress' ), { receipt: true, fields: [] } );
const wrapper = getWrapper( store );

expect( wrapper.find<HTMLInputElement>( '#donationReceipt-0' ).element.checked ).toBeTruthy();
expect( wrapper.find<HTMLInputElement>( '#donationReceipt-1' ).element.checked ).toBeFalsy();
} );

it( 'sets the correct receipt not wanted field', async () => {
const store = createStore();
await store.dispatch( action( 'address', 'initializeAddress' ), { receipt: false, fields: [] } );
const wrapper = getWrapper( store );

expect( wrapper.find<HTMLInputElement>( '#donationReceipt-0' ).element.checked ).toBeFalsy();
expect( wrapper.find<HTMLInputElement>( '#donationReceipt-1' ).element.checked ).toBeTruthy();
} );

it( 'handles the error summary when no receipt option was selected before submitting', async () => {
const wrapper = getWrapper();

Expand Down
11 changes: 10 additions & 1 deletion tests/unit/store/dataInitializers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe( 'createInitialDonationAddressValues', () => {
expect( values.addressType ).toEqual( AddressTypeModel.ANON );
} );

it( 'uses initial address type over stored address type over', () => {
it( 'uses initial address type over stored address type', () => {
const storedAddressType = { key: 'addressType', value: AddressTypeModel.PERSON };
const initialAddressType = 'firma';

Expand Down Expand Up @@ -58,6 +58,15 @@ describe( 'createInitialDonationAddressValues', () => {

expect( values.addressType ).toEqual( AddressTypeModel.PERSON );
} );

it( 'uses stored receipt when initial receipt is missing', () => {
const storedReceipt = { key: 'receipt', value: true };

const dataPersister = new FakeDataPersister( [ storedReceipt ] );
const values = createInitialDonationAddressValues( dataPersister, {} );

expect( values.receipt ).toEqual( true );
} );
} );

describe( 'createInitialDonationPaymentValues', () => {
Expand Down

0 comments on commit 0c0dbcb

Please sign in to comment.