You are here

public function WebformElementComputedJavaScriptTest::testComputedElementAjax in Webform 8.5

Same name and namespace in other branches
  1. 6.x tests/src/FunctionalJavascript/Element/WebformElementComputedJavaScriptTest.php \Drupal\Tests\webform\FunctionalJavascript\Element\WebformElementComputedJavaScriptTest::testComputedElementAjax()

Tests computed element Ajax.

File

tests/src/FunctionalJavascript/Element/WebformElementComputedJavaScriptTest.php, line 29

Class

WebformElementComputedJavaScriptTest
Tests webform computed element Ajax support.

Namespace

Drupal\Tests\webform\FunctionalJavascript\Element

Code

public function testComputedElementAjax() {
  $session = $this
    ->getSession();
  $page = $session
    ->getPage();
  $assert_session = $this
    ->assertSession();
  $webform = Webform::load('test_element_computed_ajax');

  /**************************************************************************/

  // Check computed Twig element a and b elements exist.
  $this
    ->drupalGet($webform
    ->toUrl());
  $assert_session
    ->fieldExists('a[select]');
  $assert_session
    ->fieldExists('b');
  $assert_session
    ->buttonExists('webform-computed-webform_computed_twig-button');
  $assert_session
    ->hiddenFieldValueEquals('webform_computed_twig', 'Please enter a value for a and b.');

  // Calculate computed Twig element.
  $page
    ->fillField('a[select]', '1');
  $page
    ->fillField('b', '1');
  $session
    ->executeScript("jQuery('input[name=\"webform_computed_twig\"]').click()");
  $assert_session
    ->waitForText('1 + 1 = 2');

  // Check that computed Twig was calculated.
  $assert_session
    ->hiddenFieldValueNotEquals('webform_computed_twig', 'Please enter a value for a and b.');
  $assert_session
    ->hiddenFieldValueEquals('webform_computed_twig', '1 + 1 = 2');
}