public function EntityReferenceWidgetTest::testFocusNotAppliedWithoutSelectionChange in Drupal 9
Same name and namespace in other branches
- 8 core/modules/media_library/tests/src/FunctionalJavascript/EntityReferenceWidgetTest.php \Drupal\Tests\media_library\FunctionalJavascript\EntityReferenceWidgetTest::testFocusNotAppliedWithoutSelectionChange()
Tests that disabled media items don't capture focus on page load.
File
- core/
modules/ media_library/ tests/ src/ FunctionalJavascript/ EntityReferenceWidgetTest.php, line 63
Class
- EntityReferenceWidgetTest
- Tests the Media library entity reference widget.
Namespace
Drupal\Tests\media_library\FunctionalJavascriptCode
public function testFocusNotAppliedWithoutSelectionChange() {
// Create a node with the maximum number of values for the field_twin_media
// field.
$node = $this
->drupalCreateNode([
'type' => 'basic_page',
'field_twin_media' => [
$this->mediaItems['Horse'],
$this->mediaItems['Bear'],
],
]);
$this
->drupalGet($node
->toUrl('edit-form'));
$open_button = $this
->assertElementExistsAfterWait('css', '.js-media-library-open-button[name^="field_twin_media"]');
// The open button should be disabled, but not have the
// 'data-disabled-focus' attribute.
$this
->assertFalse($open_button
->hasAttribute('data-disabled-focus'));
$this
->assertTrue($open_button
->hasAttribute('disabled'));
// The button should be disabled.
$this
->assertJsCondition('jQuery("#field_twin_media-media-library-wrapper .js-media-library-open-button").is(":disabled")');
// The button should not have focus.
$this
->assertJsCondition('jQuery("#field_twin_media-media-library-wrapper .js-media-library-open-button").not(":focus")');
}