You are here

public function CKEditor5DialogTest::testCKEditor5FocusInTooltipsInDialog in Drupal 10

Tests if CKEditor 5 tooltips can be interacted with in dialogs.

File

core/modules/ckeditor5/tests/src/FunctionalJavascript/CKEditor5DialogTest.php, line 34

Class

CKEditor5DialogTest
Tests for CKEditor 5 to ensure correct focus management in dialogs.

Namespace

Drupal\Tests\ckeditor5\FunctionalJavascript

Code

public function testCKEditor5FocusInTooltipsInDialog() {
  FilterFormat::create([
    'format' => 'test_format',
    'name' => 'CKEditor 5 with link',
    'roles' => [
      RoleInterface::AUTHENTICATED_ID,
    ],
  ])
    ->save();
  Editor::create([
    'format' => 'test_format',
    'editor' => 'ckeditor5',
    'settings' => [
      'toolbar' => [
        'items' => [
          'link',
        ],
      ],
    ],
  ])
    ->save();
  $this
    ->assertSame([], array_map(function (ConstraintViolation $v) {
    return (string) $v
      ->getMessage();
  }, iterator_to_array(CKEditor5::validatePair(Editor::load('test_format'), FilterFormat::load('test_format')))));
  $page = $this
    ->getSession()
    ->getPage();
  $assert_session = $this
    ->assertSession();
  $this
    ->drupalGet('/ckeditor5_test/dialog');
  $page
    ->clickLink('Add Node');
  $assert_session
    ->waitForElementVisible('css', '[role="dialog"]');
  $assert_session
    ->assertWaitOnAjaxRequest();
  $content_area = $assert_session
    ->waitForElementVisible('css', '.ck-editor__editable');

  // Focus the editable area first.
  $content_area
    ->click();

  // Then press the button to add a link.
  $this
    ->pressEditorButton('Link');
  $link_url = '/ckeditor5_test/dialog';
  $input = $assert_session
    ->waitForElementVisible('css', '.ck-balloon-panel input.ck-input-text');

  // Make sure the input field can have focus and we can type into it.
  $input
    ->setValue($link_url);

  // Save the new link.
  $page
    ->find('css', '.ck-balloon-panel .ck-button-save')
    ->click();

  // Make sure something was added to the text.
  $this
    ->assertNotEmpty($content_area
    ->getText());
}