Revert "Display shipping calculator when formatted address is present"
This reverts commit 5731a4cc75
.
This commit is contained in:
parent
5731a4cc75
commit
d6b802d5c1
|
@ -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 (
|
||||
<>
|
||||
|
|
|
@ -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(
|
||||
<SlotFillProvider>
|
||||
<TotalsShipping
|
||||
currency={ {
|
||||
code: 'USD',
|
||||
symbol: '$',
|
||||
position: 'left',
|
||||
precision: 2,
|
||||
} }
|
||||
values={ {
|
||||
total_shipping: '0',
|
||||
total_shipping_tax: '0',
|
||||
} }
|
||||
showCalculator={ true }
|
||||
showRateSelector={ true }
|
||||
isCheckout={ false }
|
||||
className={ '' }
|
||||
/>
|
||||
</SlotFillProvider>
|
||||
);
|
||||
expect( screen.queryByText( 'Change address' ) ).toBeInTheDocument();
|
||||
expect(
|
||||
screen.queryByText( 'Add an address for shipping options' )
|
||||
).not.toBeInTheDocument();
|
||||
} );
|
||||
} );
|
||||
|
|
Loading…
Reference in New Issue