Unverified Commit 9a11de65 authored by alexpott's avatar alexpott
Browse files

Issue #2892440 by bnjmnm, tedbow, alexpott, Krzysztof Domański, Lendude:...

Issue #2892440 by bnjmnm, tedbow, alexpott, Krzysztof Domański, Lendude: Provide helper test method to wait for an element to be removed from the page
parent 2be8f419
...@@ -71,7 +71,7 @@ public function testValidationMessage() { ...@@ -71,7 +71,7 @@ public function testValidationMessage() {
$block_css_locator = '#layout-builder .block-system-powered-by-block'; $block_css_locator = '#layout-builder .block-system-powered-by-block';
$this->assertNotEmpty($assert_session->waitForElementVisible('css', $block_css_locator)); $this->assertNotEmpty($assert_session->waitForElementVisible('css', $block_css_locator));
$this->waitForNoElement('#drupal-off-canvas'); $assert_session->assertNoElementAfterWait('css', '#drupal-off-canvas');
$assert_session->assertWaitOnAjaxRequest(); $assert_session->assertWaitOnAjaxRequest();
$this->drupalGet($this->getUrl()); $this->drupalGet($this->getUrl());
$this->clickElementWhenClickable($page->findButton('Save layout')); $this->clickElementWhenClickable($page->findButton('Save layout'));
...@@ -87,21 +87,6 @@ public function testValidationMessage() { ...@@ -87,21 +87,6 @@ public function testValidationMessage() {
$this->assertMessagesDisplayed(); $this->assertMessagesDisplayed();
} }
/**
* Waits for an element to be removed from the page.
*
* @param string $selector
* CSS selector.
* @param int $timeout
* (optional) Timeout in milliseconds, defaults to 10000.
*
* @todo Remove in https://www.drupal.org/node/2892440.
*/
protected function waitForNoElement($selector, $timeout = 10000) {
$condition = "(typeof jQuery !== 'undefined' && jQuery('$selector').length === 0)";
$this->assertJsCondition($condition, $timeout);
}
/** /**
* Asserts that the validation messages are shown correctly. * Asserts that the validation messages are shown correctly.
*/ */
......
...@@ -78,8 +78,7 @@ public function testContentPreviewToggle() { ...@@ -78,8 +78,7 @@ public function testContentPreviewToggle() {
$page->uncheckField('layout-builder-content-preview'); $page->uncheckField('layout-builder-content-preview');
$this->assertNotEmpty($assert_session->waitForElementVisible('css', '.layout-builder-block__content-preview-placeholder-label')); $this->assertNotEmpty($assert_session->waitForElementVisible('css', '.layout-builder-block__content-preview-placeholder-label'));
// Wait for preview content hide() to complete. // Confirm that block content is not on page.
$this->waitForNoElement('[data-layout-content-preview-placeholder-label] .field--name-body:visible');
$assert_session->pageTextNotContains($content_preview_body_text); $assert_session->pageTextNotContains($content_preview_body_text);
$this->assertContextualLinks(); $this->assertContextualLinks();
...@@ -124,7 +123,7 @@ protected function assertContextualLinks() { ...@@ -124,7 +123,7 @@ protected function assertContextualLinks() {
$this->assertSession()->assertWaitOnAjaxRequest(); $this->assertSession()->assertWaitOnAjaxRequest();
$this->assertNotEmpty($this->assertSession()->waitForButton('Close')); $this->assertNotEmpty($this->assertSession()->waitForButton('Close'));
$page->pressButton('Close'); $page->pressButton('Close');
$this->waitForNoElement('#drupal-off-canvas'); $assert_session->assertNoElementAfterWait('css', '#drupal-off-canvas');
} }
/** /**
...@@ -147,19 +146,4 @@ protected function assertOrderInPage(array $items) { ...@@ -147,19 +146,4 @@ protected function assertOrderInPage(array $items) {
$this->assertCount(count($items), $blocks_with_expected_text); $this->assertCount(count($items), $blocks_with_expected_text);
} }
/**
* Waits for an element to be removed from the page.
*
* @param string $selector
* CSS selector.
* @param int $timeout
* (optional) Timeout in milliseconds, defaults to 10000.
*
* @todo Remove in https://www.drupal.org/node/2892440.
*/
protected function waitForNoElement($selector, $timeout = 10000) {
$condition = "(typeof jQuery !== 'undefined' && jQuery('$selector').length === 0)";
$this->assertJsCondition($condition, $timeout);
}
} }
...@@ -110,8 +110,9 @@ protected function addBlock($block_name) { ...@@ -110,8 +110,9 @@ protected function addBlock($block_name) {
$this->assertNotEmpty($assert_session->waitForElementVisible('css', "#drupal-off-canvas a:contains('$block_name')")); $this->assertNotEmpty($assert_session->waitForElementVisible('css', "#drupal-off-canvas a:contains('$block_name')"));
$page->clickLink($block_name); $page->clickLink($block_name);
$this->assertNotEmpty($assert_session->waitForElementVisible('css', '[data-drupal-selector=\'edit-actions-submit\']')); $this->assertNotEmpty($assert_session->waitForElementVisible('css', '[data-drupal-selector=\'edit-actions-submit\']'));
$page->pressButton('Add block'); $page->pressButton('Add block');
$this->waitForNoElement('#drupal-off-canvas'); $assert_session->assertNoElementAfterWait('css', '#drupal-off-canvas');
$assert_session->assertWaitOnAjaxRequest(); $assert_session->assertWaitOnAjaxRequest();
} }
...@@ -148,19 +149,4 @@ protected function assertCorrectContextualLinksInNode() { ...@@ -148,19 +149,4 @@ protected function assertCorrectContextualLinksInNode() {
$this->assertNotEmpty($page->findAll('css', '.layout-content [data-contextual-id]')); $this->assertNotEmpty($page->findAll('css', '.layout-content [data-contextual-id]'));
} }
/**
* Waits for an element to be removed from the page.
*
* @param string $selector
* CSS selector.
* @param int $timeout
* (optional) Timeout in milliseconds, defaults to 10000.
*
* @todo Remove in https://www.drupal.org/node/2892440.
*/
protected function waitForNoElement($selector, $timeout = 10000) {
$condition = "(typeof jQuery !== 'undefined' && jQuery('$selector').length === 0)";
$this->assertJsCondition($condition, $timeout);
}
} }
...@@ -116,8 +116,8 @@ protected function removeInlineBlockFromLayout() { ...@@ -116,8 +116,8 @@ protected function removeInlineBlockFromLayout() {
$assert_session->waitForElement('css', "#drupal-off-canvas input[value='Remove']"); $assert_session->waitForElement('css', "#drupal-off-canvas input[value='Remove']");
$assert_session->assertWaitOnAjaxRequest(); $assert_session->assertWaitOnAjaxRequest();
$page->find('css', '#drupal-off-canvas')->pressButton('Remove'); $page->find('css', '#drupal-off-canvas')->pressButton('Remove');
$this->waitForNoElement('#drupal-off-canvas'); $assert_session->assertNoElementAfterWait('css', '#drupal-off-canvas');
$this->waitForNoElement(static::INLINE_BLOCK_LOCATOR); $assert_session->assertNoElementAfterWait('css', static::INLINE_BLOCK_LOCATOR);
$assert_session->assertWaitOnAjaxRequest(); $assert_session->assertWaitOnAjaxRequest();
$assert_session->pageTextNotContains($block_text); $assert_session->pageTextNotContains($block_text);
} }
...@@ -167,7 +167,7 @@ protected function configureInlineBlock($old_body, $new_body, $block_css_locator ...@@ -167,7 +167,7 @@ protected function configureInlineBlock($old_body, $new_body, $block_css_locator
$this->assertSame($old_body, $textarea->getValue()); $this->assertSame($old_body, $textarea->getValue());
$textarea->setValue($new_body); $textarea->setValue($new_body);
$page->pressButton('Update'); $page->pressButton('Update');
$this->waitForNoElement('#drupal-off-canvas'); $assert_session->assertNoElementAfterWait('css', '#drupal-off-canvas');
$assert_session->assertWaitOnAjaxRequest(); $assert_session->assertWaitOnAjaxRequest();
$this->assertDialogClosedAndTextVisible($new_body); $this->assertDialogClosedAndTextVisible($new_body);
} }
...@@ -180,9 +180,11 @@ protected function configureInlineBlock($old_body, $new_body, $block_css_locator ...@@ -180,9 +180,11 @@ protected function configureInlineBlock($old_body, $new_body, $block_css_locator
* @param int $timeout * @param int $timeout
* (optional) Timeout in milliseconds, defaults to 10000. * (optional) Timeout in milliseconds, defaults to 10000.
* *
* @todo Remove in https://www.drupal.org/node/2892440. * @deprecated in Drupal 8.8.x, will be removed before Drupal 9.0.0. Use
* Drupal\FunctionalJavascriptTests\JSWebAssert::assertNoElementAfterWait()
*/ */
protected function waitForNoElement($selector, $timeout = 10000) { protected function waitForNoElement($selector, $timeout = 10000) {
@trigger_error('::waitForNoElement is deprecated in Drupal 8.8.0 and will be removed before Drupal 9.0.0. Use \Drupal\FunctionalJavascriptTests\JSWebAssert::assertNoElementAfterWait() instead.', E_USER_DEPRECATED);
$condition = "(typeof jQuery !== 'undefined' && jQuery('$selector').length === 0)"; $condition = "(typeof jQuery !== 'undefined' && jQuery('$selector').length === 0)";
$this->assertJsCondition($condition, $timeout); $this->assertJsCondition($condition, $timeout);
} }
...@@ -197,7 +199,7 @@ protected function waitForNoElement($selector, $timeout = 10000) { ...@@ -197,7 +199,7 @@ protected function waitForNoElement($selector, $timeout = 10000) {
*/ */
protected function assertDialogClosedAndTextVisible($text, $css_locator = NULL) { protected function assertDialogClosedAndTextVisible($text, $css_locator = NULL) {
$assert_session = $this->assertSession(); $assert_session = $this->assertSession();
$this->waitForNoElement('#drupal-off-canvas'); $assert_session->assertNoElementAfterWait('css', '#drupal-off-canvas');
$assert_session->assertWaitOnAjaxRequest(); $assert_session->assertWaitOnAjaxRequest();
$assert_session->elementNotExists('css', '#drupal-off-canvas'); $assert_session->elementNotExists('css', '#drupal-off-canvas');
if ($css_locator) { if ($css_locator) {
......
...@@ -3,7 +3,6 @@ ...@@ -3,7 +3,6 @@
namespace Drupal\Tests\layout_builder\FunctionalJavascript; namespace Drupal\Tests\layout_builder\FunctionalJavascript;
use Behat\Mink\Element\NodeElement; use Behat\Mink\Element\NodeElement;
use Behat\Mink\Exception\ElementHtmlException;
use Drupal\block_content\Entity\BlockContent; use Drupal\block_content\Entity\BlockContent;
use Drupal\block_content\Entity\BlockContentType; use Drupal\block_content\Entity\BlockContentType;
use Drupal\Component\Render\FormattableMarkup; use Drupal\Component\Render\FormattableMarkup;
...@@ -206,7 +205,7 @@ protected function assertContextualLinksClickable() { ...@@ -206,7 +205,7 @@ protected function assertContextualLinksClickable() {
$this->clickContextualLink('.block-field-blocknodebundle-with-section-fieldbody [data-contextual-id^="layout_builder_block"]', 'Configure'); $this->clickContextualLink('.block-field-blocknodebundle-with-section-fieldbody [data-contextual-id^="layout_builder_block"]', 'Configure');
$this->assertNotEmpty($assert_session->waitForElementVisible('css', '.ui-dialog-titlebar [title="Close"]')); $this->assertNotEmpty($assert_session->waitForElementVisible('css', '.ui-dialog-titlebar [title="Close"]'));
$page->pressButton('Close'); $page->pressButton('Close');
$this->assertNoElementAfterWait('css', '#drupal-off-canvas'); $assert_session->assertNoElementAfterWait('css', '#drupal-off-canvas');
// Run the steps a second time after closing dialog, which reverses the // Run the steps a second time after closing dialog, which reverses the
// order that behaviors.layoutBuilderDisableInteractiveElements and // order that behaviors.layoutBuilderDisableInteractiveElements and
...@@ -214,7 +213,7 @@ protected function assertContextualLinksClickable() { ...@@ -214,7 +213,7 @@ protected function assertContextualLinksClickable() {
$this->clickContextualLink('.block-field-blocknodebundle-with-section-fieldbody [data-contextual-id^="layout_builder_block"]', 'Configure'); $this->clickContextualLink('.block-field-blocknodebundle-with-section-fieldbody [data-contextual-id^="layout_builder_block"]', 'Configure');
$this->assertNotEmpty($assert_session->waitForElementVisible('css', '#drupal-off-canvas')); $this->assertNotEmpty($assert_session->waitForElementVisible('css', '#drupal-off-canvas'));
$page->pressButton('Close'); $page->pressButton('Close');
$this->assertNoElementAfterWait('css', '#drupal-off-canvas'); $assert_session->assertNoElementAfterWait('css', '#drupal-off-canvas');
$this->assertContextualLinkRetainsMouseup(); $this->assertContextualLinkRetainsMouseup();
} }
...@@ -303,34 +302,4 @@ protected function movePointerTo($selector) { ...@@ -303,34 +302,4 @@ protected function movePointerTo($selector) {
$driver_session->moveto(['element' => $element->getID()]); $driver_session->moveto(['element' => $element->getID()]);
} }
/**
* Asserts that no matching element exists on the page after a wait.
*
* @param string $selector_type
* The element selector type (CSS, XPath).
* @param string|array $selector
* The element selector.
* @param int $timeout
* (optional) Timeout in milliseconds, defaults to 10000.
* @param string $message
* (optional) The exception message.
*
* @throws \Behat\Mink\Exception\ElementHtmlException
* When an element still exists on the page.
*/
public function assertNoElementAfterWait($selector_type, $selector, $timeout = 10000, $message = 'Element exists on the page.') {
$start = microtime(TRUE);
$end = $start + ($timeout / 1000);
$page = $this->getSession()->getPage();
do {
$node = $page->find($selector_type, $selector);
if (empty($node)) {
return;
}
usleep(100000);
} while (microtime(TRUE) < $end);
throw new ElementHtmlException($message, $this->session->getDriver(), $node);
}
} }
...@@ -125,7 +125,7 @@ public function testLayoutBuilderUi() { ...@@ -125,7 +125,7 @@ public function testLayoutBuilderUi() {
// Save the new block, and ensure it is displayed on the page. // Save the new block, and ensure it is displayed on the page.
$page->pressButton('Add block'); $page->pressButton('Add block');
$assert_session->assertWaitOnAjaxRequest(); $assert_session->assertWaitOnAjaxRequest();
$this->assertNoElementAfterWait('#drupal-off-canvas'); $assert_session->assertNoElementAfterWait('css', '#drupal-off-canvas');
$assert_session->addressEquals($layout_url); $assert_session->addressEquals($layout_url);
$assert_session->pageTextContains('Powered by Drupal'); $assert_session->pageTextContains('Powered by Drupal');
$assert_session->pageTextContains('This is the label'); $assert_session->pageTextContains('This is the label');
...@@ -158,7 +158,7 @@ public function testLayoutBuilderUi() { ...@@ -158,7 +158,7 @@ public function testLayoutBuilderUi() {
$page->pressButton('Add section'); $page->pressButton('Add section');
$assert_session->assertWaitOnAjaxRequest(); $assert_session->assertWaitOnAjaxRequest();
$this->assertNoElementAfterWait('.layout__region--second .block-system-powered-by-block'); $assert_session->assertNoElementAfterWait('css', '.layout__region--second .block-system-powered-by-block');
$assert_session->elementTextNotContains('css', '.layout__region--second', 'Powered by Drupal'); $assert_session->elementTextNotContains('css', '.layout__region--second', 'Powered by Drupal');
// Drag the block to a region in different section. // Drag the block to a region in different section.
...@@ -190,7 +190,7 @@ public function testLayoutBuilderUi() { ...@@ -190,7 +190,7 @@ public function testLayoutBuilderUi() {
$page->fillField('settings[label]', 'This is the new label'); $page->fillField('settings[label]', 'This is the new label');
$page->pressButton('Update'); $page->pressButton('Update');
$assert_session->assertWaitOnAjaxRequest(); $assert_session->assertWaitOnAjaxRequest();
$this->assertNoElementAfterWait('#drupal-off-canvas'); $assert_session->assertNoElementAfterWait('css', '#drupal-off-canvas');
$assert_session->addressEquals($layout_url); $assert_session->addressEquals($layout_url);
$assert_session->pageTextContains('Powered by Drupal'); $assert_session->pageTextContains('Powered by Drupal');
...@@ -204,7 +204,7 @@ public function testLayoutBuilderUi() { ...@@ -204,7 +204,7 @@ public function testLayoutBuilderUi() {
$assert_session->pageTextContains('This action cannot be undone.'); $assert_session->pageTextContains('This action cannot be undone.');
$page->pressButton('Remove'); $page->pressButton('Remove');
$assert_session->assertWaitOnAjaxRequest(); $assert_session->assertWaitOnAjaxRequest();
$this->assertNoElementAfterWait('#drupal-off-canvas'); $assert_session->assertNoElementAfterWait('css', '#drupal-off-canvas');
$assert_session->pageTextNotContains('Powered by Drupal'); $assert_session->pageTextNotContains('Powered by Drupal');
$assert_session->linkExists('Add block'); $assert_session->linkExists('Add block');
...@@ -296,7 +296,7 @@ public function testConfigurableLayoutSections() { ...@@ -296,7 +296,7 @@ public function testConfigurableLayoutSections() {
$page->pressButton('Add section'); $page->pressButton('Add section');
$assert_session->assertWaitOnAjaxRequest(); $assert_session->assertWaitOnAjaxRequest();
$this->assertNoElementAfterWait('#drupal-off-canvas'); $assert_session->assertNoElementAfterWait('css', '#drupal-off-canvas');
$assert_session->pageTextContains('Default'); $assert_session->pageTextContains('Default');
$assert_session->linkExists('Add block'); $assert_session->linkExists('Add block');
...@@ -307,7 +307,7 @@ public function testConfigurableLayoutSections() { ...@@ -307,7 +307,7 @@ public function testConfigurableLayoutSections() {
$page->fillField('layout_settings[setting_1]', 'Test setting value'); $page->fillField('layout_settings[setting_1]', 'Test setting value');
$page->pressButton('Update'); $page->pressButton('Update');
$assert_session->assertWaitOnAjaxRequest(); $assert_session->assertWaitOnAjaxRequest();
$this->assertNoElementAfterWait('#drupal-off-canvas'); $assert_session->assertNoElementAfterWait('css', '#drupal-off-canvas');
$assert_session->pageTextContains('Test setting value'); $assert_session->pageTextContains('Test setting value');
$this->assertPageNotReloaded(); $this->assertPageNotReloaded();
} }
...@@ -350,7 +350,7 @@ public function testLayoutNoDialog() { ...@@ -350,7 +350,7 @@ public function testLayoutNoDialog() {
'region' => 'content', 'region' => 'content',
'plugin_id' => 'system_powered_by_block', 'plugin_id' => 'system_powered_by_block',
])); ]));
$this->assertNoElementAfterWait('#drupal-off-canvas'); $assert_session->assertNoElementAfterWait('css', '#drupal-off-canvas');
$page->fillField('settings[label]', 'The block label'); $page->fillField('settings[label]', 'The block label');
$page->fillField('settings[label_display]', TRUE); $page->fillField('settings[label_display]', TRUE);
$page->pressButton('Add block'); $page->pressButton('Add block');
...@@ -372,28 +372,6 @@ public function testLayoutNoDialog() { ...@@ -372,28 +372,6 @@ public function testLayoutNoDialog() {
$assert_session->linkNotExists('Add block'); $assert_session->linkNotExists('Add block');
} }
/**
* Waits for an element to be removed from the page.
*
* @param string $selector
* CSS selector.
* @param int $timeout
* (optional) Timeout in milliseconds, defaults to 10000.
* @param string $message
* (optional) Custom message to display with the assertion.
*
* @todo: Remove after https://www.drupal.org/project/drupal/issues/2892440
*/
public function assertNoElementAfterWait($selector, $timeout = 10000, $message = '') {
$page = $this->getSession()->getPage();
if ($message === '') {
$message = "Element '$selector' was not on the page after wait.";
}
$this->assertTrue($page->waitFor($timeout / 1000, function () use ($page, $selector) {
return empty($page->find('css', $selector));
}), $message);
}
/** /**
* {@inheritdoc} * {@inheritdoc}
* *
......
...@@ -254,23 +254,10 @@ private function assertHighlightedElement($selector) { ...@@ -254,23 +254,10 @@ private function assertHighlightedElement($selector) {
* Waits for the dialog to close and confirms no highlights are present. * Waits for the dialog to close and confirms no highlights are present.
*/ */
private function assertHighlightNotExists() { private function assertHighlightNotExists() {
$this->waitForNoElement('#drupal-off-canvas'); $assert_session = $this->assertSession();
$this->waitForNoElement('.is-layout-builder-highlighted');
}
/** $assert_session->assertNoElementAfterWait('css', '#drupal-off-canvas');
* Waits for an element to be removed from the page. $assert_session->assertNoElementAfterWait('css', '.is-layout-builder-highlighted');
*
* @param string $selector
* CSS selector.
* @param int $timeout
* (optional) Timeout in milliseconds, defaults to 10000.
*
* @todo Remove in https://www.drupal.org/node/2892440.
*/
protected function waitForNoElement($selector, $timeout = 10000) {
$condition = "(typeof jQuery !== 'undefined' && jQuery('$selector').length === 0)";
$this->assertJsCondition($condition, $timeout);
} }
} }
...@@ -83,10 +83,10 @@ protected function setUp() { ...@@ -83,10 +83,10 @@ protected function setUp() {
$this->assertNotEmpty($assert_session->waitForElementVisible('css', 'input[value="Add block"]')); $this->assertNotEmpty($assert_session->waitForElementVisible('css', 'input[value="Add block"]'));
$assert_session->assertWaitOnAjaxRequest(); $assert_session->assertWaitOnAjaxRequest();
$page->pressButton('Add block'); $page->pressButton('Add block');
$assert_session->assertNoElementAfterWait('css', '#drupal-off-canvas');
$this->assertNotEmpty($assert_session->waitForElementVisible('css', $first_region_block_locator)); $this->assertNotEmpty($assert_session->waitForElementVisible('css', $first_region_block_locator));
// Ensure the request has completed before the test starts. // Ensure the request has completed before the test starts.
$this->waitForNoElement('#drupal-off-canvas');
$assert_session->assertWaitOnAjaxRequest(); $assert_session->assertWaitOnAjaxRequest();
} }
...@@ -152,21 +152,6 @@ protected function assertBlockTable(array $expected_block_labels) { ...@@ -152,21 +152,6 @@ protected function assertBlockTable(array $expected_block_labels) {
} }
} }
/**
* Waits for an element to be removed from the page.
*
* @param string $selector
* CSS selector.
* @param int $timeout
* (optional) Timeout in milliseconds, defaults to 10000.
*
* @todo Remove in https://www.drupal.org/node/2892440.
*/
protected function waitForNoElement($selector, $timeout = 10000) {
$condition = "(typeof jQuery !== 'undefined' && jQuery('$selector').length === 0)";
$this->assertJsCondition($condition, $timeout);
}
/** /**
* Moves a block in the draggable table. * Moves a block in the draggable table.
* *
...@@ -221,7 +206,7 @@ protected function assertRegionBlocksOrder($section_delta, $region, array $expec ...@@ -221,7 +206,7 @@ protected function assertRegionBlocksOrder($section_delta, $region, array $expec
$assert_session = $this->assertSession(); $assert_session = $this->assertSession();
$assert_session->assertWaitOnAjaxRequest(); $assert_session->assertWaitOnAjaxRequest();
$this->waitForNoElement('#drupal-off-canvas'); $assert_session->assertNoElementAfterWait('css', '#drupal-off-canvas');
$region_selector = "[data-layout-delta=\"$section_delta\"] [data-region=\"$region\"]"; $region_selector = "[data-layout-delta=\"$section_delta\"] [data-region=\"$region\"]";
......
...@@ -101,25 +101,10 @@ public function testWidthChange() { ...@@ -101,25 +101,10 @@ public function testWidthChange() {
$this->clickLink('Remove section'); $this->clickLink('Remove section');
$this->assertNotEmpty($assert_session->waitForElementVisible('css', '#drupal-off-canvas input[type="submit"][value="Remove"]')); $this->assertNotEmpty($assert_session->waitForElementVisible('css', '#drupal-off-canvas input[type="submit"][value="Remove"]'));
$page->pressButton('Remove'); $page->pressButton('Remove');
$this->waitForNoElement(".$width_class"); $assert_session->assertNoElementAfterWait('css', ".$width_class");
} }
} }
/**
* Waits for an element to be removed from the page.
*
* @param string $selector
* CSS selector.
* @param int $timeout
* (optional) Timeout in milliseconds, defaults to 10000.
*
* @todo Remove in https://www.drupal.org/node/2892440.
*/
protected function waitForNoElement($selector, $timeout = 10000) {
$condition = "(typeof jQuery !== 'undefined' && jQuery('$selector').length === 0)";
$this->assertJsCondition($condition, $timeout);
}
/** /**
* Asserts the width class is applied to the first section. * Asserts the width class is applied to the first section.
* *
......
...@@ -92,22 +92,9 @@ public function testFieldWithCkeditor() { ...@@ -92,22 +92,9 @@ public function testFieldWithCkeditor() {
// Wait and click by "Save" button after body field was changed. // Wait and click by "Save" button after body field was changed.
$this->assertSession()->waitForElementVisible('css', '.quickedit-toolgroup.ops [type="submit"][aria-hidden="false"]')->click(); $this->assertSession()->waitForElementVisible('css', '.quickedit-toolgroup.ops [type="submit"][aria-hidden="false"]')->click();
// Wait until the save occurs and the editor UI disappears. // Wait until the save occurs and the editor UI disappears.
$this->waitForNoElement('.cke_button.cke_button__blockquote'); $this->assertSession()->assertNoElementAfterWait('css', '.cke_button.cke_button__blockquote');
// Ensure that the changes take effect. // Ensure that the changes take effect.
$assert->responseMatches("|<blockquote>\s*$body_value\s*</blockquote>|"); $assert->responseMatches("|<blockquote>\s*$body_value\s*</blockquote>|");
} }
/**
* Waits for an element to be removed from the page.
*
* @param string $selector
* CSS selector.
* @param int $timeout
* (optional) Timeout in milliseconds, defaults to 10000.
*/
protected function waitForNoElement($selector, $timeout = 10000) {
$condition = "(typeof jQuery !== 'undefined' && jQuery('$selector').length === 0)";
$this->assertJsCondition($condition, $timeout);
}
} }
...@@ -79,14 +79,14 @@ protected function doTestBlocks($theme, $block_plugin, $new_page_text, $element_ ...@@ -79,14 +79,14 @@ protected function doTestBlocks($theme, $block_plugin, $new_page_text, $element_
if ($element = $page->find('css', "#toolbar-administration a.is-active")) { if ($element = $page->find('css', "#toolbar-administration a.is-active")) {
// If a tray was open from page load close it. // If a tray was open from page load close it.
$element->click();