diff --git a/core/modules/layout_builder/tests/src/FunctionalJavascript/LayoutBuilderTest.php b/core/modules/layout_builder/tests/src/FunctionalJavascript/LayoutBuilderTest.php index f98f80fb23f..fe995ec24b0 100644 --- a/core/modules/layout_builder/tests/src/FunctionalJavascript/LayoutBuilderTest.php +++ b/core/modules/layout_builder/tests/src/FunctionalJavascript/LayoutBuilderTest.php @@ -7,6 +7,7 @@ use Drupal\block_content\Entity\BlockContentType; use Drupal\Core\Url; use Drupal\FunctionalJavascriptTests\WebDriverTestBase; use Drupal\Tests\contextual\FunctionalJavascript\ContextualLinkClickTrait; +use Drupal\Tests\system\Traits\OffCanvasTestTrait; /** * Tests the Layout Builder UI. @@ -17,6 +18,7 @@ class LayoutBuilderTest extends WebDriverTestBase { use ContextualLinkClickTrait; use LayoutBuilderSortTrait; + use OffCanvasTestTrait; /** * {@inheritdoc} @@ -27,6 +29,7 @@ class LayoutBuilderTest extends WebDriverTestBase { 'layout_builder', 'layout_test', 'node', + 'off_canvas_test', ]; /** @@ -285,17 +288,19 @@ class LayoutBuilderTest extends WebDriverTestBase { $assert_session->linkExists('Add section'); $this->clickLink('Add section'); $assert_session->assertWaitOnAjaxRequest(); - $assert_session->elementExists('css', '#drupal-off-canvas'); + $this->waitForOffCanvasArea(); $assert_session->linkExists('One column'); $this->clickLink('One column'); $assert_session->assertWaitOnAjaxRequest(); + $this->waitForOffCanvasArea(); // Add another section. $assert_session->linkExists('Add section'); $this->clickLink('Add section'); + + $this->waitForOffCanvasArea(); $assert_session->waitForElementVisible('named', ['link', 'Layout plugin (with settings)']); - $assert_session->elementExists('css', '#drupal-off-canvas'); $assert_session->linkExists('Layout plugin (with settings)'); $this->clickLink('Layout plugin (with settings)'); @@ -310,9 +315,10 @@ class LayoutBuilderTest extends WebDriverTestBase { // Ensure validation error is displayed for ConfigureSectionForm. $assert_session->linkExists('Add section'); $this->clickLink('Add section'); + $this->waitForOffCanvasArea(); + $assert_session->waitForElementVisible('named', ['link', 'Layout plugin (with settings)']); $this->clickLink('Layout plugin (with settings)'); - $this->markTestSkipped('Temporarily skipped due to random failures.'); $this->assertOffCanvasFormAfterWait('layout_builder_configure_section'); $page->fillField('layout_settings[setting_1]', 'Test Validation Error Message'); $page->pressButton('Add section'); @@ -481,7 +487,8 @@ class LayoutBuilderTest extends WebDriverTestBase { */ private function assertOffCanvasFormAfterWait(string $expected_form_id): void { $this->assertSession()->assertWaitOnAjaxRequest(); - $off_canvas = $this->assertSession()->waitForElementVisible('css', '#drupal-off-canvas'); + $this->waitForOffCanvasArea(); + $off_canvas = $this->assertSession()->elementExists('css', '#drupal-off-canvas'); $this->assertNotNull($off_canvas); $form_id_element = $off_canvas->find('hidden_field_selector', ['hidden_field', 'form_id']); // Ensure the form ID has the correct value and that the form is visible. diff --git a/core/modules/system/tests/src/Traits/OffCanvasTestTrait.php b/core/modules/system/tests/src/Traits/OffCanvasTestTrait.php index 80e226dee22..a406c6f44ae 100644 --- a/core/modules/system/tests/src/Traits/OffCanvasTestTrait.php +++ b/core/modules/system/tests/src/Traits/OffCanvasTestTrait.php @@ -18,6 +18,11 @@ trait OffCanvasTestTrait { // The data-resize-done attribute is added by the off_canvas_test module's // wrapper around Drupal.offCanvas.resetSize. $this->assertNotEmpty($this->assertSession()->waitForElementVisible('css', '[data-resize-done="true"]')); + + // Remove the data-resize-done attribute so in scenarios where off-canvas + // opens yet another off-canvas, waitForOffCanvasArea() is looking for the + // attribute on a new dialog, not an existing one. + $this->getSession()->executeScript('document.querySelector("[data-resize-done]").removeAttribute("data-resize-done")'); } }