Skip to content

Commit

Permalink
Add test.
Browse files Browse the repository at this point in the history
  • Loading branch information
demiankatz committed Dec 4, 2023
1 parent 7b7b43d commit 09d77ba
Showing 1 changed file with 79 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@

namespace VuFindTest\Mink;

use Behat\Mink\Element\Element;

use function count;

/**
Expand Down Expand Up @@ -98,9 +100,9 @@ class SearchFacetsTest extends \VuFindTest\Integration\MinkTestCase
/**
* Get filtered search
*
* @return \Behat\Mink\Element\Element
* @return Element
*/
protected function getFilteredSearch()
protected function getFilteredSearch(): Element
{
$session = $this->getMinkSession();
$session->visit($this->getVuFindUrl() . '/Search/Results?filter%5B%5D=building%3A"weird_ids.mrc"');
Expand All @@ -110,11 +112,11 @@ protected function getFilteredSearch()
/**
* Helper function for simple facet application test
*
* @param \Behat\Mink\Element\Element $page Mink page object
* @param Element $page Mink page object
*
* @return void
*/
protected function facetApplyProcedure($page)
protected function facetApplyProcedure(Element $page): void
{
// Confirm that we have 9 results and no filters to begin with:
$time = $this->findCss($page, '.search-query-time');
Expand Down Expand Up @@ -146,13 +148,13 @@ protected function facetApplyProcedure($page)
/**
* Helper function for facets lists
*
* @param \Behat\Mink\Element\Element $page Mink page object
* @param int $limit Configured lightbox length
* @param bool $exclusionActive Is facet exclusion on?
* @param Element $page Mink page object
* @param int $limit Configured lightbox length
* @param bool $exclusionActive Is facet exclusion on?
*
* @return void
*/
protected function facetListProcedure($page, $limit, $exclusionActive = false)
protected function facetListProcedure(Element $page, int $limit, bool $exclusionActive = false): void
{
$this->waitForPageLoad($page);
$items = $page->findAll('css', '#modal #facet-list-count .js-facet-item');
Expand Down Expand Up @@ -220,7 +222,7 @@ protected function facetListProcedure($page, $limit, $exclusionActive = false)
*
* @return void
*/
public function testApplyFacet()
public function testApplyFacet(): void
{
$page = $this->performSearch('building:weird_ids.mrc');

Expand All @@ -237,7 +239,7 @@ public function testApplyFacet()
*
* @return void
*/
public function testApplyFacetDeferred()
public function testApplyFacetDeferred(): void
{
$this->changeConfigs(
[
Expand All @@ -263,7 +265,7 @@ public function testApplyFacetDeferred()
*
* @return void
*/
public function testFacetLightbox()
public function testFacetLightbox(): void
{
$limit = 4;
$this->changeConfigs(
Expand Down Expand Up @@ -292,7 +294,7 @@ public function testFacetLightbox()
*
* @return void
*/
public function testFacetLightboxMoreSetting()
public function testFacetLightboxMoreSetting(): void
{
$limit = 4;
$this->changeConfigs(
Expand Down Expand Up @@ -322,7 +324,7 @@ public function testFacetLightboxMoreSetting()
*
* @return void
*/
public function testFacetLightboxExclusion()
public function testFacetLightboxExclusion(): void
{
$limit = 4;
$this->changeConfigs(
Expand All @@ -343,14 +345,61 @@ public function testFacetLightboxExclusion()
$this->assertCount(1, $page->findAll('css', $this->activeFilterSelector));
}

/**
* Test that filtering out facet values does not break lightbox pagination.
*
* @return void
*/
public function testFilteredLightboxPagination(): void
{
$limit = 4;
$this->changeConfigs(
[
'facets' => [
'HideFacetValue' => [
'genre_facet' => [
'Fiction',
],
],
'Results_Settings' => [
'showMoreInLightbox[*]' => true,
'lightboxLimit' => $limit,
],
],
]
);
$page = $this->performSearch('building:weird_ids.mrc');
// Open the genre facet
$this->clickCss($page, '#side-collapse-genre_facet .more-facets');
$this->waitForPageLoad($page);
$items = $page->findAll('css', '#modal #facet-list-count .js-facet-item');
$this->assertCount($limit - 1, $items); // (-1 is for the filtered value)
// more
$this->clickCss($page, '#modal .js-facet-next-page');
$this->waitForPageLoad($page);
$items = $page->findAll('css', '#modal #facet-list-count .js-facet-item');
$this->assertEquals($limit * 2 - 1, count($items));
$this->assertEquals(
'Weird IDs 9 results 9 '
. 'The Study Of P|pes 1 results 1 '
. 'The Study and Scor_ng of Dots.and-Dashes:Colons 1 results 1 '
. 'The Study of "Important" Things 1 results 1 '
. 'The Study of %\'s? 1 results 1 '
. 'The Study of +\'s? 1 results 1 '
. 'The Study of @Twitter #test 1 results 1 '
. 'more…',
$this->findCss($page, '#modal #facet-list-count')->getText()
);
}

/**
* Support method to click a hierarchical facet.
*
* @param \Behat\Mink\Element\Element $page Mink page object
* @param Element $page Mink page object
*
* @return void
*/
protected function clickHierarchyFacet($page)
protected function clickHierarchyFacet(Element $page): void
{
// Open second level:
$this->clickCss($page, $this->facetExpandSelector);
Expand All @@ -372,7 +421,7 @@ protected function clickHierarchyFacet($page)
*
* @return void
*/
public function testHierarchicalFacets()
public function testHierarchicalFacets(): void
{
$this->changeConfigs(
[
Expand All @@ -395,7 +444,7 @@ public function testHierarchicalFacets()
*
* @return void
*/
public function testHierarchicalFacetExclude()
public function testHierarchicalFacetExclude(): void
{
$this->changeConfigs(
[
Expand Down Expand Up @@ -440,7 +489,7 @@ public function testHierarchicalFacetExclude()
*
* @return void
*/
public function testCollapseStatePersistence()
public function testCollapseStatePersistence(): void
{
$this->changeConfigs(
[
Expand Down Expand Up @@ -476,11 +525,11 @@ public function testCollapseStatePersistence()
/**
* Assert that the filter used by these tests is still applied.
*
* @param \Behat\Mink\Element\Element $page Mink page object
* @param Element $page Mink page object
*
* @return void
*/
protected function assertFilterIsStillThere($page)
protected function assertFilterIsStillThere(Element $page): void
{
$filter = $this->findCss($page, $this->activeFilterSelector);
$this->assertEquals('Remove Filter weird_ids.mrc', $filter->getText());
Expand All @@ -489,11 +538,11 @@ protected function assertFilterIsStillThere($page)
/**
* Assert that no filters are applied.
*
* @param \Behat\Mink\Element\Element $page Mink page object
* @param Element $page Mink page object
*
* @return void
*/
protected function assertNoFilters($page)
protected function assertNoFilters(Element $page): void
{
$items = $page->findAll('css', $this->activeFilterSelector);
$this->assertCount(0, $items);
Expand All @@ -502,11 +551,11 @@ protected function assertNoFilters($page)
/**
* Assert that the "reset filters" button is not present.
*
* @param \Behat\Mink\Element\Element $page Mink page object
* @param Element $page Mink page object
*
* @return void
*/
protected function assertNoResetFiltersButton($page)
protected function assertNoResetFiltersButton(Element $page): void
{
$reset = $page->findAll('css', '.reset-filters-btn');
$this->assertCount(0, $reset);
Expand All @@ -517,7 +566,7 @@ protected function assertNoResetFiltersButton($page)
*
* @return void
*/
public function testDefaultRetainFiltersBehavior()
public function testDefaultRetainFiltersBehavior(): void
{
$page = $this->getFilteredSearch();
$this->assertFilterIsStillThere($page);
Expand All @@ -536,7 +585,7 @@ public function testDefaultRetainFiltersBehavior()
*
* @return void
*/
public function testRetainFiltersOnHomePageBehavior()
public function testRetainFiltersOnHomePageBehavior(): void
{
$page = $this->getFilteredSearch();
// Back to home spage:
Expand All @@ -555,7 +604,7 @@ public function testRetainFiltersOnHomePageBehavior()
*
* @return void
*/
public function testFiltersOnRecord()
public function testFiltersOnRecord(): void
{
$page = $this->getFilteredSearch();
$this->assertFilterIsStillThere($page);
Expand All @@ -574,7 +623,7 @@ public function testFiltersOnRecord()
*
* @return void
*/
public function testNeverRetainFiltersBehavior()
public function testNeverRetainFiltersBehavior(): void
{
$this->changeConfigs(
[
Expand All @@ -597,7 +646,7 @@ public function testNeverRetainFiltersBehavior()
*
* @return void
*/
public function testDefaultFiltersWithResetButton()
public function testDefaultFiltersWithResetButton(): void
{
// Unlike the other tests, which use $this->getFilteredSearch() to set up
// the weird_ids.mrc filter through a URL parameter, this test sets up the
Expand Down Expand Up @@ -636,7 +685,7 @@ public function testDefaultFiltersWithResetButton()
*
* @return void
*/
public function testOrFacets()
public function testOrFacets(): void
{
$this->changeConfigs(
[
Expand Down

0 comments on commit 09d77ba

Please sign in to comment.