1
- import { createCheckoutService , type StripeShippingEvent } from '@bigcommerce/checkout-sdk' ;
1
+ import {
2
+ type CheckoutSelectors ,
3
+ createCheckoutService ,
4
+ type StripeShippingEvent ,
5
+ } from '@bigcommerce/checkout-sdk' ;
2
6
import userEvent from '@testing-library/user-event' ;
3
7
import React , { act } from 'react' ;
4
8
@@ -14,6 +18,8 @@ import { getStoreConfig } from '../../config/config.mock';
14
18
import { getShippingAddress } from '../shipping-addresses.mock' ;
15
19
16
20
import StripeShippingForm from './StripeShippingForm' ;
21
+ import { getCustomer } from '../../customer/customers.mock' ;
22
+ import { getCheckout } from '../../checkout/checkouts.mock' ;
17
23
18
24
let hasSelectedShippingOptionsReturn = false ;
19
25
@@ -28,6 +34,10 @@ describe('StripeShippingForm', () => {
28
34
const errorLogger = new ConsoleErrorLogger ( ) ;
29
35
const { customFields, ...rest } = getShippingAddress ( ) ;
30
36
const localeContext = createLocaleContext ( getStoreConfig ( ) ) ;
37
+ let checkoutState : CheckoutSelectors ;
38
+
39
+ const initialize = jest . fn ( ) ;
40
+ checkoutService . initializeShipping = initialize ;
31
41
32
42
const defaultProps = {
33
43
isShippingMethodLoading : false ,
@@ -42,7 +52,6 @@ describe('StripeShippingForm', () => {
42
52
isBillingSameAsShipping : false ,
43
53
isInitialValueLoaded : false ,
44
54
isMultiShippingMode : false ,
45
- countries : [ ] ,
46
55
countriesWithAutocomplete : [ ] ,
47
56
shippingAddress : rest ,
48
57
customerMessage : '' ,
@@ -55,9 +64,7 @@ describe('StripeShippingForm', () => {
55
64
onSubmit : jest . fn ( ) ,
56
65
getFields : jest . fn ( ( ) => addressFormFields ) ,
57
66
onUnhandledError : jest . fn ( ) ,
58
- deinitialize : jest . fn ( ) ,
59
67
signOut : jest . fn ( ) ,
60
- initialize : jest . fn ( ) ,
61
68
updateAddress : jest . fn ( ) ,
62
69
deleteConsignments : jest . fn ( ) ,
63
70
} ;
@@ -72,14 +79,20 @@ describe('StripeShippingForm', () => {
72
79
</ CheckoutProvider >
73
80
) ;
74
81
82
+ beforeEach ( ( ) => {
83
+ checkoutState = checkoutService . getState ( ) ;
84
+ jest . spyOn ( checkoutState . data , 'getCustomer' ) . mockReturnValue ( getCustomer ( ) ) ;
85
+ jest . spyOn ( checkoutState . data , 'getCheckout' ) . mockReturnValue ( getCheckout ( ) ) ;
86
+ } )
87
+
75
88
afterEach ( ( ) => {
76
89
jest . clearAllMocks ( ) ;
77
90
} )
78
91
79
92
it ( 'renders form with a correct parameters' , async ( ) => {
80
93
const { container } = renderContainer ( { isLoading : false } ) ;
81
94
82
- expect ( defaultProps . initialize ) . toHaveBeenCalled ( ) ;
95
+ expect ( initialize ) . toHaveBeenCalled ( ) ;
83
96
expect ( defaultProps . getFields ) . toHaveBeenCalledTimes ( 2 ) ;
84
97
expect ( defaultProps . getFields ) . toHaveBeenCalledWith ( "US" ) ;
85
98
// eslint-disable-next-line testing-library/no-node-access,testing-library/no-container
@@ -159,7 +172,7 @@ describe('StripeShippingForm', () => {
159
172
renderContainer ( { isLoading : false } ) ;
160
173
161
174
await act ( async ( ) => {
162
- const { stripeupe } = defaultProps . initialize . mock . calls [ 0 ] [ 0 ] ;
175
+ const { stripeupe } = initialize . mock . calls [ 0 ] [ 0 ] ;
163
176
164
177
await stripeupe . onChangeShipping ( shippingChangeEvent ) ;
165
178
} ) ;
@@ -210,7 +223,7 @@ describe('StripeShippingForm', () => {
210
223
renderContainer ( { isLoading : false } ) ;
211
224
212
225
await act ( async ( ) => {
213
- const { stripeupe } = defaultProps . initialize . mock . calls [ 0 ] [ 0 ] ;
226
+ const { stripeupe } = initialize . mock . calls [ 0 ] [ 0 ] ;
214
227
215
228
await stripeupe . onChangeShipping ( shippingChangeEvent ) ;
216
229
} ) ;
0 commit comments