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 self::assertTrue(strstr($style, 'width: 555px;') !== FALSE, 'Dialog width respected.');
69 // Check that header is correct.
70 $this->assertEquals("Thing $link_index", $header_text);
71 $web_assert->elementNotExists('css', '.ui-dialog-empty-title');
78 * Tests the body displacement behaves differently at a narrow width.
80 public function testNarrowWidth() {
81 $narrow_width_breakpoint = 768;
84 $page = $this->getSession()->getPage();
85 $web_assert = $this->assertSession();
87 // Test the same functionality on multiple themes.
88 foreach ($this->getTestThemes() as $theme) {
89 $this->enableTheme($theme);
90 // Testing at the wider width.
91 $this->getSession()->resizeWindow($narrow_width_breakpoint + $offset, $height);
92 $this->drupalGet('/off-canvas-test-links');
93 $this->assertFalse($page->find('css', '.dialog-off-canvas__main-canvas')->hasAttribute('style'), 'Body not padded on wide page load.');
94 $page->clickLink("Click Me 1!");
95 $this->waitForOffCanvasToOpen();
96 // Check that the main canvas is padded when page is not narrow width and
98 $web_assert->elementAttributeContains('css', '.dialog-off-canvas__main-canvas', 'style', 'padding-right');
100 // Testing at the narrower width.
101 $this->getSession()->resizeWindow($narrow_width_breakpoint - $offset, $height);
102 $this->drupalGet('/off-canvas-test-links');
103 $this->assertFalse($page->find('css', '.dialog-off-canvas__main-canvas')->hasAttribute('style'), 'Body not padded on narrow page load.');
104 $page->clickLink("Click Me 1!");
105 $this->waitForOffCanvasToOpen();
106 $this->assertFalse($page->find('css', '.dialog-off-canvas__main-canvas')->hasAttribute('style'), 'Body not padded on narrow page with tray open.');
113 protected function getTestThemes() {
114 // Add 'seven' theme. Setting Tray "Edit Mode" will not work with 'seven'
115 // because it removes all contextual links the off-canvas dialog should.
116 return array_merge(parent::getTestThemes(), ['seven']);