Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Copy shipping phone to billing phone if sync is checked #10603

Merged
merged 2 commits into from
Oct 20, 2023
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 @@ -34,6 +34,7 @@
setShippingAddress,
setBillingAddress,
setShippingPhone,
setBillingPhone,
useShippingAsBilling,
} = useCheckoutAddress();
const { dispatchCheckoutEvent } = useStoreEvents();
Expand Down Expand Up @@ -129,21 +130,27 @@
dispatchCheckoutEvent( 'set-phone-number', {
step: 'shipping',
} );
if ( useShippingAsBilling ) {
setBillingPhone( value );
dispatchCheckoutEvent( 'set-phone-number', {
step: 'billing',
} );
}
} }
/>
) }
</>
),
[
addressFieldKeys,
addressFieldsConfig,
dispatchCheckoutEvent,
onChangeAddress,
requirePhoneField,
setShippingPhone,
shippingAddress,
showPhoneField,
]

Check warning on line 153 in assets/js/blocks/checkout/inner-blocks/checkout-shipping-address-block/customer-address.tsx

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

assets/js/blocks/checkout/inner-blocks/checkout-shipping-address-block/customer-address.tsx#L144-L153

[react-hooks/exhaustive-deps] React Hook useCallback has missing dependencies: 'setBillingPhone' and 'useShippingAsBilling'. Either include them or remove the dependency array.
);

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,23 @@ test.describe( 'Shopper → Checkout block → Shipping', () => {
FLAT_RATE_SHIPPING_PRICE
)
).toBe( true );
await page.getByLabel( 'Use same address for billing' ).uncheck();

await pageObject.syncBillingWithShipping();
await pageObject.fillInCheckoutWithTestData( {
phone: '0987654322',
} );
await pageObject.unsyncBillingWithShipping();
const shippingForm = page.getByRole( 'group', {
name: 'Shipping address',
} );
const billingForm = page.getByRole( 'group', {
name: 'Billing address',
} );

await expect( shippingForm.getByLabel( 'Phone' ).inputValue ).toEqual(
billingForm.getByLabel( 'Phone' ).inputValue
);

await pageObject.fillInCheckoutWithTestData();
const overrideBillingDetails = {
firstname: 'Juan',
Expand Down
8 changes: 8 additions & 0 deletions tests/e2e/tests/checkout/checkout.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,14 @@ export class CheckoutPage {
}
}

async syncBillingWithShipping() {
await this.page.getByLabel( 'Use same address for billing' ).check();
}

async unsyncBillingWithShipping() {
await this.page.getByLabel( 'Use same address for billing' ).uncheck();
}

getOrderId() {
// Get the current URL
const url = this.page.url();
Expand Down
Loading