Skip to content

Commit 47cbb5a

Browse files
committed
feat(core): CHECKOUT-9513 Pass in initial state to avoid request waterfall
1 parent cb3e2ca commit 47cbb5a

File tree

22 files changed

+480
-398
lines changed

22 files changed

+480
-398
lines changed

packages/core/src/app/billing/Billing.test.tsx

Lines changed: 53 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,14 @@ import {
2323
import {
2424
CheckoutPageNodeObject,
2525
CheckoutPreset,
26+
checkoutSettings,
2627
checkoutWithBillingEmail,
2728
checkoutWithDigitalCart,
2829
checkoutWithShipping,
2930
checkoutWithShippingAndBilling,
3031
consignment,
3132
customer,
33+
formFields,
3234
payments,
3335
shippingAddress,
3436
shippingAddress2,
@@ -37,7 +39,8 @@ import {
3739
import { act, renderWithoutWrapper as render, screen } from '@bigcommerce/checkout/test-utils';
3840
import { ThemeProvider } from '@bigcommerce/checkout/ui';
3941

40-
import Checkout, { type CheckoutProps } from '../checkout/Checkout';
42+
import Checkout from '../checkout/Checkout';
43+
import { type CheckoutIntermediateProps } from '../checkout/CheckoutIntermediate';
4144
import { getCheckoutPayment } from '../checkout/checkouts.mock';
4245
import { createErrorLogger } from '../common/error';
4346
import {
@@ -47,9 +50,9 @@ import {
4750

4851
describe('Billing step', () => {
4952
let checkout: CheckoutPageNodeObject;
50-
let CheckoutTest: FunctionComponent<CheckoutProps>;
53+
let CheckoutTest: FunctionComponent<CheckoutIntermediateProps>;
5154
let checkoutService: CheckoutService;
52-
let defaultProps: CheckoutProps & AnalyticsContextProps;
55+
let defaultProps: CheckoutIntermediateProps & AnalyticsContextProps;
5356
let embeddedMessengerMock: EmbeddedCheckoutMessenger;
5457
let analyticsTracker: Partial<AnalyticsEvents>;
5558

@@ -128,7 +131,9 @@ describe('Billing step', () => {
128131
});
129132

130133
it('completes the billing step as a guest and goes to the payment step', async () => {
131-
checkout.use(CheckoutPreset.CheckoutWithShipping);
134+
checkoutService = checkout.use(CheckoutPreset.CheckoutWithShipping);
135+
136+
jest.spyOn(checkoutService, 'updateBillingAddress');
132137

133138
render(<CheckoutTest {...defaultProps} />);
134139

@@ -153,7 +158,9 @@ describe('Billing step', () => {
153158
});
154159

155160
it('edit the billing address and goes back to the payment step', async () => {
156-
checkout.use(CheckoutPreset.CheckoutWithShippingAndBilling);
161+
checkoutService = checkout.use(CheckoutPreset.CheckoutWithShippingAndBilling);
162+
163+
jest.spyOn(checkoutService, 'updateBillingAddress');
157164

158165
render(<CheckoutTest {...defaultProps} />);
159166

@@ -186,14 +193,15 @@ describe('Billing step', () => {
186193
});
187194

188195
it('should show order comments', async () => {
189-
checkout.updateCheckout(
190-
'get',
191-
'/checkout/*',
192-
{
196+
defaultProps.initialState = {
197+
config: checkoutSettings,
198+
checkout: {
193199
...checkoutWithBillingEmail,
194200
cart: checkoutWithDigitalCart.cart,
195201
},
196-
);
202+
formFields,
203+
extensions: [],
204+
};
197205

198206
render(<CheckoutTest {...defaultProps} />);
199207

@@ -203,17 +211,18 @@ describe('Billing step', () => {
203211
});
204212

205213
it('should show PoweredByPayPalFastlaneLabel', async () => {
206-
checkout.updateCheckout(
207-
'get',
208-
'/checkout/*',
209-
{
214+
defaultProps.initialState = {
215+
config: checkoutSettings,
216+
checkout: {
210217
...checkoutWithShipping,
211218
billingAddress:checkoutWithBillingEmail.billingAddress,
212219
payments:[
213220
getCheckoutPayment(),
214221
],
215222
},
216-
);
223+
formFields,
224+
extensions: [],
225+
};
217226

218227
render(<CheckoutTest {...defaultProps} />);
219228

@@ -223,11 +232,9 @@ describe('Billing step', () => {
223232
});
224233

225234
it('should show PoweredByPayPalFastlaneLabel and custom form fields', async () => {
226-
checkout.use(CheckoutPreset.CheckoutWithBillingEmailAndCustomFormFields);
227-
checkout.updateCheckout(
228-
'get',
229-
'/checkout/*',
230-
{
235+
checkoutService = checkout.use(CheckoutPreset.CheckoutWithBillingEmailAndCustomFormFields, {
236+
config: checkoutSettings,
237+
checkout: {
231238
...checkoutWithShipping,
232239
billingAddress:checkoutWithBillingEmail.billingAddress,
233240
consignments: [
@@ -273,7 +280,8 @@ describe('Billing step', () => {
273280
getCheckoutPayment(),
274281
],
275282
},
276-
);
283+
formFields,
284+
});
277285

278286
render(<CheckoutTest {...defaultProps} />);
279287

@@ -292,11 +300,14 @@ describe('Billing step', () => {
292300

293301
describe('registered customer', () => {
294302
it('completes the billing step after selecting a valid address', async () => {
295-
checkout.updateCheckout(
296-
'get',
297-
'/checkout/*',
298-
checkoutWithCustomer
299-
);
303+
defaultProps.initialState = {
304+
config: checkoutSettings,
305+
checkout: checkoutWithCustomer,
306+
formFields,
307+
extensions: [],
308+
};
309+
310+
jest.spyOn(checkoutService, 'updateBillingAddress');
300311

301312
render(<CheckoutTest {...defaultProps} />);
302313

@@ -354,11 +365,14 @@ describe('Billing step', () => {
354365
phone: shippingAddress3.phone,
355366
} as BillingAddress;
356367

357-
checkout.updateCheckout(
358-
'get',
359-
'/checkout/*',
360-
checkoutWithCustomer
361-
);
368+
defaultProps.initialState ={
369+
config: checkoutSettings,
370+
checkout: checkoutWithCustomer,
371+
formFields,
372+
extensions: [],
373+
};
374+
375+
jest.spyOn(checkoutService, 'updateBillingAddress');
362376

363377
render(<CheckoutTest {...defaultProps} />);
364378

@@ -405,11 +419,14 @@ describe('Billing step', () => {
405419
});
406420

407421
it('completes the billing step after creating a new address even with existing addresses', async () => {
408-
checkout.updateCheckout(
409-
'get',
410-
'/checkout/*',
411-
checkoutWithCustomer
412-
);
422+
defaultProps.initialState = {
423+
config: checkoutSettings,
424+
checkout: checkoutWithCustomer,
425+
formFields,
426+
extensions: [],
427+
};
428+
429+
jest.spyOn(checkoutService, 'updateBillingAddress');
413430

414431
render(<CheckoutTest {...defaultProps} />);
415432

0 commit comments

Comments
 (0)