You are here

public function AjaxBehaviorTest::testAjaxDropdown in Facets 8

Tests ajax dropdown.

File

tests/src/FunctionalJavascript/AjaxBehaviorTest.php, line 79

Class

AjaxBehaviorTest
Tests for the JS that powers ajax.

Namespace

Drupal\Tests\facets\FunctionalJavascript

Code

public function testAjaxDropdown() {

  // Create facets.
  $this
    ->createFacet('owl');
  $this
    ->createFacet('duck', 'category', 'dropdown', []);

  // Go to the views page.
  $this
    ->drupalGet('search-api-test-fulltext');

  // Make sure the blocks are shown on the page.
  $page = $this
    ->getSession()
    ->getPage();
  $block_owl = $page
    ->findById('block-owl-block');
  $block_owl
    ->isVisible();
  $block_duck = $page
    ->findById('block-duck-block');
  $block_duck
    ->isVisible();
  $this
    ->assertSession()
    ->pageTextContains('Displaying 5 search results');

  // Check that the article_category option disappears when filtering on item.
  $dropdown_entry = $this
    ->xpath('//*[@id="block-duck-block"]/div/select/option[normalize-space(text())=:label]', [
    ':label' => 'article_category',
  ]);
  $this
    ->assertNotEmpty($dropdown_entry);
  $block_owl
    ->clickLink('item');
  $this
    ->assertSession()
    ->assertWaitOnAjaxRequest();
  $dropdown_entry = $this
    ->xpath('//*[@id="block-duck-block"]/div/select/option[normalize-space(text())=:label]', [
    ':label' => 'article_category',
  ]);
  $this
    ->assertEmpty($dropdown_entry);

  // Click the item facet again.
  $block_owl
    ->clickLink('item');
  $this
    ->assertSession()
    ->assertWaitOnAjaxRequest();

  // Select the article_category in the dropdown.
  $dropdown = $this
    ->xpath('//*[@id="block-duck-block"]/div/select');
  $dropdown[0]
    ->selectOption('article_category');
  $this
    ->assertSession()
    ->assertWaitOnAjaxRequest();
  $this
    ->assertSession()
    ->pageTextContains('Displaying 2 search results');

  // Check that the article link exists (and is formatted like a facet) link.
  $links = $this
    ->xpath('//a//span[normalize-space(text())=:label]', [
    ':label' => 'article',
  ]);
  $this
    ->assertNotEmpty($links);

  // Check that the item link didn't exists.
  $links = $this
    ->xpath('//a//span[normalize-space(text())=:label]', [
    ':label' => 'item',
  ]);
  $this
    ->assertEmpty($links);
}