Skip to content

Commit

Permalink
Fix some tests and clean up code
Browse files Browse the repository at this point in the history
- remove unused statements in the code
- fix warning in test setup
- fix scroll tests

https://phabricator.wikimedia.org/T368525
  • Loading branch information
moiikana committed Sep 17, 2024
1 parent 01110bc commit 14f4aac
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ const props = defineProps<Props>();
const campaignParams = inject<string>( QUERY_STRING_INJECTION_KEY, '' );
const isFullSelected = ref( false );
const store = useStore();
defineExpose( { focus: (): void => pageRef.value.focus() } );
const setFullSelected = ( selected: boolean ) => {
isFullSelected.value = selected;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,6 @@ const { addressSummary, inlineSummaryLanguageItem } = useAddressSummary( store )
const mailingList = useMailingListModel( store );
const { receiptNeeded, showReceiptOptionError } = useReceiptModel( store );
const countryWasRestored = ref<boolean>( false );
defineExpose( { focus: (): void => pageRef.value.focus() } );
const scrollToPaymentSection = () => {
const scrollIntoViewElement = document.getElementById( 'donation-page-form-section-payment' );
if ( scrollIntoViewElement ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ export function usePersonalDataSectionEventHandlers(
return;
}

if ( !addressDataIsValid.value || !bankDataIsValid.value || !paymentDataIsValid.value ) {
return;
}

// Track the form submission with the Matomo Form Analytics plugin
// The form is a different one than the one for the submitValuesForm
trackFormSubmissionForAddressType( addressType.value );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ describe( 'DonationForm.vue', () => {
validateBankDataUrl: '',
validateLegacyBankDataUrl: '',
salutations: [],
addressValidationPatterns: {} as AddressValidation,
addressValidationPatterns: { postcode: '' } as AddressValidation,
usesContentCards: true,
},
global: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,13 @@ describe( 'PersonalDataSection.vue', () => {

it( 'scrolls to payment section when button for changing payment data is clicked', async () => {
const scrollElement = { scrollIntoView: jest.fn() };
Object.defineProperty( document, 'getElementById', { writable: true, configurable: true, value: () => scrollElement } );

const { wrapper } = getWrapper();

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

// TODO test that payment section got scrolled to
expect( scrollElement.scrollIntoView ).toHaveBeenCalledTimes( 1 );
expect( scrollElement.scrollIntoView ).toHaveBeenCalledWith( { behavior: 'smooth' } );
} );

it( 'shows and hides the error summary', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,13 @@ describe( 'PersonalDataSectionDonationReceipt.vue', () => {

it( 'scrolls to payment section when button for changing payment data is clicked', async () => {
const scrollElement = { scrollIntoView: jest.fn() };
Object.defineProperty( document, 'getElementById', { writable: true, configurable: true, value: () => scrollElement } );

const { wrapper } = getWrapper();

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

// TODO test that payment section got scrolled to
expect( scrollElement.scrollIntoView ).toHaveBeenCalled();
expect( scrollElement.scrollIntoView ).toHaveBeenCalledWith( { behavior: 'smooth' } );
} );

it( 'shows and hides the error summary', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { Salutation } from '@src/view_models/Salutation';
import PersonalDataSectionDonationReceipt from '@src/components/pages/donation_form/singlePageFormSections/PersonalDataSectionDonationReceipt.vue';
import BankFields from '@src/components/shared/BankFields.vue';
import { FakeBankValidationResource } from '@test/unit/TestDoubles/FakeBankValidationResource';
import { PaymentType } from '@src/view_models/PaymentType';

const testCountry = {
countryCode: 'de',
Expand Down Expand Up @@ -111,13 +112,13 @@ describe( 'PersonalDataSectionDonationReceipt.vue (With Street Autocomplete)', (

it( 'scrolls to payment section when button for changing payment data is clicked', async () => {
const scrollElement = { scrollIntoView: jest.fn() };
Object.defineProperty( document, 'getElementById', { writable: true, configurable: true, value: () => scrollElement } );

const { wrapper } = getWrapper();

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

// TODO test that payment section got scrolled to
expect( scrollElement.scrollIntoView ).toHaveBeenCalled();
expect( scrollElement.scrollIntoView ).toHaveBeenCalledWith( { behavior: 'smooth' } );
} );

it( 'shows and hides the error summary', async () => {
Expand Down Expand Up @@ -333,9 +334,18 @@ describe( 'PersonalDataSectionDonationReceipt.vue (With Street Autocomplete)', (

it( 'submits the form', async () => {
const store = createStore();
await setPaymentType( store, 'UEB' );
await store.dispatch( action( 'payment', 'initializePayment' ), {
allowedIntervals: [ 0, 12 ],
allowedPaymentTypes: [ PaymentType.PAYPAL ],
initialValues: {
amount: '2399',
type: PaymentType.PAYPAL,
paymentIntervalInMonths: '12',
isCustomAmount: false,
},
} );
await store.dispatch( action( 'address', 'initializeAddress' ), {
addressType: AddressTypeModel.PERSON,
addressType: AddressTypeModel.ANON,
newsletter: true,
receipt: true,
fields: [
Expand All @@ -355,10 +365,10 @@ describe( 'PersonalDataSectionDonationReceipt.vue (With Street Autocomplete)', (
mockedAxios.post.mockResolvedValue( { data: { status: 'OK' } } );
const { wrapper } = getWrapper( store );

const submitForm = wrapper.find<HTMLFormElement>( '#donation-form-submit-values' );
const submitForm = wrapper.find<HTMLFormElement>( '#submit-form' );
submitForm.element.submit = jest.fn();

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

expect( submitForm.element.submit ).toHaveBeenCalled();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,15 @@ describe( 'PersonalDataSection.vue (With Street Autocomplete)', () => {
expect( store.dispatch ).toBeCalledWith( expectedAction, expectedPayload );
} );

it( 'emits previous event', async () => {
it( 'scrolls to top when the donor clicks the previous button', async () => {
const scrollElement = { scrollIntoView: jest.fn() };
Object.defineProperty( document, 'getElementById', { writable: true, configurable: true, value: () => scrollElement } );

const { wrapper } = getWrapper();

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

expect( wrapper.emitted( 'previous-page' ).length ).toStrictEqual( 1 );
expect( scrollElement.scrollIntoView ).toHaveBeenCalledWith( { behavior: 'smooth' } );
} );

it( 'shows and hides the error summary', async () => {
Expand Down

0 comments on commit 14f4aac

Please sign in to comment.