Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
burhandodhy committed Jan 27, 2025
1 parent 3dbf6c6 commit 8a710d7
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
25 changes: 25 additions & 0 deletions tests/cypress/integration/features/instant-results.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -468,5 +468,30 @@ describe('Instant Results Feature', { tags: '@slow' }, () => {
*/
cy.get('.ep-search-sort :selected').should('contain.text', 'Date, newest to oldest');
});

it('Is possible to filter the taxonomy terms', () => {
/**
* Activate test plugin.
*/
cy.maybeEnableFeature('instant-results');
cy.activatePlugin('filter-instant-results-facet-terms', 'wpCli');

/**
* Perform a search.
*/
cy.intercept('*search=block*').as('apiRequest');
cy.visit('/');
cy.get('.wp-block-search').last().as('searchBlock');
cy.get('@searchBlock').find('input[type="search"]').type('block');
cy.get('@searchBlock').find('button').click();
cy.wait('@apiRequest');

/**
* The number of terms displayed in the facet should be one.
*/
cy.get('[id^="ep-search-tax-category-"]').should('have.length', 1);

cy.deactivatePlugin('filter-instant-results-facet-terms', 'wpCli');
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php
/**
* Plugin Name: Filter Instant Results Taxonomy Terms
* Description: Filters the Instant Results taxonomy terms for test purposes.
* Version: 1.0.0
* Author: 10up Inc.
* License: GPLv2 or later
*
* @package ElasticPress_Tests_E2e
*/

/**
* Limit the Instant Results facet terms to only the "Classic" term.
*/
add_action(
'wp_footer',
function (): void {
?>
<script>
document.addEventListener('DOMContentLoaded', function() {
const filterCategoryTerms = (terms, taxonomyName) => {

if (taxonomyName !== 'tax-category') {
return terms;
}

// keep only Term Classic
const filteredTerms = terms.filter(term => term.label === 'Classic');
return filteredTerms;
}

wp.hooks.addFilter('ep.InstantResults.facet.taxonomy.terms', 'ep-test', filterCategoryTerms);
});
</script>
<?php
}
);

0 comments on commit 8a710d7

Please sign in to comment.