function FormGroupingElementsTest::testVerticalTabChildVisibility

Same name in other branches
  1. 9 core/tests/Drupal/FunctionalJavascriptTests/Core/Form/FormGroupingElementsTest.php \Drupal\FunctionalJavascriptTests\Core\Form\FormGroupingElementsTest::testVerticalTabChildVisibility()
  2. 8.9.x core/tests/Drupal/FunctionalJavascriptTests/Core/Form/FormGroupingElementsTest.php \Drupal\FunctionalJavascriptTests\Core\Form\FormGroupingElementsTest::testVerticalTabChildVisibility()
  3. 10 core/tests/Drupal/FunctionalJavascriptTests/Core/Form/FormGroupingElementsTest.php \Drupal\FunctionalJavascriptTests\Core\Form\FormGroupingElementsTest::testVerticalTabChildVisibility()

Tests that vertical tab children become visible.

Makes sure that a child element of a vertical tab that is not visible, becomes visible when the tab is clicked, a fragment link to the child is clicked or when the URI fragment pointing to that child changes.

File

core/tests/Drupal/FunctionalJavascriptTests/Core/Form/FormGroupingElementsTest.php, line 45

Class

FormGroupingElementsTest
Tests for form grouping elements.

Namespace

Drupal\FunctionalJavascriptTests\Core\Form

Code

public function testVerticalTabChildVisibility() : void {
    $session = $this->getSession();
    $web_assert = $this->assertSession();
    // Request the group vertical tabs testing page with a fragment identifier
    // to the second element.
    $this->drupalGet('form-test/group-vertical-tabs', [
        'fragment' => 'edit-element-2',
    ]);
    $page = $session->getPage();
    $tab_link_1 = $page->find('css', '.vertical-tabs__menu-item > a');
    $child_1_selector = '#edit-element';
    $child_1 = $page->find('css', $child_1_selector);
    $child_2_selector = '#edit-element-2';
    $child_2 = $page->find('css', $child_2_selector);
    // Assert that the child in the second vertical tab becomes visible.
    // It should be visible after initial load due to the fragment in the URI.
    $this->assertTrue($child_2->isVisible(), 'Child 2 is visible due to a URI fragment');
    // Click on a fragment link pointing to an invisible child inside an
    // inactive vertical tab.
    $session->executeScript("jQuery('<a href=\"{$child_1_selector}\"></a>').insertAfter('h1')[0].click()");
    // Assert that the child in the first vertical tab becomes visible.
    $web_assert->waitForElementVisible('css', $child_1_selector, 50);
    // Trigger a URI fragment change (hashchange) to show the second vertical
    // tab again.
    $session->executeScript("location.replace('{$child_2_selector}')");
    // Assert that the child in the second vertical tab becomes visible again.
    $web_assert->waitForElementVisible('css', $child_2_selector, 50);
    $tab_link_1->click();
    // Assert that the child in the first vertical tab is visible again after
    // a click on the first tab.
    $this->assertTrue($child_1->isVisible(), 'Child 1 is visible after clicking the parent tab');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.