2024-07-12 12:58:34 +02:00
|
|
|
import { render, screen } from '@testing-library/react';
|
2024-06-22 16:11:00 +02:00
|
|
|
import userEvent from '@testing-library/user-event';
|
2024-06-22 15:53:46 +02:00
|
|
|
import '@testing-library/jest-dom';
|
2024-07-12 12:58:34 +02:00
|
|
|
import { CheckoutHandler } from '../Components/checkout-handler';
|
2024-06-22 15:37:01 +02:00
|
|
|
|
2024-07-12 12:58:34 +02:00
|
|
|
test( 'checkbox label displays the given text', async () => {
|
|
|
|
render(
|
|
|
|
<CheckoutHandler
|
|
|
|
getCardFieldsForm={ () => {} }
|
|
|
|
saveCardText="Foo"
|
|
|
|
is_vaulting_enabled={ true }
|
|
|
|
/>
|
|
|
|
);
|
2024-06-22 15:53:46 +02:00
|
|
|
|
2024-07-12 12:58:34 +02:00
|
|
|
await expect( screen.getByLabelText( 'Foo' ) ).toBeInTheDocument();
|
|
|
|
} );
|
2024-06-22 16:11:00 +02:00
|
|
|
|
2024-07-12 12:58:34 +02:00
|
|
|
test( 'click checkbox calls function passing checked value', async () => {
|
|
|
|
const getSavePayment = jest.fn();
|
2024-06-22 16:11:00 +02:00
|
|
|
|
2024-07-12 12:58:34 +02:00
|
|
|
render(
|
|
|
|
<CheckoutHandler
|
|
|
|
getSavePayment={ getSavePayment }
|
|
|
|
getCardFieldsForm={ () => {} }
|
|
|
|
saveCardText="Foo"
|
|
|
|
is_vaulting_enabled={ true }
|
|
|
|
/>
|
|
|
|
);
|
2024-06-22 16:11:00 +02:00
|
|
|
|
2024-07-12 12:58:34 +02:00
|
|
|
await userEvent.click( screen.getByLabelText( 'Foo' ) );
|
2024-06-22 16:11:00 +02:00
|
|
|
|
2024-07-12 12:58:34 +02:00
|
|
|
await expect( getSavePayment.mock.calls ).toHaveLength( 1 );
|
|
|
|
await expect( getSavePayment.mock.calls[ 0 ][ 0 ] ).toBe( true );
|
|
|
|
} );
|