Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 1 addition & 14 deletions packages/core/src/app/shipping/stripeUPE/StripeShipping.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { useCheckout } from '@bigcommerce/checkout/payment-integration-api';
import { AddressFormSkeleton } from '@bigcommerce/checkout/ui';

import type CheckoutStepStatus from '../../checkout/CheckoutStepStatus';
import { EMPTY_ARRAY } from '../../common/utility';
import ShippingHeader from '../ShippingHeader';

import StripeShippingForm, { type SingleShippingFormValues } from './StripeShippingForm';
Expand Down Expand Up @@ -48,25 +47,17 @@ const StripeShipping = ({
isShippingMethodLoading,
...shippingFormProps
}: StripeShippingProps): ReactNode => {
const { checkoutService, checkoutState } = useCheckout();
const { checkoutState } = useCheckout();

const {
data: {
getCheckout,
getCustomer,
getConsignments,
getShippingAddressFields,
getShippingCountries,
},
} = checkoutState;
const checkout = getCheckout();
const consignments = getConsignments() || [];
const customer = getCustomer();

const initialize = checkoutService.initializeShipping;
const deinitialize = checkoutService.deinitializeShipping;

const countries = getShippingCountries() || EMPTY_ARRAY;
const getFields = getShippingAddressFields;

const [isStripeLoading, setIsStripeLoading] = useState(true);
Expand Down Expand Up @@ -101,13 +92,9 @@ const StripeShipping = ({
shouldShowMultiShipping={shouldShowMultiShipping}
/>
<StripeShippingForm
consignments={consignments}
countries={countries}
customerMessage={customerMessage}
getFields={getFields}
{...shippingFormProps}
deinitialize={deinitialize}
initialize={initialize}
isBillingSameAsShipping={isBillingSameAsShipping}
isLoading={isLoading}
isMultiShippingMode={isMultiShippingMode}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { createCheckoutService, type StripeShippingEvent } from '@bigcommerce/checkout-sdk';
import {
type CheckoutSelectors,
createCheckoutService,
type StripeShippingEvent,
} from '@bigcommerce/checkout-sdk';
import userEvent from '@testing-library/user-event';
import React, { act } from 'react';

Expand All @@ -14,6 +18,8 @@ import { getStoreConfig } from '../../config/config.mock';
import { getShippingAddress } from '../shipping-addresses.mock';

import StripeShippingForm from './StripeShippingForm';
import { getCustomer } from '../../customer/customers.mock';
import { getCheckout } from '../../checkout/checkouts.mock';

let hasSelectedShippingOptionsReturn = false;

Expand All @@ -28,6 +34,10 @@ describe('StripeShippingForm', () => {
const errorLogger = new ConsoleErrorLogger();
const { customFields, ...rest } = getShippingAddress();
const localeContext = createLocaleContext(getStoreConfig());
let checkoutState: CheckoutSelectors;

const initialize = jest.fn();
checkoutService.initializeShipping = initialize;

const defaultProps = {
isShippingMethodLoading: false,
Expand All @@ -42,7 +52,6 @@ describe('StripeShippingForm', () => {
isBillingSameAsShipping: false,
isInitialValueLoaded: false,
isMultiShippingMode: false,
countries: [],
countriesWithAutocomplete: [],
shippingAddress: rest,
customerMessage: '',
Expand All @@ -55,9 +64,7 @@ describe('StripeShippingForm', () => {
onSubmit: jest.fn(),
getFields: jest.fn(() => addressFormFields),
onUnhandledError: jest.fn(),
deinitialize: jest.fn(),
signOut: jest.fn(),
initialize: jest.fn(),
updateAddress: jest.fn(),
deleteConsignments: jest.fn(),
};
Expand All @@ -72,14 +79,20 @@ describe('StripeShippingForm', () => {
</CheckoutProvider>
);

beforeEach(() => {
checkoutState = checkoutService.getState();
jest.spyOn(checkoutState.data, 'getCustomer').mockReturnValue(getCustomer());
jest.spyOn(checkoutState.data, 'getCheckout').mockReturnValue(getCheckout());
})

afterEach(() => {
jest.clearAllMocks();
})

it('renders form with a correct parameters', async () => {
const { container } = renderContainer({ isLoading: false });

expect(defaultProps.initialize).toHaveBeenCalled();
expect(initialize).toHaveBeenCalled();
expect(defaultProps.getFields).toHaveBeenCalledTimes(2);
expect(defaultProps.getFields).toHaveBeenCalledWith("US");
// eslint-disable-next-line testing-library/no-node-access,testing-library/no-container
Expand Down Expand Up @@ -159,7 +172,7 @@ describe('StripeShippingForm', () => {
renderContainer({ isLoading: false });

await act(async () => {
const { stripeupe } = defaultProps.initialize.mock.calls[0][0];
const { stripeupe } = initialize.mock.calls[0][0];

await stripeupe.onChangeShipping(shippingChangeEvent);
});
Expand Down Expand Up @@ -210,7 +223,7 @@ describe('StripeShippingForm', () => {
renderContainer({ isLoading: false });

await act(async () => {
const { stripeupe } = defaultProps.initialize.mock.calls[0][0];
const { stripeupe } = initialize.mock.calls[0][0];

await stripeupe.onChangeShipping(shippingChangeEvent);
});
Expand Down
Loading