You are here

public function OffCanvasTest::testOffCanvasLinks in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/system/tests/src/FunctionalJavascript/OffCanvasTest.php \Drupal\Tests\system\FunctionalJavascript\OffCanvasTest::testOffCanvasLinks()

Tests that non-contextual links will work with the off-canvas dialog.

@dataProvider themeDataProvider

File

core/modules/system/tests/src/FunctionalJavascript/OffCanvasTest.php, line 38

Class

OffCanvasTest
Tests the off-canvas dialog functionality.

Namespace

Drupal\Tests\system\FunctionalJavascript

Code

public function testOffCanvasLinks($theme) {
  $this
    ->enableTheme($theme);
  $this
    ->drupalGet('/off-canvas-test-links');
  $page = $this
    ->getSession()
    ->getPage();
  $web_assert = $this
    ->assertSession();

  // Make sure off-canvas dialog is on page when first loaded.
  $web_assert
    ->elementNotExists('css', '#drupal-off-canvas');

  // Check opening and closing with two separate links.
  // Make sure tray updates to new content.
  // Check the first link again to make sure the empty title class is
  // removed.
  foreach ([
    '1',
    '2',
    '1',
  ] as $link_index) {
    $this
      ->assertOffCanvasDialog($link_index, 'side');
    $header_text = $this
      ->getOffCanvasDialog()
      ->find('css', '.ui-dialog-title')
      ->getText();
    if ($link_index == '2') {

      // Check no title behavior.
      $web_assert
        ->elementExists('css', '.ui-dialog-empty-title');
      $this
        ->assertEquals(' ', $header_text);
      $style = $page
        ->find('css', '.ui-dialog-off-canvas')
        ->getAttribute('style');
      $this
        ->assertTrue(strstr($style, 'width: 555px;') !== FALSE, 'Dialog width respected.');
      $page
        ->clickLink("Open side panel 1");
      $this
        ->waitForOffCanvasToOpen();
      $style = $page
        ->find('css', '.ui-dialog-off-canvas')
        ->getAttribute('style');
      $this
        ->assertTrue(strstr($style, 'width: 555px;') === FALSE, 'Dialog width reset to default.');
    }
    else {

      // Check that header is correct.
      $this
        ->assertEquals("Thing {$link_index}", $header_text);
      $web_assert
        ->elementNotExists('css', '.ui-dialog-empty-title');
    }
  }

  // Test the off_canvas_top tray.
  foreach ([
    1,
    2,
  ] as $link_index) {
    $this
      ->assertOffCanvasDialog($link_index, 'top');
    $style = $page
      ->find('css', '.ui-dialog-off-canvas')
      ->getAttribute('style');
    if ($link_index === 1) {
      $this
        ->assertTrue((bool) strstr($style, 'height: auto;'));
    }
    else {
      $this
        ->assertTrue((bool) strstr($style, 'height: 421px;'));
    }
  }

  // Ensure an off-canvas link opened from inside the off-canvas dialog will
  // work.
  $this
    ->drupalGet('/off-canvas-test-links');
  $page
    ->clickLink('Display more links!');
  $this
    ->waitForOffCanvasToOpen();
  $web_assert
    ->linkExists('Off_canvas link!');

  // Click off-canvas link inside off-canvas dialog
  $page
    ->clickLink('Off_canvas link!');

  /*  @var \Behat\Mink\Element\NodeElement $dialog */
  $this
    ->waitForOffCanvasToOpen();
  $web_assert
    ->elementTextContains('css', '.ui-dialog[aria-describedby="drupal-off-canvas"]', 'Thing 2 says hello');

  // Ensure an off-canvas link opened from inside the off-canvas dialog will
  // work after another dialog has been opened.
  $this
    ->drupalGet('/off-canvas-test-links');
  $page
    ->clickLink("Open side panel 1");
  $this
    ->waitForOffCanvasToOpen();
  $page
    ->clickLink('Display more links!');
  $this
    ->waitForOffCanvasToOpen();
  $web_assert
    ->linkExists('Off_canvas link!');

  // Click off-canvas link inside off-canvas dialog
  $page
    ->clickLink('Off_canvas link!');

  /*  @var \Behat\Mink\Element\NodeElement $dialog */
  $this
    ->waitForOffCanvasToOpen();
  $web_assert
    ->elementTextContains('css', '.ui-dialog[aria-describedby="drupal-off-canvas"]', 'Thing 2 says hello');
}