diff --git a/js/soft-limit.js b/js/soft-limit.js index ea2bd33..f301175 100644 --- a/js/soft-limit.js +++ b/js/soft-limit.js @@ -23,7 +23,7 @@ * Applies the soft limit UI feature to a specific facets list. */ Drupal.facets.applySoftLimit = function (facet, limit, settings) { - var zero_based_limit = limit - 1; + var zero_based_limit = (limit - 1); var facetsList = $('ul[data-drupal-facet-id="' + facet + '"]'); // Hide facets over the limit. diff --git a/tests/src/FunctionalJavascript/WidgetJSTest.php b/tests/src/FunctionalJavascript/WidgetJSTest.php index 752af7b..00b8299 100644 --- a/tests/src/FunctionalJavascript/WidgetJSTest.php +++ b/tests/src/FunctionalJavascript/WidgetJSTest.php @@ -63,6 +63,54 @@ class WidgetJSTest extends JavascriptTestBase { } /** + * Tests show more / less links. + */ + 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' => 'views_page:search_api_test_view__page_1', + 'field_identifier' => 'type', + 'empty_behavior' => ['behavior' => 'none'], + 'widget' => [ + 'type' => 'links', + 'config' => [ + 'show_numbers' => TRUE, + 'soft_limit' => TRUE, + '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'); + } + + /** * Tests checkbox widget. */ public function testCheckboxWidget() { diff --git a/tests/src/Unit/Plugin/widget/CheckboxWidgetTest.php b/tests/src/Unit/Plugin/widget/CheckboxWidgetTest.php index d686439..dcf4575 100644 --- a/tests/src/Unit/Plugin/widget/CheckboxWidgetTest.php +++ b/tests/src/Unit/Plugin/widget/CheckboxWidgetTest.php @@ -85,7 +85,15 @@ class CheckboxWidgetTest extends UnitTestCase { */ public function testDefaultConfiguration() { $default_config = $this->widget->defaultConfiguration(); - $this->assertEquals(['show_numbers' => FALSE, 'soft_limit' => 0], $default_config); + $expected = [ + 'show_numbers' => FALSE, + 'soft_limit' => 0, + 'soft_limit_settings' => [ + 'show_less_label' => 'Show less', + 'show_more_label' => 'Show more', + ], + ]; + $this->assertEquals($expected, $default_config); } /** diff --git a/tests/src/Unit/Plugin/widget/LinksWidgetTest.php b/tests/src/Unit/Plugin/widget/LinksWidgetTest.php index 64f8764..6b462d6 100644 --- a/tests/src/Unit/Plugin/widget/LinksWidgetTest.php +++ b/tests/src/Unit/Plugin/widget/LinksWidgetTest.php @@ -216,7 +216,15 @@ class LinksWidgetTest extends UnitTestCase { */ public function testDefaultConfiguration() { $default_config = $this->widget->defaultConfiguration(); - $this->assertEquals(['show_numbers' => FALSE, 'soft_limit' => 0], $default_config); + $expected = [ + 'show_numbers' => FALSE, + 'soft_limit' => 0, + 'soft_limit_settings' => [ + 'show_less_label' => 'Show less', + 'show_more_label' => 'Show more', + ], + ]; + $this->assertEquals($expected, $default_config); } /**