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

Commit

Permalink
Copy shipping phone to billing phone if sync is checked (#10603)
Browse files Browse the repository at this point in the history
  • Loading branch information
senadir authored Oct 20, 2023
1 parent e162612 commit 577279e
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const CustomerAddress = ( {
setShippingAddress,
setBillingAddress,
setShippingPhone,
setBillingPhone,
useShippingAsBilling,
} = useCheckoutAddress();
const { dispatchCheckoutEvent } = useStoreEvents();
Expand Down Expand Up @@ -129,6 +130,12 @@ const CustomerAddress = ( {
dispatchCheckoutEvent( 'set-phone-number', {
step: 'shipping',
} );
if ( useShippingAsBilling ) {
setBillingPhone( value );
dispatchCheckoutEvent( 'set-phone-number', {
step: 'billing',
} );
}
} }
/>
) }
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

0 comments on commit 577279e

Please sign in to comment.