Commit e3d5d3ec authored by borisson_'s avatar borisson_ Committed by borisson_

Issue #2986020 by Ice-D, borisson_: Ajax facets don't respect views exposed filters

parent ca701c62
......@@ -192,6 +192,7 @@
});
if (reload) {
href = addExposedFiltersToFacetsUrl(href, options.extraData.view_name, options.extraData.view_display_id);
updateFacetsBlocks(href);
}
}
......@@ -200,4 +201,17 @@
beforeSend.apply(this, arguments);
}
// Helper function to add exposed form data to facets url
var addExposedFiltersToFacetsUrl = function(href, view_name, view_display_id) {
var $exposed_form = $('form#views-exposed-form-' + view_name.replace(/_/g, '-') + '-' + view_display_id.replace(/_/g, '-'));
var params = Drupal.Views.parseQueryString(href);
$.each($exposed_form.serializeArray(), function() {
params[this.name] = this.value;
});
return href.split('?')[0] + '?' + $.param(params);
};
})(jQuery, Drupal);
......@@ -12,18 +12,25 @@ use Drupal\views\Entity\View;
class AjaxBehaviorTest extends JsBase {
/**
* Tests ajax links.
* {@inheritdoc}
*/
public function testAjaxLinks() {
// Create facets.
$this->createFacet('owl');
$this->createFacet('duck', 'keywords');
public function setUp() {
parent::setUp();
// Force ajax.
$view = View::load('search_api_test_view');
$display = $view->getDisplay('page_1');
$display['display_options']['use_ajax'] = TRUE;
$view->save();
}
/**
* Tests ajax links.
*/
public function testAjaxLinks() {
// Create facets.
$this->createFacet('owl');
$this->createFacet('duck', 'keywords');
// Go to the views page.
$this->drupalGet('search-api-test-fulltext');
......@@ -55,7 +62,7 @@ class AjaxBehaviorTest extends JsBase {
$this->assertSession()->assertWaitOnAjaxRequest();
$this->assertSession()->pageTextContains('Displaying 5 search results');
$links = $this->xpath('//a//span[normalize-space(text())=:label]', [':label' => 'article']);
// $this->assertNotEmpty($links);
$this->assertNotEmpty($links);
// Check that the strawberry link disappears when filtering on items.
$links = $this->xpath('//a//span[normalize-space(text())=:label]', [':label' => 'strawberry']);
......@@ -66,4 +73,30 @@ class AjaxBehaviorTest extends JsBase {
$this->assertEmpty($links);
}
/**
* Tests links with exposed filters.
*/
public function testLinksWithExposedFilter() {
$view = View::load('search_api_test_view');
$display = $view->getDisplay('page_1');
$display['display_options']['filters']['search_api_fulltext']['expose']['required'] = TRUE;
$view->save();
$this->createFacet('owl');
$this->drupalGet('search-api-test-fulltext');
$page = $this->getSession()->getPage();
$block_owl = $page->findById('block-owl-block');
$block_owl->isVisible();
$this->assertSession()->fieldExists('edit-search-api-fulltext')->setValue('baz');
$this->click('.form-submit');
$this->assertSession()->assertWaitOnAjaxRequest();
$this->assertSession()->pageTextContains('Displaying 3 search results');
$this->clickLink('item');
$this->assertSession()->assertWaitOnAjaxRequest();
$this->assertSession()->pageTextContains('Displaying 1 search results');
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment