Remove payments API routing initialization
[ProtonMail-WebClient.git] / packages / components / containers / payments / EditCardModal.test.tsx
blob450c3d49bd7dfc747cfe0f32f4ced075918715ff
1 // import { fireEvent, waitFor } from '@testing-library/react';
3 // import { Autopay, CardModel } from '@proton/payments';
4 // import { updatePaymentMethod } from '@proton/shared/lib/api/payments';
5 // import {
6 //     apiMock,
7 //     applyHOCs,
8 //     withApi,
9 //     withCache,
10 //     withDeprecatedModals,
11 //     withEventManager,
12 //     withNotifications,
13 // } from '@proton/testing';
15 // import { renderWithProviders } from '../contacts/tests/render';
16 // import EditCardModal from './EditCardModal';
18 // jest.mock('@proton/components/components/portal/Portal');
19 // jest.mock('@proton/components/components/toggle/Toggle');
21 // const defaultCard: CardModel = {
22 //     number: '',
23 //     month: '',
24 //     year: '',
25 //     cvc: '',
26 //     zip: '',
27 //     country: 'US',
28 // };
30 // beforeEach(() => {
31 //     jest.clearAllMocks();
32 // });
34 // const ContextEditCardModal = applyHOCs(
35 //     withNotifications(),
36 //     withEventManager(),
37 //     withApi(),
38 //     withCache(),
39 //     withDeprecatedModals()
40 // )(EditCardModal);
42 // it('should render', () => {
43 //     const { container } = renderWithProviders(<ContextEditCardModal open={true} />);
45 //     expect(container).not.toBeEmptyDOMElement();
46 // });
48 // it('should update Autopay and close modal if user edits the existing payment method', async () => {
49 //     const paymentMethodId = 'paymentMethodId123';
50 //     const onClose = jest.fn();
51 //     const { getByTestId } = renderWithProviders(
52 //         <ContextEditCardModal
53 //             card={defaultCard}
54 //             renewState={Autopay.DISABLE}
55 //             paymentMethodId={paymentMethodId}
56 //             open={true}
57 //             onClose={onClose}
58 //         />
59 //     );
61 //     fireEvent.click(getByTestId('toggle-subscription-renew'));
63 //     await waitFor(() => {
64 //         expect(apiMock).toHaveBeenCalledWith(updatePaymentMethod(paymentMethodId, { Autopay: Autopay.ENABLE }));
65 //     });
66 //     await waitFor(() => {
67 //         expect(onClose).toHaveBeenCalled();
68 //     });
69 // });
71 // it('should update Autopay and close modal if user edits the existing payment method (toggle off)', async () => {
72 //     const paymentMethodId = 'paymentMethodId123';
73 //     const onClose = jest.fn();
74 //     const { getByTestId } = renderWithProviders(
75 //         <ContextEditCardModal
76 //             card={defaultCard}
77 //             renewState={Autopay.ENABLE}
78 //             paymentMethodId={paymentMethodId}
79 //             open={true}
80 //             onClose={onClose}
81 //         />
82 //     );
84 //     fireEvent.click(getByTestId('toggle-subscription-renew'));
85 //     fireEvent.click(getByTestId('action-disable-autopay'));
87 //     await waitFor(() => {
88 //         expect(apiMock).toHaveBeenCalledWith(updatePaymentMethod(paymentMethodId, { Autopay: Autopay.DISABLE }));
89 //     });
90 //     await waitFor(() => {
91 //         expect(onClose).toHaveBeenCalled();
92 //     });
93 // });
95 // it('should not update autopay if this is Add Credit card mode', async () => {
96 //     const onClose = jest.fn();
97 //     const { getByTestId } = renderWithProviders(<ContextEditCardModal open={true} onClose={onClose} />);
99 //     fireEvent.click(getByTestId('toggle-subscription-renew'));
100 //     fireEvent.click(getByTestId('action-disable-autopay'));
102 //     await waitFor(() => {});
104 //     expect(apiMock).not.toHaveBeenCalled();
105 //     expect(onClose).not.toHaveBeenCalled();
106 // });
108 // it('should toggle back if API returned error', async () => {
109 //     apiMock.mockRejectedValue(new Error());
111 //     const paymentMethodId = 'paymentMethodId123';
112 //     const onClose = jest.fn();
113 //     const { getByTestId } = renderWithProviders(
114 //         <ContextEditCardModal
115 //             card={defaultCard}
116 //             renewState={Autopay.DISABLE}
117 //             paymentMethodId={paymentMethodId}
118 //             open={true}
119 //             onClose={onClose}
120 //         />
121 //     );
123 //     fireEvent.click(getByTestId('toggle-subscription-renew'));
125 //     await waitFor(() => {
126 //         expect(apiMock).toHaveBeenCalledWith(updatePaymentMethod(paymentMethodId, { Autopay: Autopay.ENABLE }));
127 //     });
128 //     await waitFor(() => {
129 //         expect(onClose).not.toHaveBeenCalled();
130 //     });
131 //     await waitFor(() => {
132 //         expect(getByTestId('toggle-subscription-renew')).not.toHaveTextContent('CHECKED');
133 //     });
134 // });
136 // it('should disable Save button while updating the toggle status', async () => {
137 //     let resolve!: () => void;
138 //     const manualPromise = new Promise<void>((innerResolve) => (resolve = innerResolve));
139 //     apiMock.mockReturnValue(manualPromise);
141 //     const paymentMethodId = 'paymentMethodId123';
142 //     const onClose = jest.fn();
143 //     const { getByTestId } = renderWithProviders(
144 //         <ContextEditCardModal
145 //             card={defaultCard}
146 //             renewState={Autopay.DISABLE}
147 //             paymentMethodId={paymentMethodId}
148 //             open={true}
149 //             onClose={onClose}
150 //         />
151 //     );
153 //     fireEvent.click(getByTestId('toggle-subscription-renew'));
154 //     await waitFor(() => {
155 //         expect(getByTestId('edit-card-action-save')).toHaveAttribute('disabled');
156 //     });
158 //     resolve();
159 //     await waitFor(() => {
160 //         expect(getByTestId('edit-card-action-save')).not.toHaveAttribute('disabled');
161 //     });
162 // });
164 it('placeholder', () => expect(true).toBeTruthy());