Skip to content

Commit

Permalink
Create test to capture checkbox duplication bug.
Browse files Browse the repository at this point in the history
  • Loading branch information
demiankatz committed Jan 23, 2025
1 parent 866ff32 commit 4b7ac81
Showing 1 changed file with 31 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1381,32 +1381,37 @@ protected function assertNoResetFiltersButton(Element $page): void
public static function multiSelectOnAdvancedSearchProvider(): array
{
return [
'with language switch' => [true],
'without language switch' => [false],
'with language switch / with checkbox' => [true, true],
'without language switch / with checkbox' => [false, true],
'with language switch / without checkbox' => [true, false],
'without language switch / without checkbox' => [false, false],
];
}

/**
* Test applying multi-facet selection to advanced search results, with or without changing the
* language setting first.
* language setting first and/or including a pre-existing checkbox filter.
*
* @param bool $changeLanguage Should we change the language before applying the facets?
* @param bool $changeLanguage Should we change the language before applying the facets?
* @param bool $includeCheckbox Should we apply a checkbox prior to multi-selection?
*
* @dataProvider multiSelectOnAdvancedSearchProvider
*
* @return void
*/
public function testMultiSelectOnAdvancedSearch(bool $changeLanguage): void
public function testMultiSelectOnAdvancedSearch(bool $changeLanguage, bool $includeCheckbox): void
{
$this->changeConfigs(
[
'facets' => [
'Results_Settings' => [
'multiFacetsSelection' => true,
],
],
]
);
$facets = [
'Results_Settings' => [
'multiFacetsSelection' => true,
],
];
if ($includeCheckbox) {
// Create a pointless checkbox filter that will not impact the result set size
// (we're just testing that it applies to the URL correctly):
$facets['CheckboxFacets']['title:*'] = 'Has Title';
}
$this->changeConfigs(compact('facets'));
$path = '/Search/Advanced';
$session = $this->getMinkSession();
$session->visit($this->getVuFindUrl() . $path);
Expand All @@ -1416,11 +1421,17 @@ public function testMultiSelectOnAdvancedSearch(bool $changeLanguage): void
$this->findCssAndSetValue($page, '#search_lookfor0_1', 'history');
$this->findCss($page, '[type=submit]')->press();

if ($includeCheckbox) {
$link = $this->findAndAssertLink($page, 'Has Title');
$link->click();
$this->waitForPageLoad($page);
}

if ($changeLanguage) {
$this->flipflopLanguage($page);
}

// Activate the first two facet values:
// Activate the first two facet values (and the checkbox filter, if requested):
$this->clickCss($page, '.js-user-selection-multi-filters');
$this->clickCss($page, '.facet__list__item a');
$this->clickCss($page, '.facet__list__item a', index: 1);
Expand All @@ -1433,7 +1444,12 @@ public function testMultiSelectOnAdvancedSearch(bool $changeLanguage): void
$this->findCssAndGetText($page, '.adv_search_terms strong')
);

// Make sure we have the expected number of filters applied:
$this->assertCount(2, $page->findAll('css', '.facet.active'));
$query = parse_url($session->getCurrentUrl(), PHP_URL_QUERY);
parse_str($query, $queryArray);
$expectedFilterCount = $includeCheckbox ? 3 : 2;
$this->assertCount($expectedFilterCount, $queryArray['filter']);

// If configured, flip-flop language again to potentially modify filter params:
if ($changeLanguage) {
Expand Down

0 comments on commit 4b7ac81

Please sign in to comment.