You are here

public function WidgetJSTest::testLinksShowMoreLess in Facets 8

Tests show more / less links.

File

tests/src/FunctionalJavascript/WidgetJSTest.php, line 37

Class

WidgetJSTest
Tests for the JS that transforms widgets into form elements.

Namespace

Drupal\Tests\facets\FunctionalJavascript

Code

public function testLinksShowMoreLess() {
  $facet_storage = \Drupal::entityTypeManager()
    ->getStorage('facets_facet');
  $id = 'owl';

  // Create and save a facet with a checkbox widget on the 'type' field.
  $facet_storage
    ->create([
    'id' => $id,
    'name' => strtoupper($id),
    'url_alias' => $id,
    'facet_source_id' => 'search_api:views_page__search_api_test_view__page_1',
    'field_identifier' => 'type',
    'empty_behavior' => [
      'behavior' => 'none',
    ],
    'weight' => 1,
    'widget' => [
      'type' => 'links',
      'config' => [
        'show_numbers' => TRUE,
        'soft_limit' => 1,
        'soft_limit_settings' => [
          'show_less_label' => 'Show less',
          'show_more_label' => 'Show more',
        ],
      ],
    ],
    'processor_configs' => [
      'url_processor_handler' => [
        'processor_id' => 'url_processor_handler',
        'weights' => [
          'pre_query' => -10,
          'build' => -10,
        ],
        'settings' => [],
      ],
    ],
  ])
    ->save();
  $this
    ->createBlock($id);

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

  // Make sure the block is shown on the page.
  $page = $this
    ->getSession()
    ->getPage();
  $block = $page
    ->findById('block-owl-block');
  $block
    ->isVisible();

  // Make sure the show more / show less links are shown.
  $this
    ->assertSession()
    ->linkExists('Show more');

  // Change the link label of show more into "Moar Llamas".
  $facet = Facet::load('owl');
  $facet
    ->setWidget('links', [
    'show_numbers' => TRUE,
    'soft_limit' => 1,
    'soft_limit_settings' => [
      'show_less_label' => 'Show less',
      'show_more_label' => 'Moar Llamas',
    ],
  ]);
  $facet
    ->save();

  // Check that the new configuration is used now.
  $this
    ->drupalGet('search-api-test-fulltext');
  $this
    ->assertSession()
    ->linkNotExists('Show more');
  $this
    ->assertSession()
    ->linkExists('Moar Llamas');
}