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:
parent
f4f95eb26e
commit
4fe4060fec
|
@ -126,7 +126,6 @@ const ProductPrice = ( {
|
||||||
}
|
}
|
||||||
|
|
||||||
const isDiscounted = regularPrice && price !== regularPrice;
|
const isDiscounted = regularPrice && price !== regularPrice;
|
||||||
|
|
||||||
let priceComponent = (
|
let priceComponent = (
|
||||||
<span
|
<span
|
||||||
className={ classNames(
|
className={ classNames(
|
||||||
|
@ -148,9 +147,7 @@ const ProductPrice = ( {
|
||||||
regularPriceStyle={ regularPriceStyle }
|
regularPriceStyle={ regularPriceStyle }
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
} else if ( minPrice !== null && maxPrice !== null ) {
|
||||||
|
|
||||||
if ( minPrice !== null && maxPrice !== null ) {
|
|
||||||
priceComponent = (
|
priceComponent = (
|
||||||
<PriceRange
|
<PriceRange
|
||||||
currency={ currency }
|
currency={ currency }
|
||||||
|
@ -160,9 +157,7 @@ const ProductPrice = ( {
|
||||||
priceStyle={ priceStyle }
|
priceStyle={ priceStyle }
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
} else if ( price !== null ) {
|
||||||
|
|
||||||
if ( price !== null ) {
|
|
||||||
priceComponent = (
|
priceComponent = (
|
||||||
<FormattedMonetaryAmount
|
<FormattedMonetaryAmount
|
||||||
className={ classNames(
|
className={ classNames(
|
||||||
|
|
|
@ -6,10 +6,25 @@ exports[`ProductPrice should apply the format if one is provided 1`] = `
|
||||||
>
|
>
|
||||||
pre price
|
pre price
|
||||||
<span
|
<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
|
£0.50
|
||||||
</span>
|
</ins>
|
||||||
Test format
|
Test format
|
||||||
</span>
|
</span>
|
||||||
`;
|
`;
|
||||||
|
@ -19,9 +34,24 @@ exports[`ProductPrice should use default price if no format is provided 1`] = `
|
||||||
className="price wc-block-components-product-price"
|
className="price wc-block-components-product-price"
|
||||||
>
|
>
|
||||||
<span
|
<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
|
£0.50
|
||||||
</span>
|
</ins>
|
||||||
</span>
|
</span>
|
||||||
`;
|
`;
|
||||||
|
|
Loading…
Reference in New Issue