From d6b802d5c1e1063a2949f9c5d006ff750efb0ee0 Mon Sep 17 00:00:00 2001 From: Tarun Vijwani Date: Wed, 25 Oct 2023 11:52:49 +0400 Subject: [PATCH] Revert "Display shipping calculator when formatted address is present" This reverts commit 5731a4cc75f8d51751a60b908daef26550a47b42. --- .../totals/shipping/shipping-address.tsx | 13 +++--- .../totals/shipping/test/index.tsx | 44 ------------------- 2 files changed, 7 insertions(+), 50 deletions(-) diff --git a/plugins/woocommerce-blocks/assets/js/base/components/cart-checkout/totals/shipping/shipping-address.tsx b/plugins/woocommerce-blocks/assets/js/base/components/cart-checkout/totals/shipping/shipping-address.tsx index 0e75d89a6ca..79b58efeaf3 100644 --- a/plugins/woocommerce-blocks/assets/js/base/components/cart-checkout/totals/shipping/shipping-address.tsx +++ b/plugins/woocommerce-blocks/assets/js/base/components/cart-checkout/totals/shipping/shipping-address.tsx @@ -2,7 +2,10 @@ * External dependencies */ import { __ } from '@wordpress/i18n'; -import { formatShippingAddress } from '@woocommerce/base-utils'; +import { + formatShippingAddress, + isAddressComplete, +} from '@woocommerce/base-utils'; import { useEditorContext } from '@woocommerce/base-context'; import { ShippingAddress as ShippingAddressType } from '@woocommerce/settings'; import PickupLocation from '@woocommerce/base-components/cart-checkout/pickup-location'; @@ -28,17 +31,15 @@ export const ShippingAddress = ( { setIsShippingCalculatorOpen, shippingAddress, }: ShippingAddressProps ): JSX.Element | null => { + const addressComplete = isAddressComplete( shippingAddress ); const { isEditor } = useEditorContext(); const prefersCollection = useSelect( ( select ) => select( CHECKOUT_STORE_KEY ).prefersCollection() ); - const hasFormattedAddress = !! formatShippingAddress( shippingAddress ); - - // If we don't have formatted address, and we're not in the editor, don't show anything. - if ( ! hasFormattedAddress && ! isEditor ) { + // If the address is incomplete, and we're not in the editor, don't show anything. + if ( ! addressComplete && ! isEditor ) { return null; } - const formattedLocation = formatShippingAddress( shippingAddress ); return ( <> diff --git a/plugins/woocommerce-blocks/assets/js/base/components/cart-checkout/totals/shipping/test/index.tsx b/plugins/woocommerce-blocks/assets/js/base/components/cart-checkout/totals/shipping/test/index.tsx index b27da256064..5181a9c69ca 100644 --- a/plugins/woocommerce-blocks/assets/js/base/components/cart-checkout/totals/shipping/test/index.tsx +++ b/plugins/woocommerce-blocks/assets/js/base/components/cart-checkout/totals/shipping/test/index.tsx @@ -295,48 +295,4 @@ describe( 'TotalsShipping', () => { screen.queryByText( 'Add an address for shipping options' ) ).not.toBeInTheDocument(); } ); - it( 'does show the calculator button when default rates are available and has formatted address', () => { - baseContextHooks.useStoreCart.mockReturnValue( { - cartItems: mockPreviewCart.items, - cartTotals: [ mockPreviewCart.totals ], - cartCoupons: mockPreviewCart.coupons, - cartFees: mockPreviewCart.fees, - cartNeedsShipping: mockPreviewCart.needs_shipping, - shippingRates: mockPreviewCart.shipping_rates, - shippingAddress: { - ...shippingAddress, - city: '', - state: 'California', - country: 'US', - postcode: '', - }, - billingAddress: mockPreviewCart.billing_address, - cartHasCalculatedShipping: mockPreviewCart.has_calculated_shipping, - isLoadingRates: false, - } ); - render( - - - - ); - expect( screen.queryByText( 'Change address' ) ).toBeInTheDocument(); - expect( - screen.queryByText( 'Add an address for shipping options' ) - ).not.toBeInTheDocument(); - } ); } );