3 namespace Drupal\FunctionalJavascriptTests\Core\Form;
5 use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
8 * Tests for form grouping elements.
12 class FormGroupingElementsTest extends WebDriverTestBase {
19 public static $modules = ['form_test'];
24 protected function setUp() {
27 $account = $this->drupalCreateUser();
28 $this->drupalLogin($account);
32 * Tests that vertical tab children become visible.
34 * Makes sure that a child element of a vertical tab that is not visible,
35 * becomes visible when the tab is clicked, a fragment link to the child is
36 * clicked or when the URI fragment pointing to that child changes.
38 public function testVerticalTabChildVisibility() {
39 $session = $this->getSession();
40 $web_assert = $this->assertSession();
42 // Request the group vertical tabs testing page with a fragment identifier
43 // to the second element.
44 $this->drupalGet('form-test/group-vertical-tabs', ['fragment' => 'edit-element-2']);
46 $page = $session->getPage();
48 $tab_link_1 = $page->find('css', '.vertical-tabs__menu-item > a');
50 $child_1_selector = '#edit-element';
51 $child_1 = $page->find('css', $child_1_selector);
53 $child_2_selector = '#edit-element-2';
54 $child_2 = $page->find('css', $child_2_selector);
56 // Assert that the child in the second vertical tab becomes visible.
57 // It should be visible after initial load due to the fragment in the URI.
58 $this->assertTrue($child_2->isVisible(), 'Child 2 is visible due to a URI fragment');
60 // Click on a fragment link pointing to an invisible child inside an
61 // inactive vertical tab.
62 $session->executeScript("jQuery('<a href=\"$child_1_selector\"></a>').insertAfter('h1')[0].click()");
64 // Assert that the child in the first vertical tab becomes visible.
65 $web_assert->waitForElementVisible('css', $child_1_selector, 50);
67 // Trigger a URI fragment change (hashchange) to show the second vertical
69 $session->executeScript("location.replace('$child_2_selector')");
71 // Assert that the child in the second vertical tab becomes visible again.
72 $web_assert->waitForElementVisible('css', $child_2_selector, 50);
76 // Assert that the child in the first vertical tab is visible again after
77 // a click on the first tab.
78 $this->assertTrue($child_1->isVisible(), 'Child 1 is visible after clicking the parent tab');
82 * Tests that details element children become visible.
84 * Makes sure that a child element of a details element that is not visible,
85 * becomes visible when a fragment link to the child is clicked or when the
86 * URI fragment pointing to that child changes.
88 public function testDetailsChildVisibility() {
89 $session = $this->getSession();
90 $web_assert = $this->assertSession();
92 // Store reusable JavaScript code to remove the current URI fragment and
94 $reset_js = "location.replace('#'); jQuery('details').removeAttr('open')";
96 // Request the group details testing page.
97 $this->drupalGet('form-test/group-details');
99 $page = $session->getPage();
101 $session->executeScript($reset_js);
103 $child_selector = '#edit-element';
104 $child = $page->find('css', $child_selector);
106 // Assert that the child is not visible.
107 $this->assertFalse($child->isVisible(), 'Child is not visible');
109 // Trigger a URI fragment change (hashchange) to open all parent details
110 // elements of the child.
111 $session->executeScript("location.replace('$child_selector')");
113 // Assert that the child becomes visible again after a hash change.
114 $web_assert->waitForElementVisible('css', $child_selector, 50);
116 $session->executeScript($reset_js);
118 // Click on a fragment link pointing to an invisible child inside a closed
120 $session->executeScript("jQuery('<a href=\"$child_selector\"></a>').insertAfter('h1')[0].click()");
122 // Assert that the child is visible again after a fragment link click.
123 $web_assert->waitForElementVisible('css', $child_selector, 50);
125 // Find the summary belonging to the closest details element.
126 $summary = $page->find('css', '#edit-meta > summary');
128 // Assert that both aria-expanded and aria-pressed are true.
129 $this->assertTrue($summary->getAttribute('aria-expanded'));
130 $this->assertTrue($summary->getAttribute('aria-pressed'));