You are here

protected function JavascriptStatesTest::doSelectTriggerTests in Drupal 10

Same name and namespace in other branches
  1. 9 core/tests/Drupal/FunctionalJavascriptTests/Core/Form/JavascriptStatesTest.php \Drupal\FunctionalJavascriptTests\Core\Form\JavascriptStatesTest::doSelectTriggerTests()

Tests states of elements triggered by a select element.

1 call to JavascriptStatesTest::doSelectTriggerTests()
JavascriptStatesTest::testJavascriptStates in core/tests/Drupal/FunctionalJavascriptTests/Core/Form/JavascriptStatesTest.php
Tests the JavaScript #states functionality of form elements.

File

core/tests/Drupal/FunctionalJavascriptTests/Core/Form/JavascriptStatesTest.php, line 272

Class

JavascriptStatesTest
Tests the state of elements based on another elements.

Namespace

Drupal\FunctionalJavascriptTests\Core\Form

Code

protected function doSelectTriggerTests() {
  $this
    ->drupalGet('form-test/javascript-states-form');
  $page = $this
    ->getSession()
    ->getPage();

  // Find trigger and target elements.
  $trigger = $page
    ->findField('select_trigger');
  $this
    ->assertNotEmpty($trigger);
  $item_visible_value2 = $this
    ->assertSession()
    ->elementExists('css', '#edit-item-visible-when-select-trigger-has-value2');
  $textfield_visible_value3 = $page
    ->findField('textfield_visible_when_select_trigger_has_value3');
  $this
    ->assertNotEmpty($textfield_visible_value3);
  $textfield_visible_value2_or_value3 = $page
    ->findField('textfield_visible_when_select_trigger_has_value2_or_value3');
  $this
    ->assertNotEmpty($textfield_visible_value2_or_value3);

  // Verify initial state.
  $this
    ->assertFalse($item_visible_value2
    ->isVisible());
  $this
    ->assertFalse($textfield_visible_value3
    ->isVisible());
  $this
    ->assertFalse($textfield_visible_value2_or_value3
    ->isVisible());

  // Change state: select the 'Value 2' option.
  $trigger
    ->setValue('value2');
  $this
    ->assertTrue($item_visible_value2
    ->isVisible());
  $this
    ->assertFalse($textfield_visible_value3
    ->isVisible());
  $this
    ->assertTrue($textfield_visible_value2_or_value3
    ->isVisible());

  // Change state: select the 'Value 3' option.
  $trigger
    ->setValue('value3');
  $this
    ->assertFalse($item_visible_value2
    ->isVisible());
  $this
    ->assertTrue($textfield_visible_value3
    ->isVisible());
  $this
    ->assertTrue($textfield_visible_value2_or_value3
    ->isVisible());
}