Skip to content
Open
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 @@ -304,12 +304,16 @@ export const AcceleratedCheckoutButtons: React.FC<
return (
<RCTAcceleratedCheckoutButtons
testID="accelerated-checkout-buttons"
applePayLabel={applePayLabel}
applePayStyle={applePayStyle}
style={{...defaultStyles, height: dynamicHeight}}
{...(applePayLabel === undefined ? {} : {applePayLabel})}
{...(applePayStyle === undefined ? {} : {applePayStyle})}
style={
dynamicHeight === undefined
? defaultStyles
: {...defaultStyles, height: dynamicHeight}
}
checkoutIdentifier={checkoutIdentifier}
cornerRadius={cornerRadius}
wallets={wallets}
{...(cornerRadius === undefined ? {} : {cornerRadius})}
{...(wallets === undefined ? {} : {wallets})}
onFail={handleFail}
onComplete={handleComplete}
onCancel={handleCancel}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {Platform} from 'react-native';
import {
AcceleratedCheckoutButtons,
AcceleratedCheckoutWallet,
ApplePayLabel,
ApplePayStyle,
RenderState,
} from '../src';
Expand Down Expand Up @@ -98,6 +99,7 @@ describe('AcceleratedCheckoutButtons', () => {
cartId={'gid://shopify/Cart/123'}
cornerRadius={12}
wallets={[AcceleratedCheckoutWallet.shopPay]}
applePayLabel={ApplePayLabel.buy}
applePayStyle={ApplePayStyle.black}
/>,
);
Expand All @@ -111,6 +113,7 @@ describe('AcceleratedCheckoutButtons', () => {
expect(nativeComponent.props.wallets).toEqual([
AcceleratedCheckoutWallet.shopPay,
]);
expect(nativeComponent.props.applePayLabel).toBe(ApplePayLabel.buy);
expect(nativeComponent.props.applePayStyle).toBe(ApplePayStyle.black);
});

Expand Down Expand Up @@ -143,6 +146,28 @@ describe('AcceleratedCheckoutButtons', () => {
expect(nativeComponent.props.cornerRadius).toBeUndefined();
});

it('omits optional props when they are not provided', () => {
const {getByTestId} = render(
<AcceleratedCheckoutButtons cartId="gid://shopify/Cart/123" />,
);

const nativeComponent = getByTestId('accelerated-checkout-buttons');
expect(nativeComponent).toBeTruthy();
expect(nativeComponent.props).not.toHaveProperty('applePayLabel');
expect(nativeComponent.props).not.toHaveProperty('applePayStyle');
expect(nativeComponent.props).not.toHaveProperty('cornerRadius');
expect(nativeComponent.props).not.toHaveProperty('wallets');
});

it('omits height from style until a size is reported', () => {
const {getByTestId} = render(
<AcceleratedCheckoutButtons cartId="gid://shopify/Cart/123" />,
);

const nativeComponent = getByTestId('accelerated-checkout-buttons');
expect(nativeComponent.props.style).toEqual({flex: 1});
});

it('passes through custom quantity and cornerRadius', () => {
const {getByTestId} = render(
<AcceleratedCheckoutButtons
Expand Down
Loading