You are here

public function LayoutBuilderModalTest::testLayoutBuilderModal in Layout Builder Modal 8

Tests the Layout Builder Modal.

File

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

Class

LayoutBuilderModalTest
Tests Layout Builder Modal.

Namespace

Drupal\Tests\layout_builder_modal\FunctionalJavascript

Code

public function testLayoutBuilderModal() {
  $layout_url = 'node/1/layout';
  $assert_session = $this
    ->assertSession();
  $page = $this
    ->getSession()
    ->getPage();
  $this
    ->drupalGet($layout_url);
  $this
    ->click('.layout-builder__add-block .layout-builder__link');
  $assert_session
    ->assertWaitOnAjaxRequest();
  $this
    ->clickLink('Create custom block');
  $assert_session
    ->assertWaitOnAjaxRequest();

  // Verify that the add block has been opened in the modal.
  $assert_session
    ->elementExists('css', '#layout-builder-modal .layout-builder-add-block');
  $textarea = $assert_session
    ->waitForElement('css', '[name="settings[block_form][body][0][value]"]');
  $this
    ->assertNotEmpty($textarea);
  $assert_session
    ->fieldValueEquals('Title', '');
  $page
    ->findField('Title')
    ->setValue('Hello World');
  $textarea
    ->setValue('Body says hello');
  $button = $assert_session
    ->elementExists('css', '#layout-builder-add-block .button--primary');
  $button
    ->press();
  $assert_session
    ->assertWaitOnAjaxRequest();

  // Verify that both the modal and off canvas has been closed.
  $assert_session
    ->elementNotExists('css', '#layout-builder-modal .layout-builder-add-block');
  $assert_session
    ->elementNotExists('css', '#drupal-off-canvas');
  $assert_session
    ->pageTextContains('Body says hello');
  $this
    ->clickContextualLink('.block-inline-blockbasic', 'Configure');
  $assert_session
    ->assertWaitOnAjaxRequest();

  // Verify that the update block has been opened in the modal.
  $assert_session
    ->elementExists('css', '#layout-builder-modal .layout-builder-update-block');
}