diff -u b/core/modules/views_ui/tests/src/FunctionalJavascript/FilterOptionsTest.php b/core/modules/views_ui/tests/src/FunctionalJavascript/FilterOptionsTest.php --- b/core/modules/views_ui/tests/src/FunctionalJavascript/FilterOptionsTest.php +++ b/core/modules/views_ui/tests/src/FunctionalJavascript/FilterOptionsTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\views_ui\FunctionalJavascript; +use Behat\Mink\Element\NodeElement; use Drupal\FunctionalJavascriptTests\JavascriptTestBase; /** @@ -39,36 +40,51 @@ $session = $this->getSession(); $web_assert = $this->assertSession(); - $page = $session->getPage(); // Open the dialog. $page->clickLink('views-add-field'); - $web_assert->assertWaitOnAjaxRequest(); + + // Wait for the popup to open and the search field to be available. + $options_search = $web_assert->waitForField('override[controls][options_search]'); + + // Assert the count is equal before filtering. + $all_rows = $page->findAll('css', '.filterable-option'); + $visible_rows = $this->filterVisibleElements($all_rows); + $this->assertTrue(count($visible_rows) == count($all_rows)); // Populate the options search field with the string 'date'. - $page->fillField('override[controls][options_search]', 'date'); - $session->wait(1000); + $options_search->setValue('date'); + + // Wait for the filtering to finish by checking on a field that we know + // should now be invisible. + $page->waitFor(10, function() use ($page) { + return !$page->findField('name[node_field_data.uid]')->isVisible(); + }); // Find matching rows based on visibility. - $all_rows = $page->findAll('css', 'tr.filterable-option'); + $all_rows = $page->findAll('css', '.filterable-option'); $visible_rows = $this->filterVisibleElements($all_rows); // Test that greater than zero options have been returned. - $this->assertTrue(count($visible_rows), format_string('Options filter found @num rows containing "date".', array('@num' => count($visible_rows)))); + $this->assertTrue(count($visible_rows) > 0); // Test that the number of rows returned is less than total rows. - $this->assertTrue(count($visible_rows) < count($all_rows), 'Number of rows returned is less than total rows.'); + $this->assertTrue(count($visible_rows) < count($all_rows)); // Test that one of the return options is 'Updated date'. - $this->assertFieldByName('name[users_field_data.changed]', NULL, 'Updated date field is displayed.'); + $field = $page->findField('name[users_field_data.changed]'); + $this->assertTrue($field->isVisible()); } /** * Removes any non-visible elements from the passed array. * - * @param array $elements - * @return array + * @param NodeElement[] $elements + * Array of elements to filter. + * + * @return NodeElement[] + * Array of visible elements. */ protected function filterVisibleElements($elements) { $elements = array_filter($elements, function($element) {