You are here

protected function LayoutBuilderModalTest::clickContextualLink in Layout Builder Modal 8

@todo Remove this in https://www.drupal.org/project/drupal/issues/2918718.

Overrides ContextualLinkClickTrait::clickContextualLink

1 call to LayoutBuilderModalTest::clickContextualLink()
LayoutBuilderModalTest::testLayoutBuilderModal in tests/src/FunctionalJavascript/LayoutBuilderModalTest.php
Tests the Layout Builder Modal.

File

tests/src/FunctionalJavascript/LayoutBuilderModalTest.php, line 222

Class

LayoutBuilderModalTest
Tests Layout Builder Modal.

Namespace

Drupal\Tests\layout_builder_modal\FunctionalJavascript

Code

protected function clickContextualLink($selector, $link_locator, $force_visible = TRUE) {

  /** @var \Drupal\FunctionalJavascriptTests\JSWebAssert $assert_session */
  $assert_session = $this
    ->assertSession();

  /** @var \Behat\Mink\Element\DocumentElement $page */
  $page = $this
    ->getSession()
    ->getPage();
  $page
    ->waitFor(10, function () use ($page, $selector) {
    return $page
      ->find('css', "{$selector} .contextual-links");
  });
  if (count($page
    ->findAll('css', "{$selector} .contextual-links")) > 1) {
    throw new \Exception('More than one contextual links found by selector');
  }
  if ($force_visible && $page
    ->find('css', "{$selector} .contextual .trigger.visually-hidden")) {
    $this
      ->toggleContextualTriggerVisibility($selector);
  }
  $link = $assert_session
    ->elementExists('css', $selector)
    ->findLink($link_locator);
  $this
    ->assertNotEmpty($link);
  if (!$link
    ->isVisible()) {
    $button = $assert_session
      ->waitForElementVisible('css', "{$selector} .contextual button");
    $this
      ->assertNotEmpty($button);
    $button
      ->press();
    $link = $page
      ->waitFor(10, function () use ($link) {
      return $link
        ->isVisible() ? $link : FALSE;
    });
  }
  $link
    ->click();
  if ($force_visible) {
    $this
      ->toggleContextualTriggerVisibility($selector);
  }
}