diff --git a/core/modules/outside_in/tests/src/FunctionalJavascript/OffCanvasTest.php b/core/modules/outside_in/tests/src/FunctionalJavascript/OffCanvasTest.php new file mode 100644 index 0000000..52ebaaf --- /dev/null +++ b/core/modules/outside_in/tests/src/FunctionalJavascript/OffCanvasTest.php @@ -0,0 +1,83 @@ +install([$theme]); + $theme_config = \Drupal::configFactory()->getEditable('system.theme'); + $theme_config->set('default', $theme); + $theme_config->save(); + //$this->placeBlock('offcanvas_links_block', ['id' => 'offcanvaslinks']); + $this->drupalGet('/offcanvas-test-links'); + + $page = $this->getSession()->getPage(); + + $this->htmlOutput($page->getContent()); + $web_assert = $this->assertSession(); + + // Make sure off-canvas tray is on page when first loaded. + $web_assert->elementNotExists('css', '#offcanvas'); + + // Check opening and closing with two separate links. + // Make sure tray updates to new content. + foreach (['1', '2'] as $link_index) { + // Click the first test like that should open the page. + $page->clickLink("Click Me $link_index!"); + $web_assert->assertWaitOnAjaxRequest(); + // Wait for off-canvas element to appear. + $condition = "(jQuery('#offcanvas').length > 0)"; + $this->assertJsCondition($condition, 5000); + + // Check that the canvas is not on the page. + $web_assert->elementExists('css', '#offcanvas'); + // Check that response text is on page. + $web_assert->pageTextContains("Thing $link_index says hello"); + $offcanvas_tray = $page->findById('offcanvas'); + + // Check that tray is visible. + $this->assertEquals(TRUE,$offcanvas_tray->isVisible()); + $header_text = $offcanvas_tray->findById('offcanvas-header')->getText(); + + // Check that header is correct. + $this->assertEquals("Thing $link_index", $header_text); + $tray_text = $offcanvas_tray->find('css', '.content')->getText(); + $this->assertEquals("Thing $link_index says hello", $tray_text); + + // Close the tray. + // @todo Should the close have an id? + $offcanvas_tray->find('css', '.offcanvasClose')->press(); + // Wait for animation to be done. + $web_assert->assertWaitOnAjaxRequest(); + // Make sure canvas doesn't exist after closing. + $web_assert->elementNotExists('css', '#offcanvas'); + } + + $this->verbose('Test theme: ' . $theme); + } + } + +}