From 24472eef5d95770bf5f55ed0d766ace102cbb001 Mon Sep 17 00:00:00 2001 From: Alex Pott Date: Tue, 29 Mar 2022 11:23:43 +0100 Subject: [PATCH] Issue #3268680 by phenaproxima, xjm, Spokje, ravi.shankar, bnjmmn: [random test failure] Restore and fix LayoutBuilderDisableInteractionsTest::testFormsLinksDisabled() --- .../LayoutBuilderDisableInteractionsTest.php | 9 +++++++- .../off_canvas_test/js/resize-helper.es6.js | 18 +++++++++++++++ .../off_canvas_test/js/resize-helper.js | 16 +++++++++++++ .../off_canvas_test.libraries.yml | 5 ++++ .../off_canvas_test/off_canvas_test.module | 18 +++++++++++++++ .../tests/src/Traits/OffCanvasTestTrait.php | 23 +++++++++++++++++++ 6 files changed, 88 insertions(+), 1 deletion(-) create mode 100644 core/modules/system/tests/modules/off_canvas_test/js/resize-helper.es6.js create mode 100644 core/modules/system/tests/modules/off_canvas_test/js/resize-helper.js create mode 100644 core/modules/system/tests/modules/off_canvas_test/off_canvas_test.libraries.yml create mode 100644 core/modules/system/tests/modules/off_canvas_test/off_canvas_test.module create mode 100644 core/modules/system/tests/src/Traits/OffCanvasTestTrait.php diff --git a/core/modules/layout_builder/tests/src/FunctionalJavascript/LayoutBuilderDisableInteractionsTest.php b/core/modules/layout_builder/tests/src/FunctionalJavascript/LayoutBuilderDisableInteractionsTest.php index 129c1ea4cdf..6ce658324b8 100644 --- a/core/modules/layout_builder/tests/src/FunctionalJavascript/LayoutBuilderDisableInteractionsTest.php +++ b/core/modules/layout_builder/tests/src/FunctionalJavascript/LayoutBuilderDisableInteractionsTest.php @@ -9,6 +9,7 @@ use Drupal\Component\Render\FormattableMarkup; use Drupal\FunctionalJavascriptTests\JSWebAssert; use Drupal\FunctionalJavascriptTests\WebDriverTestBase; use Drupal\Tests\contextual\FunctionalJavascript\ContextualLinkClickTrait; +use Drupal\Tests\system\Traits\OffCanvasTestTrait; /** * Tests the Layout Builder disables interactions of rendered blocks. @@ -18,6 +19,7 @@ use Drupal\Tests\contextual\FunctionalJavascript\ContextualLinkClickTrait; class LayoutBuilderDisableInteractionsTest extends WebDriverTestBase { use ContextualLinkClickTrait; + use OffCanvasTestTrait; /** * {@inheritdoc} @@ -31,6 +33,7 @@ class LayoutBuilderDisableInteractionsTest extends WebDriverTestBase { 'node', 'search', 'contextual', + 'off_canvas_test', ]; /** @@ -88,7 +91,6 @@ class LayoutBuilderDisableInteractionsTest extends WebDriverTestBase { * Tests that forms and links are disabled in the Layout Builder preview. */ public function testFormsLinksDisabled() { - $this->markTestSkipped(); // Resize window due to bug in Chromedriver when clicking on overlays over // iFrames. // @see https://bugs.chromium.org/p/chromedriver/issues/detail?id=2758 @@ -219,6 +221,11 @@ class LayoutBuilderDisableInteractionsTest extends WebDriverTestBase { $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"]')); + // We explicitly wait for the off-canvas area to be fully resized before + // trying to press the Close button, instead of waiting for the Close button + // itself to become visible. This is to prevent a regularly occurring random + // test failure. + $this->waitForOffCanvasArea(); $page->pressButton('Close'); $assert_session->assertNoElementAfterWait('css', '#drupal-off-canvas'); diff --git a/core/modules/system/tests/modules/off_canvas_test/js/resize-helper.es6.js b/core/modules/system/tests/modules/off_canvas_test/js/resize-helper.es6.js new file mode 100644 index 00000000000..c7dd3de9bf5 --- /dev/null +++ b/core/modules/system/tests/modules/off_canvas_test/js/resize-helper.es6.js @@ -0,0 +1,18 @@ +(function ({ offCanvas }) { + const originalResetSize = offCanvas.resetSize; + + /** + * Wraps the Drupal.offCanvas.resetSize() method. + * + * @param {jQuery.Event} event + * The event triggered. + * @param {object} event.data + * Data attached to the event. + */ + offCanvas.resetSize = (event) => { + originalResetSize(event); + // Set an attribute so that tests can reliably detect when the off-canvas + // area has been resized. + event.data.$element.attr('data-resize-done', 'true'); + }; +})(Drupal); diff --git a/core/modules/system/tests/modules/off_canvas_test/js/resize-helper.js b/core/modules/system/tests/modules/off_canvas_test/js/resize-helper.js new file mode 100644 index 00000000000..ee367765651 --- /dev/null +++ b/core/modules/system/tests/modules/off_canvas_test/js/resize-helper.js @@ -0,0 +1,16 @@ +/** +* DO NOT EDIT THIS FILE. +* See the following change record for more information, +* https://www.drupal.org/node/2815083 +* @preserve +**/ + +(function (_ref) { + var offCanvas = _ref.offCanvas; + var originalResetSize = offCanvas.resetSize; + + offCanvas.resetSize = function (event) { + originalResetSize(event); + event.data.$element.attr('data-resize-done', 'true'); + }; +})(Drupal); \ No newline at end of file diff --git a/core/modules/system/tests/modules/off_canvas_test/off_canvas_test.libraries.yml b/core/modules/system/tests/modules/off_canvas_test/off_canvas_test.libraries.yml new file mode 100644 index 00000000000..6d653dacd7c --- /dev/null +++ b/core/modules/system/tests/modules/off_canvas_test/off_canvas_test.libraries.yml @@ -0,0 +1,5 @@ +resize_helper: + js: + js/resize-helper.js: {} + dependencies: + - 'core/drupal.dialog.off_canvas' diff --git a/core/modules/system/tests/modules/off_canvas_test/off_canvas_test.module b/core/modules/system/tests/modules/off_canvas_test/off_canvas_test.module new file mode 100644 index 00000000000..3c3384d8adf --- /dev/null +++ b/core/modules/system/tests/modules/off_canvas_test/off_canvas_test.module @@ -0,0 +1,18 @@ +assertNotEmpty($this->assertSession()->waitForElementVisible('css', '[data-resize-done="true"]')); + } + +}