public function ElementTest::testAutocomplete in Select 2 8
Tests select2 autocomplete.
File
- tests/
src/ FunctionalJavascript/ Form/ ElementTest.php, line 87
Class
- ElementTest
- Tests the select2 element.
Namespace
Drupal\Tests\select2\FunctionalJavascript\FormCode
public function testAutocomplete() {
EntityTestMulRevPub::create([
'name' => 'foo',
])
->save();
EntityTestMulRevPub::create([
'name' => 'bar',
])
->save();
EntityTestMulRevPub::create([
'name' => 'gaga',
])
->save();
$page = $this
->getSession()
->getPage();
$this
->drupalGet('/select2-autocomplete-form');
$this
->click('.form-item-select2-autocomplete .select2-selection.select2-selection--single');
$this
->assertNotEmpty($this
->assertSession()
->waitForElementVisible('css', '.select2-search__field'));
$page
->find('css', '.select2-search__field')
->setValue('gaga');
$this
->assertNotEmpty($this
->assertSession()
->waitForElementVisible('css', '.select2-results__option--highlighted'));
$page
->find('css', '.select2-results__option--highlighted')
->click();
$page
->pressButton('Submit');
$json = json_decode($this
->getSession()
->getPage()
->getText(), TRUE);
$this
->assertEquals([
[
'target_id' => 3,
],
], $json['select2_autocomplete']);
}