You are here

public function AjaxBehaviorTest::testAjaxLinks in Facets 8

Tests ajax links.

File

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

Class

AjaxBehaviorTest
Tests for the JS that powers ajax.

Namespace

Drupal\Tests\facets\FunctionalJavascript

Code

public function testAjaxLinks() {

  // Create facets.
  $this
    ->createFacet('owl');
  $this
    ->createFacet('duck', 'keywords');

  // 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 link exists (and is formatted like a facet) link.
  $links = $this
    ->xpath('//a//span[normalize-space(text())=:label]', [
    ':label' => 'article',
  ]);
  $this
    ->assertNotEmpty($links);

  // Click the item facet.
  $this
    ->clickLink('item');
  $this
    ->assertSession()
    ->assertWaitOnAjaxRequest();
  $this
    ->assertSession()
    ->pageTextContains('Displaying 3 search results');

  // Check that the article facet is now gone.
  $links = $this
    ->xpath('//a//span[normalize-space(text())=:label]', [
    ':label' => 'article',
  ]);
  $this
    ->assertEmpty($links);

  // Click the item facet again, and check that the article facet is back.
  $this
    ->clickLink('item');
  $this
    ->assertSession()
    ->assertWaitOnAjaxRequest();
  $this
    ->assertSession()
    ->pageTextContains('Displaying 5 search results');
  $links = $this
    ->xpath('//a//span[normalize-space(text())=:label]', [
    ':label' => 'article',
  ]);
  $this
    ->assertNotEmpty($links);

  // Check that the strawberry link disappears when filtering on items.
  $links = $this
    ->xpath('//a//span[normalize-space(text())=:label]', [
    ':label' => 'strawberry',
  ]);
  $this
    ->assertNotEmpty($links);
  $this
    ->clickLink('item');
  $this
    ->assertSession()
    ->assertWaitOnAjaxRequest();
  $links = $this
    ->xpath('//a//span[normalize-space(text())=:label]', [
    ':label' => 'strawberry',
  ]);
  $this
    ->assertEmpty($links);
}