Skip to content

Commit

Permalink
Fix more tests, write new tests
Browse files Browse the repository at this point in the history
  • Loading branch information
moiikana committed Sep 4, 2024
1 parent fea3999 commit b7bba1a
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ describe( 'AddressTypeBasic.vue', () => {
expect( anonymous.attributes( 'disabled' ) ).toBeDefined();
} );

it( 'renders hint if payment is direct debit', () => {
it( 'renders tooltip hint if payment is direct debit', () => {
const wrapper = getWrapper( [ AddressTypeModel.ANON ], true );

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

it( 'does not render hint if payment is not direct debit', () => {
it( 'does not render tooltip hint if payment is not direct debit', () => {
const wrapper = getWrapper( [ AddressTypeModel.ANON ], false );

expect( wrapper.find( '.form-field-intro' ).isVisible() ).toBe( false );
expect( wrapper.find( '.radio-field-tooltip' ).exists() ).toBe( false );
} );
} );
36 changes: 35 additions & 1 deletion tests/unit/components/pages/donation_form/Payment.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe( 'Payment.vue', () => {
props: {
paymentAmounts: [ 5 ],
paymentIntervals: [ 0, 1, 3, 6, 12 ],
paymentTypes: [ 'BEZ', 'PPL', 'UEB', 'BTC' ],
paymentTypes: [ 'BEZ', 'PPL', 'UEB', 'SUB', 'BTC' ],
},
global: {
plugins: [ store ],
Expand Down Expand Up @@ -56,4 +56,38 @@ describe( 'Payment.vue', () => {
expect( store.dispatch ).toBeCalledWith( action( 'payment', 'setType' ), 'PPL' );
} );

it( 'renders tooltip hint if SUB payment method is disabled', async () => {
const wrapper = getWrapper();

await wrapper.find<HTMLInputElement>( '#interval-1' ).trigger( 'change' );
await nextTick();

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

it( 'does not render tooltip hint if SUB payment method is enabled', async () => {
const wrapper = getWrapper();

await wrapper.find( '#interval-0' ).trigger( 'click' );
await nextTick();

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

it( 'renders tooltip hint if address type is Anonymous', async () => {
const wrapper = getWrapper();

// TODO trigger store to have anonymous address type set

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

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

// TODO trigger store to have something else than anonymous address type set

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

} );
Original file line number Diff line number Diff line change
Expand Up @@ -36,34 +36,7 @@ describe( 'PaymentSection.vue', () => {
global.window.scrollTo = jest.fn();
} );

it( 'validates the input on page submit', async () => {
const { wrapper, store } = getWrapper();
store.dispatch = jest.fn().mockResolvedValue( true );

await wrapper.find( '#submit-btn' ).trigger( 'click' );

expect( store.dispatch ).toHaveBeenCalledWith( action( 'payment', 'markEmptyValuesAsInvalid' ) );
} );

it.skip( 'emits event if there are no validation errors', async () => {
const { wrapper } = getWrapper();

await wrapper.find( '#amount-500' ).trigger( 'change' );
await wrapper.find( '#paymentType-0' ).trigger( 'change' );
await wrapper.find( '#submit-btn' ).trigger( 'click' );

expect( wrapper.emitted( 'next-page' ) ).toBeTruthy();
} );

it.skip( 'doesn\'t emit event if there are validation errors', async () => {
const { wrapper, store } = getWrapper();
store.dispatch = jest.fn().mockResolvedValue( true );

await wrapper.find( '#submit-btn' ).trigger( 'click' );

expect( wrapper.emitted( 'next-page' ) ).toBeUndefined();
} );

//TODO this won't work because the error summary is now shown in the personaldatasection, not in this wrapper

Check failure on line 39 in tests/unit/components/pages/donation_form/single_page_form/PaymentSection.spec.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Expected exception block, space or tab after '//' in comment
it( 'shows and hides the error summary', async () => {
const { wrapper } = getWrapper();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ describe( 'PersonalDataSection.vue', () => {
const wrapper = mount( PersonalDataSection, {
props: {
assetsPath: '',
validateAddressUrl: '',
validateEmailUrl: '',
validateAddressUrl: 'https://localhost:8082',
validateEmailUrl: 'https://localhost:8082',
validateBankDataUrl: 'https://localhost:8082',
validateLegacyBankDataUrl: 'https://localhost:8082',
countries: [ testCountry ],
Expand Down Expand Up @@ -119,14 +119,16 @@ describe( 'PersonalDataSection.vue', () => {
} );

it( 'shows and hides the error summary', async () => {
const { wrapper } = getWrapper();
const { wrapper, store } = getWrapper();

await wrapper.find( '#submit-btn' ).trigger( 'click' );
await nextTick();
await nextTick();

expect( wrapper.find( '.error-summary' ).exists() ).toBeTruthy();

await setPaymentType( store, 'UEB' );

await wrapper.find( '#addressType-0' ).trigger( 'change' );
await wrapper.find( '#person-salutation-0' ).trigger( 'change' );

Expand Down Expand Up @@ -164,8 +166,18 @@ describe( 'PersonalDataSection.vue', () => {
expect( wrapper.find( '.address-type-person' ).exists() ).toBeTruthy();
} );

it( 'validates the payment section input on page submit', async () => {
const { wrapper, store } = getWrapper();
store.dispatch = jest.fn().mockResolvedValue( true );

await wrapper.find( '#submit-btn' ).trigger( 'click' );

expect( store.dispatch ).toHaveBeenCalledWith( action( 'payment', 'markEmptyValuesAsInvalid' ) );
} );

it( 'submits the form', async () => {
const store = createStore();
await setPaymentType( store, 'UEB' );
await store.dispatch( action( 'address', 'initializeAddress' ), {
addressType: AddressTypeModel.ANON,
newsletter: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ describe( 'PersonalDataSectionDonationReceipt.vue', () => {
const { wrapper } = getWrapper();

await wrapper.find( '#previous-btn' ).trigger( 'click' );
await nextTick();

//TODO test that payment section got scrolled to

Check failure on line 116 in tests/unit/components/pages/donation_form/single_page_form/PersonalDataSectionDonationReceipt.spec.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Expected exception block, space or tab after '//' in comment
expect( focusElement.focus ).toHaveBeenCalledWith( { preventScroll: true } );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ import SinglePageDonationForm from '@src/components/pages/SinglePageDonationForm
import countries from '@src/../tests/data/countries';
import { AddressValidation } from '@src/view_models/Validation';
import { createFeatureToggle } from '@src/util/createFeatureToggle';
import PaymentPage from '@test/data/DonationFormPages/PaymentPageStub.vue';
import AddressPage from '@test/data/DonationFormPages/AddressPageStub.vue';
import { nextTick } from 'vue';
import PaymentSection from '@src/components/pages/donation_form/singlePageFromSections/PaymentSection.vue';
import PersonalDataSection from '@src/components/pages/donation_form/singlePageFromSections/PersonalDataSection.vue';
import { Store } from 'vuex';
import { createStore } from '@src/store/donation_store';

declare global {
namespace NodeJS {
Expand All @@ -21,8 +22,8 @@ describe( 'SinglePageDonationForm.vue', () => {
global.window.scrollTo = jest.fn();
} );

const getWrapper = ( startPageIndex: 0 | 1 = 0 ): VueWrapper<any> => {
return mount( SinglePageDonationForm, {
const getWrapper = ( store: Store<any> = createStore() ): { wrapper: VueWrapper<any>, store: Store<any> } => {
const wrapper = mount( SinglePageDonationForm, {
props: {
assetsPath: '',
paymentAmounts: [ 5 ],
Expand All @@ -37,27 +38,21 @@ describe( 'SinglePageDonationForm.vue', () => {
validateLegacyBankDataUrl: '',
salutations: [],
addressValidationPatterns: {} as AddressValidation,
startPageIndex,
usesContentCards: true,
},
global: {
stubs: {
PaymentPage,
AddressPage,
},
plugins: [ store ],
components: {
FeatureToggle: createFeatureToggle( [ 'campaigns.address_pages.legacy' ] ),
},
},
} );
return { wrapper, store };
};

it( 'displays payment section and address data section', () => {
const wrapper = getWrapper().wrapper;
expect( wrapper.findComponent( PaymentSection ).exists() ).toBe( true );
expect( wrapper.findComponent( PersonalDataSection ).exists() ).toBe( true );
} );

it( 'displays Payment page by default ', () => {
const wrapper = getWrapper( 0 );
expect( wrapper.find( '.i-am-payment' ).exists() ).toBe( true );
} );


} );

0 comments on commit b7bba1a

Please sign in to comment.