Skip to content
Snippets Groups Projects

Issue #3238915: Refactor (if feasible) uses of the jQuery ready function to use VanillaJS

Closed Issue #3238915: Refactor (if feasible) uses of the jQuery ready function to use VanillaJS
Closed Harumi Jang requested to merge issue/drupal-3238915:3238915-refactor-if-feasible into 9.3.x
12 files
+ 353
40
Compare changes
  • Side-by-side
  • Inline
Files
12
  • 7ff9cbf0
    Issue #3032275 by alexpott, dww, bendeguz.csirmaz, tedbow: Create a... · 7ff9cbf0
    Lauri Timmanee authored
    Issue #3032275 by alexpott, dww, bendeguz.csirmaz, tedbow: Create a fault-tolerant method for interacting with links and fields in Javascript tests
@@ -2,10 +2,8 @@
namespace Drupal\Tests\layout_builder\FunctionalJavascript;
use Behat\Mink\Element\NodeElement;
use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
use Drupal\Tests\contextual\FunctionalJavascript\ContextualLinkClickTrait;
use WebDriver\Exception\UnknownError;
/**
* Tests that messages appear in the off-canvas dialog with configuring blocks.
@@ -59,14 +57,14 @@ public function testValidationMessage() {
// Enable layout builder.
$this->drupalGet($field_ui_prefix . '/display/default');
$this->submitForm(['layout[enabled]' => TRUE], 'Save');
$this->clickElementWhenClickable($page->findLink('Manage layout'));
$page->findLink('Manage layout')->click();
$assert_session->addressEquals($field_ui_prefix . '/display/default/layout');
$this->clickElementWhenClickable($page->findLink('Add block'));
$page->findLink('Add block')->click();
$this->assertNotEmpty($assert_session->waitForElementVisible('css', '#drupal-off-canvas .block-categories'));
$this->clickElementWhenClickable($page->findLink('Powered by Drupal'));
$page->findLink('Powered by Drupal')->click();
$this->assertNotEmpty($assert_session->waitForElementVisible('css', '#drupal-off-canvas [name="settings[label]"]'));
$page->findField('Title')->setValue('');
$this->clickElementWhenClickable($page->findButton('Add block'));
$page->findButton('Add block')->click();
$this->assertMessagesDisplayed();
$page->findField('Title')->setValue('New title');
$page->pressButton('Add block');
@@ -76,7 +74,7 @@ public function testValidationMessage() {
$assert_session->assertNoElementAfterWait('css', '#drupal-off-canvas');
$assert_session->assertWaitOnAjaxRequest();
$this->drupalGet($this->getUrl());
$this->clickElementWhenClickable($page->findButton('Save layout'));
$page->findButton('Save layout')->click();
$this->assertNotEmpty($assert_session->waitForElement('css', 'div:contains("The layout has been saved")'));
// Ensure that message are displayed when configuring an existing block.
@@ -85,7 +83,7 @@ public function testValidationMessage() {
$this->clickContextualLink($block_css_locator, 'Configure', TRUE);
$this->assertNotEmpty($assert_session->waitForElementVisible('css', '#drupal-off-canvas [name="settings[label]"]'));
$page->findField('Title')->setValue('');
$this->clickElementWhenClickable($page->findButton('Update'));
$page->findButton('Update')->click();
$this->assertMessagesDisplayed();
}
@@ -106,34 +104,4 @@ protected function assertMessagesDisplayed() {
$this->assertGreaterThan(4, count($top_form_elements));
}
/**
* Attempts to click an element until it is in a clickable state.
*
* @param \Behat\Mink\Element\NodeElement $element
* The element to click.
* @param int $timeout
* (Optional) Timeout in milliseconds, defaults to 10000.
*
* @todo Replace this method with general solution for random click() test
* failures in https://www.drupal.org/node/3032275.
*/
protected function clickElementWhenClickable(NodeElement $element, $timeout = 10000) {
$page = $this->getSession()->getPage();
$result = $page->waitFor($timeout / 1000, function () use ($element) {
try {
$element->click();
return TRUE;
}
catch (UnknownError $exception) {
if (strstr($exception->getMessage(), 'not clickable') === FALSE) {
// Rethrow any unexpected UnknownError exceptions.
throw $exception;
}
return NULL;
}
});
$this->assertTrue($result);
}
}
Loading