function ModalRendererTest::testOpenerInDropbutton

Same name and namespace in other branches
  1. 11.x core/modules/system/tests/src/FunctionalJavascript/ModalRendererTest.php \Drupal\Tests\system\FunctionalJavascript\ModalRendererTest::testOpenerInDropbutton()

Confirm focus management of a dialog openers in a dropbutton.

File

core/modules/system/tests/src/FunctionalJavascript/ModalRendererTest.php, line 106

Class

ModalRendererTest
Tests that dialog links use different renderer services.

Namespace

Drupal\Tests\system\FunctionalJavascript

Code

public function testOpenerInDropbutton() : void {
  $assert_session = $this->assertSession();
  $page = $this->getSession()
    ->getPage();
  $this->drupalGet('dialog_renderer-collapsed-opener');
  // Open a modal using a link inside a dropbutton.
  $page->find('css', '.dropbutton-toggle button')
    ->click();
  $modal_link = $assert_session->waitForElementVisible('css', '.secondary-action a');
  $modal_link->click();
  $assert_session->waitForElementVisible('css', '.ui-dialog');
  $assert_session->assertVisibleInViewport('css', '.ui-dialog .ui-dialog-content');
  $page->pressButton('Close');
  // When the dialog "closes" it is still present, so wait on it switching to
  // `display: none;`.
  $assert_session->waitForElement('css', '.ui-dialog[style*="display: none;"]');
  // Confirm that when the modal closes, focus is moved to the first visible
  // and focusable item in the contextual link container, because the original
  // opener is not available.
  $this->assertJsCondition('document.activeElement === document.querySelector(".dropbutton-action a")');
}

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