Product Collection: Fix max price filter query value inclusion (#49917)

This commit is contained in:
Bart Kalisz 2024-07-29 11:51:26 +02:00 committed by GitHub
parent df4bd38297
commit d731edc868
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 82 additions and 8 deletions

View File

@ -422,6 +422,76 @@ test.describe( 'Product Collection', () => {
await expect( pageObject.products ).toHaveCount( 4 );
} );
// See https://github.com/woocommerce/woocommerce/pull/49917
test( 'Price range is inclusive in both editor and frontend.', async ( {
page,
pageObject,
editor,
} ) => {
await pageObject.createNewPostAndInsertBlock();
await expect( pageObject.products ).toHaveCount( 9 );
await pageObject.addFilter( 'Price Range' );
await pageObject.setPriceRange( {
min: '45',
max: '55',
} );
// Wait for the products to be filtered.
await expect( pageObject.products ).not.toHaveCount( 9 );
await expect(
pageObject.products.filter( { hasText: '$45.00' } )
).not.toHaveCount( 0 );
await expect(
pageObject.products.filter( { hasText: '$55.00' } )
).not.toHaveCount( 0 );
// Reset the price range.
await pageObject.setPriceRange( {
min: '0',
max: '0',
} );
await expect( pageObject.products ).toHaveCount( 9 );
await editor.insertBlock( {
name: 'woocommerce/filter-wrapper',
attributes: { filterType: 'price-filter' },
} );
await pageObject.publishAndGoToFrontend();
await expect( pageObject.products ).toHaveCount( 9 );
await page
.getByRole( 'textbox', {
name: 'Filter products by minimum',
} )
.dblclick();
await page.keyboard.type( '45' );
await page
.getByRole( 'textbox', {
name: 'Filter products by maximum',
} )
.dblclick();
await page.keyboard.type( '55' );
await page.keyboard.press( 'Tab' );
// Wait for the products to be filtered.
await expect( pageObject.products ).not.toHaveCount( 9 );
await expect(
pageObject.products.filter( { hasText: '$45.00' } )
).not.toHaveCount( 0 );
await expect(
pageObject.products.filter( { hasText: '$55.00' } )
).not.toHaveCount( 0 );
} );
test.describe( '"Use page context" control', () => {
test( 'should be visible on posts', async ( { pageObject } ) => {
await pageObject.createNewPostAndInsertBlock();

View File

@ -0,0 +1,4 @@
Significance: minor
Type: fix
Product Collection: Fix max price query to include prices less or equal to the given max value.

View File

@ -1092,7 +1092,7 @@ class ProductCollection extends AbstractBlock {
$max_price_query = empty( $max_price ) ? array() : array(
'key' => '_price',
'value' => $max_price,
'compare' => '<',
'compare' => '<=',
'type' => 'numeric',
);

View File

@ -619,7 +619,7 @@ class ProductQuery extends AbstractBlock {
$max_price_query = empty( $max_price ) ? array() : [
'key' => '_price',
'value' => $max_price,
'compare' => '<',
'compare' => '<=',
'type' => 'numeric',
];

View File

@ -345,7 +345,7 @@ class ProductCollection extends \WP_UnitTestCase {
array(
'key' => '_price',
'value' => 100,
'compare' => '<',
'compare' => '<=',
'type' => 'numeric',
),
array(),
@ -394,7 +394,7 @@ class ProductCollection extends \WP_UnitTestCase {
array(
'key' => '_price',
'value' => 100,
'compare' => '<',
'compare' => '<=',
'type' => 'numeric',
),
array(
@ -573,7 +573,7 @@ class ProductCollection extends \WP_UnitTestCase {
array(
'key' => '_price',
'value' => 100,
'compare' => '<',
'compare' => '<=',
'type' => 'numeric',
),
array(

View File

@ -339,7 +339,7 @@ class ProductQuery extends \WP_UnitTestCase {
array(
'key' => '_price',
'value' => 100,
'compare' => '<',
'compare' => '<=',
'type' => 'numeric',
),
array(),
@ -388,7 +388,7 @@ class ProductQuery extends \WP_UnitTestCase {
array(
'key' => '_price',
'value' => 100,
'compare' => '<',
'compare' => '<=',
'type' => 'numeric',
),
array(
@ -512,7 +512,7 @@ class ProductQuery extends \WP_UnitTestCase {
array(
'key' => '_price',
'value' => 100,
'compare' => '<',
'compare' => '<=',
'type' => 'numeric',
),
array(