Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix missing currency for price range facet. #3293

Merged
merged 4 commits into from
Feb 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions assets/css/instant-results/result.css
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@

& img {
display: block;
height: auto;
margin: 0;
width: 100%;
}
Expand Down
16 changes: 12 additions & 4 deletions assets/js/instant-results/components/facets/price-range-facet.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { __, sprintf } from '@wordpress/i18n';
* Internal dependencies.
*/
import { useApiSearch } from '../../../api-search';
import { currencyCode } from '../../config';
import { formatPrice } from '../../utilities';
import Panel from '../common/panel';
import RangeSlider from '../common/range-slider';
Expand Down Expand Up @@ -49,8 +50,15 @@ export default ({ defaultIsOpen, label }) => {
/**
* Current minimum and maximum prices, formatted.
*/
const currentMaxPrice = formatPrice(currentMaxValue, { maximumFractionDigits: 0 });
const currentMinPrice = formatPrice(currentMinValue, { maximumFractionDigits: 0 });
const currentMaxPrice = formatPrice(currentMaxValue, {
maximumFractionDigits: 0,
currency: currencyCode,
});

const currentMinPrice = formatPrice(currentMinValue, {
maximumFractionDigits: 0,
currency: currencyCode,
});

/**
* Applied minimum and maximum values.
Expand All @@ -61,8 +69,8 @@ export default ({ defaultIsOpen, label }) => {
/**
* Applied minimum and maximum prices, formatted.
*/
const maxPrice = formatPrice(maxValue, { maximumFractionDigits: 0 });
const minPrice = formatPrice(minValue, { maximumFractionDigits: 0 });
const maxPrice = formatPrice(maxValue, { maximumFractionDigits: 0, currency: currencyCode });
const minPrice = formatPrice(minValue, { maximumFractionDigits: 0, currency: currencyCode });

/**
* Handle completed slider change.
Expand Down
46 changes: 46 additions & 0 deletions tests/cypress/integration/features/instant-results.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ describe('Instant Results Feature', { tags: '@slow' }, () => {
}

before(() => {
cy.deactivatePlugin('woocommerce', 'wpCli');
cy.deactivatePlugin('classic-widgets', 'wpCli');
createSearchWidget();

Expand Down Expand Up @@ -62,6 +63,8 @@ describe('Instant Results Feature', { tags: '@slow' }, () => {

describe('Instant Results Available', () => {
before(() => {
cy.activatePlugin('woocommerce');

if (!isEpIo) {
cy.activatePlugin('elasticpress-proxy');
}
Expand Down Expand Up @@ -152,6 +155,49 @@ describe('Instant Results Feature', { tags: '@slow' }, () => {
cy.get('#querylist').should('be.visible');
});

it('Can filter results by price', () => {
/**
* Add price range facet.
*/
cy.maybeEnableFeature('instant-results');
cy.visitAdminPage('admin.php?page=elasticpress');
cy.intercept('/wp-admin/admin-ajax.php*').as('ajaxRequest');
cy.get('.ep-feature-instant-results .settings-button').click();
cy.get('.ep-feature-instant-results .components-form-token-field__input').type(
'{backspace}{backspace}price{downArrow}{enter}{esc}',
);
cy.get('.ep-feature-instant-results .button-primary').click();
cy.wait('@ajaxRequest');

/**
* Perform a search.
*/
cy.visit('/');
cy.intercept('*search=ergonomic*').as('apiRequest');
cy.get('.wp-block-search').last().as('searchBlock');
cy.get('@searchBlock').find('input[type="search"]').type('ergonomic');
cy.get('@searchBlock').find('button').click();
cy.get('.ep-search-modal').should('be.visible');
cy.wait('@apiRequest');
cy.get('.ep-search-result').should('have.length', 3);

/**
* Adjusting the price range facet should filter results by price.
*/
cy.get('.ep-search-range-slider__thumb-0').as('priceThumb');
cy.get('@priceThumb').type('{rightArrow}');
cy.wait('@apiRequest');
cy.url().should('include', 'min_price=420');
cy.get('.ep-search-result').should('have.length', 2);

/**
* Clearing the filter should return the unfiltered results.
*/
cy.get('.ep-search-tokens button').contains('420').click();
cy.wait('@apiRequest');
cy.get('.ep-search-result').should('have.length', 3);
});

it('Is possible to manually open Instant Results with a plugin', () => {
Cypress.on(
'uncaught:exception',
Expand Down