3 namespace Drupal\Tests\outside_in\FunctionalJavascript;
6 * Tests the off-canvas dialog functionality.
10 class OffCanvasTest extends OutsideInJavascriptTestBase {
15 public static $modules = [
24 * Tests that non-contextual links will work with the off-canvas dialog.
26 public function testOffCanvasLinks() {
27 // Test the same functionality on multiple themes.
28 foreach ($this->getTestThemes() as $theme) {
29 $this->enableTheme($theme);
30 $this->drupalGet('/off-canvas-test-links');
32 $page = $this->getSession()->getPage();
33 $web_assert = $this->assertSession();
35 // Make sure off-canvas dialog is on page when first loaded.
36 $web_assert->elementNotExists('css', '#drupal-off-canvas');
38 // Check opening and closing with two separate links.
39 // Make sure tray updates to new content.
40 // Check the first link again to make sure the empty title class is
42 foreach (['1', '2', '1'] as $link_index) {
43 // Click the first test like that should open the page.
44 $page->clickLink("Click Me $link_index!");
45 $this->waitForOffCanvasToOpen();
47 // Check that the canvas is not on the page.
48 $web_assert->elementExists('css', '#drupal-off-canvas');
49 // Check that response text is on page.
50 $web_assert->pageTextContains("Thing $link_index says hello");
51 $off_canvas_tray = $this->getTray();
53 // Check that tray is visible.
54 $this->assertEquals(TRUE, $off_canvas_tray->isVisible());
55 $header_text = $off_canvas_tray->find('css', '.ui-dialog-title')->getText();
57 $tray_text = $off_canvas_tray->findById('drupal-off-canvas')->getText();
58 $this->assertEquals("Thing $link_index says hello", $tray_text);
60 if ($link_index == '2') {
61 // Check no title behavior.
62 $web_assert->elementExists('css', '.ui-dialog-empty-title');
63 $this->assertEquals('', $header_text);
65 $style = $page->find('css', '.ui-dialog-off-canvas')->getAttribute('style');
66 $this->assertTrue(strstr($style, 'width: 555px;') !== FALSE, 'Dialog width respected.');
67 $page->clickLink("Click Me 1!");
68 $this->waitForOffCanvasToOpen();
69 $style = $page->find('css', '.ui-dialog-off-canvas')->getAttribute('style');
70 $this->assertTrue(strstr($style, 'width: 555px;') === FALSE, 'Dialog width reset to default.');
73 // Check that header is correct.
74 $this->assertEquals("Thing $link_index", $header_text);
75 $web_assert->elementNotExists('css', '.ui-dialog-empty-title');
82 * Tests the body displacement behaves differently at a narrow width.
84 public function testNarrowWidth() {
85 $narrow_width_breakpoint = 768;
88 $page = $this->getSession()->getPage();
89 $web_assert = $this->assertSession();
91 // Test the same functionality on multiple themes.
92 foreach ($this->getTestThemes() as $theme) {
93 $this->enableTheme($theme);
94 // Testing at the wider width.
95 $this->getSession()->resizeWindow($narrow_width_breakpoint + $offset, $height);
96 $this->drupalGet('/off-canvas-test-links');
97 $this->assertFalse($page->find('css', '.dialog-off-canvas__main-canvas')->hasAttribute('style'), 'Body not padded on wide page load.');
98 $page->clickLink("Click Me 1!");
99 $this->waitForOffCanvasToOpen();
100 // Check that the main canvas is padded when page is not narrow width and
102 $web_assert->elementAttributeContains('css', '.dialog-off-canvas__main-canvas', 'style', 'padding-right');
104 // Testing at the narrower width.
105 $this->getSession()->resizeWindow($narrow_width_breakpoint - $offset, $height);
106 $this->drupalGet('/off-canvas-test-links');
107 $this->assertFalse($page->find('css', '.dialog-off-canvas__main-canvas')->hasAttribute('style'), 'Body not padded on narrow page load.');
108 $page->clickLink("Click Me 1!");
109 $this->waitForOffCanvasToOpen();
110 $this->assertFalse($page->find('css', '.dialog-off-canvas__main-canvas')->hasAttribute('style'), 'Body not padded on narrow page with tray open.');
117 protected function getTestThemes() {
118 // Add 'seven' theme. Setting Tray "Edit Mode" will not work with 'seven'
119 // because it removes all contextual links the off-canvas dialog should.
120 return array_merge(parent::getTestThemes(), ['seven']);