|
1 | 1 | import { render, screen, waitFor } from '@testing-library/preact';
|
2 | 2 | import KlarnaPayments from './KlarnaPayments';
|
3 | 3 | import Dropin from '../Dropin';
|
| 4 | +import { PaymentAction } from '../../types/global-types'; |
4 | 5 |
|
5 | 6 | describe('KlarnaPayments', () => {
|
6 |
| - const coreProps = { name: 'Klarna', i18n: global.i18n, loadingContext: 'test', modules: { resources: global.resources } }; |
| 7 | + const coreProps = { |
| 8 | + name: 'Klarna', |
| 9 | + i18n: global.i18n, |
| 10 | + loadingContext: 'test', |
| 11 | + modules: { resources: global.resources, analytics: global.analytics } |
| 12 | + }; |
7 | 13 | const renderKlarna = props => {
|
8 | 14 | const KlarnaPaymentsEle = new KlarnaPayments(global.core, {
|
9 | 15 | ...coreProps,
|
@@ -53,4 +59,64 @@ describe('KlarnaPayments', () => {
|
53 | 59 |
|
54 | 60 | expect(onAdditionalDetailsMock).toHaveBeenCalled();
|
55 | 61 | });
|
| 62 | + |
| 63 | + describe('when handling action', () => { |
| 64 | + test('should use updateWithAction when action type is "sdk"', async () => { |
| 65 | + const widgetAction: PaymentAction = { |
| 66 | + paymentData: 'Ab02b4c0!...', |
| 67 | + paymentMethodType: 'klarna_paynow', |
| 68 | + type: 'sdk', |
| 69 | + sdkData: { |
| 70 | + client_token: 'eyJhbGciOiJ...', |
| 71 | + payment_method_category: 'pay_over_time' |
| 72 | + } |
| 73 | + }; |
| 74 | + |
| 75 | + const klarna = new KlarnaPayments(global.core, { |
| 76 | + ...coreProps, |
| 77 | + type: 'klarna_paynow', |
| 78 | + onSubmit(state, component, actions) { |
| 79 | + actions.resolve({ |
| 80 | + resultCode: 'Pending', |
| 81 | + action: widgetAction |
| 82 | + }); |
| 83 | + } |
| 84 | + }); |
| 85 | + const spy = jest.spyOn(klarna, 'updateWithAction'); |
| 86 | + |
| 87 | + render(klarna.render()); |
| 88 | + klarna.submit(); |
| 89 | + |
| 90 | + await waitFor(() => expect(spy).toHaveBeenCalledWith(widgetAction), { interval: 100 }); |
| 91 | + }); |
| 92 | + |
| 93 | + test('should NOT use updateWithAction when action type is NOT "sdk"', done => { |
| 94 | + const action: PaymentAction = { |
| 95 | + paymentMethodType: 'klarna_paynow', |
| 96 | + type: 'redirect', |
| 97 | + url: 'https://checkoutshopper-test.adyen.com/checkoutshopper/checkoutPaymentRedirect?redirectData=X3XtfGC9%21H4s...', |
| 98 | + method: 'GET' |
| 99 | + }; |
| 100 | + |
| 101 | + const klarna = new KlarnaPayments(global.core, { |
| 102 | + ...coreProps, |
| 103 | + type: 'klarna_paynow', |
| 104 | + onSubmit(state, component, actions) { |
| 105 | + actions.resolve({ |
| 106 | + resultCode: 'Pending', |
| 107 | + action |
| 108 | + }); |
| 109 | + } |
| 110 | + }); |
| 111 | + const spy = jest.spyOn(klarna, 'updateWithAction'); |
| 112 | + |
| 113 | + render(klarna.render()); |
| 114 | + klarna.submit(); |
| 115 | + |
| 116 | + setTimeout(() => { |
| 117 | + expect(spy).not.toHaveBeenCalled(); |
| 118 | + done(); |
| 119 | + }, 500); |
| 120 | + }); |
| 121 | + }); |
56 | 122 | });
|
0 commit comments