function AjaxTest::testAjaxFocus
Same name in other branches
- 11.x core/tests/Drupal/FunctionalJavascriptTests/Ajax/AjaxTest.php \Drupal\FunctionalJavascriptTests\Ajax\AjaxTest::testAjaxFocus()
Tests ajax focus handling.
File
-
core/
tests/ Drupal/ FunctionalJavascriptTests/ Ajax/ AjaxTest.php, line 303
Class
- AjaxTest
- Tests AJAX responses.
Namespace
Drupal\FunctionalJavascriptTests\AjaxCode
public function testAjaxFocus() : void {
$this->markTestSkipped("Skipped due to frequent random test failures. See https://www.drupal.org/project/drupal/issues/3396536");
$this->drupalGet('/ajax_forms_test_get_form');
$this->assertNotNull($select = $this->assertSession()
->elementExists('css', '#edit-select'));
$select->setValue('green');
$this->assertSession()
->assertWaitOnAjaxRequest();
$has_focus_id = $this->getSession()
->evaluateScript('document.activeElement.id');
$this->assertEquals('edit-select', $has_focus_id);
$this->assertNotNull($checkbox = $this->assertSession()
->elementExists('css', '#edit-checkbox'));
$checkbox->check();
$this->assertSession()
->assertWaitOnAjaxRequest();
$has_focus_id = $this->getSession()
->evaluateScript('document.activeElement.id');
$this->assertEquals('edit-checkbox', $has_focus_id);
$this->assertNotNull($textfield1 = $this->assertSession()
->elementExists('css', '#edit-textfield'));
$this->assertNotNull($textfield2 = $this->assertSession()
->elementExists('css', '#edit-textfield-2'));
$this->assertNotNull($textfield3 = $this->assertSession()
->elementExists('css', '#edit-textfield-3'));
// Test textfield with 'blur' event listener.
$textfield1->setValue('Kittens say purr');
$textfield2->focus();
$this->assertSession()
->assertWaitOnAjaxRequest();
$has_focus_id = $this->getSession()
->evaluateScript('document.activeElement.id');
$this->assertEquals('edit-textfield-2', $has_focus_id);
// Test textfield with 'change' event listener with refocus-blur set to
// FALSE.
$textfield2->setValue('Llamas say hi');
$textfield3->focus();
$this->assertSession()
->assertWaitOnAjaxRequest();
$has_focus_id = $this->getSession()
->evaluateScript('document.activeElement.id');
$this->assertEquals('edit-textfield-2', $has_focus_id);
// Test textfield with 'change' event.
$textfield3->focus();
$textfield3->setValue('Wasps buzz');
$textfield3->blur();
$this->assertSession()
->assertWaitOnAjaxRequest();
$has_focus_id = $this->getSession()
->evaluateScript('document.activeElement.id');
$this->assertEquals('edit-textfield-3', $has_focus_id);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.