1 import { render } from '@testing-library/react';
2 import { renderHook } from '@testing-library/react-hooks';
4 import { usePaypal } from '@proton/components/payments/react-extensions/usePaypal';
5 import { PAYMENT_METHOD_TYPES } from '@proton/payments';
6 import { type Currency } from '@proton/payments';
7 import { apiMock, mockVerifyPayment } from '@proton/testing';
9 import PayPalView from './PayPalView';
11 const onChargeable = jest.fn();
12 const onClick = jest.fn();
18 let amountAndCurrency = {
20 Currency: 'EUR' as Currency,
27 mockVerificationResult,
30 mockVerificationResult?: boolean;
34 const verifyPayment = mockVerifyPayment();
35 if (mockVerificationResult) {
36 verifyPayment.mockVerification();
40 ({ amountAndCurrency }) =>
49 verifyPayment: mockVerifyPayment(),
63 it('should render', () => {
64 const { result: paypal } = paypalHook({ isCredit: false, ...amountAndCurrency });
65 const { result: paypalCredit } = paypalHook({ isCredit: true, ...amountAndCurrency });
67 const { container } = render(
70 paypal={paypal.current}
71 paypalCredit={paypalCredit.current}
73 amount={amountAndCurrency.Amount}
74 currency={amountAndCurrency.Currency}
75 showPaypalCredit={true}
76 method={PAYMENT_METHOD_TYPES.PAYPAL_CREDIT}
79 expect(container).not.toBeEmptyDOMElement();
82 it('should render the message of paypal credit and "click here" button', () => {
83 const { result: paypal } = paypalHook({ isCredit: false, ...amountAndCurrency });
84 const { result: paypalCredit } = paypalHook({ isCredit: true, ...amountAndCurrency });
86 const { getByText, getByTestId } = render(
89 paypal={paypal.current}
90 paypalCredit={paypalCredit.current}
92 amount={amountAndCurrency.Amount}
93 currency={amountAndCurrency.Currency}
94 showPaypalCredit={true}
95 method={PAYMENT_METHOD_TYPES.PAYPAL_CREDIT}
99 const message = `You must have a credit card or bank account linked with your PayPal account. If your PayPal account doesn't have that, please click on the button below.`;
100 expect(getByText(message)).toBeInTheDocument();
101 expect(getByTestId('paypal-credit-button')).toBeInTheDocument();
104 it('should disable the "click here" button when triggers are disabled', () => {
105 const { result: paypal } = paypalHook({ isCredit: false, ...amountAndCurrency });
106 const { result: paypalCredit } = paypalHook({ isCredit: true, ...amountAndCurrency });
108 const { getByTestId } = render(
111 paypal={paypal.current}
112 paypalCredit={paypalCredit.current}
114 amount={amountAndCurrency.Amount}
115 currency={amountAndCurrency.Currency}
116 triggersDisabled={true}
117 showPaypalCredit={true}
118 method={PAYMENT_METHOD_TYPES.PAYPAL_CREDIT}
122 expect(getByTestId('paypal-credit-button')).toBeDisabled();
125 it('should disable the "click here" button when paypal credit is in initial state', () => {
126 const { result: paypal } = paypalHook({ isCredit: false, ...amountAndCurrency });
127 const { result: paypalCredit } = paypalHook({ isCredit: true, ...amountAndCurrency });
129 const { getByTestId } = render(
132 paypal={paypal.current}
133 paypalCredit={paypalCredit.current}
135 amount={amountAndCurrency.Amount}
136 currency={amountAndCurrency.Currency}
137 showPaypalCredit={true}
138 method={PAYMENT_METHOD_TYPES.PAYPAL_CREDIT}
142 expect(getByTestId('paypal-credit-button')).toBeDisabled();