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
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,54 @@ describe('StripeShippingAddress Component', () => {
expect(defaultProps.onAddressSelect).toHaveBeenCalled();
});

it('renders StripeShippingAddress with initialize props and when page is reloaded', async () => {
defaultProps.initialize = jest.fn((options) => {
const { getStyles = noop, onChangeShipping = noop} = options.stripeupe || {};

onChangeShipping({
complete: true,
elementType: 'shipping',
empty: false,
isNewAddress: true,
value: {
address: {
city: 'string',
country: 'US',
line1: 'string',
line2: 'string',
postal_code: 'string',
state: 'string',
},
name: 'cosme fulanito',
},
}
);
getStyles();

return Promise.resolve(checkoutService.getState());
});

const stripeProps = {...defaultProps, isStripeLinkEnabled: true, customerEmail: ''};
const component = mount(
<Formik
initialValues={ {} }
onSubmit={ noop }
>
<StripeShippingAddress { ...stripeProps } />
</Formik>
);

expect(component.find(StripeShippingAddressDisplay).props()).toEqual(
expect.objectContaining({
methodId: 'stripeupe',
deinitialize: defaultProps.deinitialize,
})
);

expect(defaultProps.initialize).toHaveBeenCalled();
expect(defaultProps.onAddressSelect).toHaveBeenCalled();
});

it('renders StripeShippingAddress with initialize props without last name', async () => {
defaultProps.initialize = jest.fn((options) => {
const { getStyles = noop, onChangeShipping = noop} = options.stripeupe || {};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ const StripeShippingAddress: FunctionComponent<StripeShippingAddressProps> = (pr
isStripeLoading,
isStripeAutoStep,
isShippingMethodLoading,
shippingAddress,
} = props;

const [isNewAddress, setIsNewAddress] = useState(true);
Expand Down Expand Up @@ -103,7 +104,7 @@ const StripeShippingAddress: FunctionComponent<StripeShippingAddressProps> = (pr
, name = '' } } = shipping;

if(complete) {
if (step.isComplete) {
if (step.isComplete || (shippingAddress?.firstName && shipping.isNewAddress)) {
handleLoading();
}

Expand Down