function FormGroupingElementsTest::testDetailsChildVisibility

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

Tests that details element children become visible.

Makes sure that a child element of a details element that is not visible, becomes visible when 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 93

Class

FormGroupingElementsTest
Tests for form grouping elements.

Namespace

Drupal\FunctionalJavascriptTests\Core\Form

Code

public function testDetailsChildVisibility() {
    $session = $this->getSession();
    $web_assert = $this->assertSession();
    // Store reusable JavaScript code to remove the current URI fragment and
    // close all details.
    $reset_js = "location.replace('#'); jQuery('details').removeAttr('open')";
    // Request the group details testing page.
    $this->drupalGet('form-test/group-details');
    $page = $session->getPage();
    $session->executeScript($reset_js);
    $child_selector = '#edit-element';
    $child = $page->find('css', $child_selector);
    // Assert that the child is not visible.
    $this->assertFalse($child->isVisible(), 'Child is not visible');
    // Trigger a URI fragment change (hashchange) to open all parent details
    // elements of the child.
    $session->executeScript("location.replace('{$child_selector}')");
    // Assert that the child becomes visible again after a hash change.
    $web_assert->waitForElementVisible('css', $child_selector, 50);
    $session->executeScript($reset_js);
    // Click on a fragment link pointing to an invisible child inside a closed
    // details element.
    $session->executeScript("jQuery('<a href=\"{$child_selector}\"></a>').insertAfter('h1')[0].click()");
    // Assert that the child is visible again after a fragment link click.
    $web_assert->waitForElementVisible('css', $child_selector, 50);
    // Find the summary belonging to the closest details element.
    $summary = $page->find('css', '#edit-meta > summary');
    // Assert that both aria-expanded and aria-pressed are true.
    $this->assertEquals('true', $summary->getAttribute('aria-expanded'));
    $this->assertEquals('true', $summary->getAttribute('aria-pressed'));
}

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