You are here

public function ElementTest::testOptgroups in Select 2 8

Tests select2 optgroups.

File

tests/src/FunctionalJavascript/Form/ElementTest.php, line 28

Class

ElementTest
Tests the select2 element.

Namespace

Drupal\Tests\select2\FunctionalJavascript\Form

Code

public function testOptgroups() {
  $page = $this
    ->getSession()
    ->getPage();
  $this
    ->drupalGet('/select2-optgroup-form');
  $this
    ->click('.form-item-select2-optgroups .select2-selection.select2-selection--single');
  $this
    ->assertNotEmpty($this
    ->assertSession()
    ->waitForElementVisible('css', '.select2-results__group'));
  $this
    ->assertSession()
    ->elementTextContains('css', '.select2-results__group', 'Baba');
  $this
    ->assertSession()
    ->elementTextContains('css', 'ul.select2-results__options li.select2-results__option ul.select2-results__options--nested li.select2-results__option', 'Nana');
  $page
    ->find('css', '.select2-search__field')
    ->setValue('Nana');
  $page
    ->find('css', '.select2-results__option--highlighted')
    ->click();
  $page
    ->pressButton('Submit');
  $json = json_decode($this
    ->getSession()
    ->getPage()
    ->getText(), TRUE);
  $this
    ->assertEquals(3, $json['select2_optgroups']);
}