trait OffCanvasTestTrait

Same name in other branches
  1. 9 core/modules/system/tests/src/Traits/OffCanvasTestTrait.php \Drupal\Tests\system\Traits\OffCanvasTestTrait
  2. 10 core/modules/system/tests/src/Traits/OffCanvasTestTrait.php \Drupal\Tests\system\Traits\OffCanvasTestTrait

Provides helper methods for interacting with the off-canvas area.

This trait is only useful in functional JavaScript tests which need to use the off-canvas area. Tests using this trait should also list off_canvas_test in their $modules property.

Hierarchy

7 files declare their use of OffCanvasTestTrait
AjaxBlockTest.php in core/modules/layout_builder/tests/src/FunctionalJavascript/AjaxBlockTest.php
ContentPreviewToggleTest.php in core/modules/layout_builder/tests/src/FunctionalJavascript/ContentPreviewToggleTest.php
LayoutBuilderDisableInteractionsTest.php in core/modules/layout_builder/tests/src/FunctionalJavascript/LayoutBuilderDisableInteractionsTest.php
LayoutBuilderTest.php in core/modules/layout_builder/tests/src/FunctionalJavascript/LayoutBuilderTest.php
NavigationBlockUiTest.php in core/modules/navigation/tests/src/FunctionalJavascript/NavigationBlockUiTest.php

... See full list

File

core/modules/system/tests/src/Traits/OffCanvasTestTrait.php, line 14

Namespace

Drupal\Tests\system\Traits
View source
trait OffCanvasTestTrait {
    
    /**
     * Waits for the off-canvas area to appear, resized and visible.
     */
    protected function waitForOffCanvasArea() : void {
        // 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")');
    }

}

Members

Title Sort descending Modifiers Object type Summary
OffCanvasTestTrait::waitForOffCanvasArea protected function Waits for the off-canvas area to appear, resized and visible.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.