Fix product price not displaying properly when product is on sale (https://github.com/woocommerce/woocommerce-blocks/pull/3853)

* Use else if in ProductPrice

This is because the priceComponent variable should be set depending on some conditions, but multiple of them could be true, so by using else if we only handle the first true case

* Update snapshots for jest
This commit is contained in:
Thomas Roberts 2021-02-16 11:42:11 +00:00 committed by Thomas Roberts
parent f4f95eb26e
commit 4fe4060fec
2 changed files with 36 additions and 11 deletions

View File

@ -126,7 +126,6 @@ const ProductPrice = ( {
}
const isDiscounted = regularPrice && price !== regularPrice;
let priceComponent = (
<span
className={ classNames(
@ -148,9 +147,7 @@ const ProductPrice = ( {
regularPriceStyle={ regularPriceStyle }
/>
);
}
if ( minPrice !== null && maxPrice !== null ) {
} else if ( minPrice !== null && maxPrice !== null ) {
priceComponent = (
<PriceRange
currency={ currency }
@ -160,9 +157,7 @@ const ProductPrice = ( {
priceStyle={ priceStyle }
/>
);
}
if ( price !== null ) {
} else if ( price !== null ) {
priceComponent = (
<FormattedMonetaryAmount
className={ classNames(

View File

@ -6,10 +6,25 @@ exports[`ProductPrice should apply the format if one is provided 1`] = `
>
pre price
<span
className="wc-block-formatted-money-amount wc-block-components-formatted-money-amount wc-block-components-product-price__value"
className="screen-reader-text"
>
Previous price:
</span>
<del
className="wc-block-components-product-price__regular"
>
£1.00
</del>
<span
className="screen-reader-text"
>
Discounted price:
</span>
<ins
className="wc-block-components-product-price__value is-discounted"
>
£0.50
</span>
</ins>
Test format
</span>
`;
@ -19,9 +34,24 @@ exports[`ProductPrice should use default price if no format is provided 1`] = `
className="price wc-block-components-product-price"
>
<span
className="wc-block-formatted-money-amount wc-block-components-formatted-money-amount wc-block-components-product-price__value"
className="screen-reader-text"
>
Previous price:
</span>
<del
className="wc-block-components-product-price__regular"
>
£1.00
</del>
<span
className="screen-reader-text"
>
Discounted price:
</span>
<ins
className="wc-block-components-product-price__value is-discounted"
>
£0.50
</span>
</ins>
</span>
`;