From 3df6e801b59d83cd28cef082a7d5eec64e0c4d45 Mon Sep 17 00:00:00 2001 From: Rajesh Taneja Date: Mon, 28 Nov 2016 07:57:31 +0800 Subject: [PATCH] MDL-57168 behat: Ensure drawer is open before clicking the link --- lib/behat/behat_base.php | 35 +++++++++++++++++++ theme/boost/scss/moodle/debug.scss | 13 +++++++ .../behat_theme_boost_behat_navigation.php | 1 + 3 files changed, 49 insertions(+) diff --git a/lib/behat/behat_base.php b/lib/behat/behat_base.php index afdd4f618a3..04dcb434002 100644 --- a/lib/behat/behat_base.php +++ b/lib/behat/behat_base.php @@ -573,6 +573,41 @@ class behat_base extends Behat\MinkExtension\Context\RawMinkContext { ); } + /** + * Ensures that the provided node has a attribute value set. This step can be used to check if specific + * JS has finished modifying the node. + * + * @throws ExpectationException + * @param NodeElement $node + * @param string $attribute attribute name + * @param string $attributevalue attribute value to check. + * @return void Throws an exception if it times out without the element being visible + */ + protected function ensure_node_attribute_is_set($node, $attribute, $attributevalue) { + + if (!$this->running_javascript()) { + return; + } + + // Exception if it timesout and the element is still there. + $msg = 'The "' . $node->getXPath() . '" xpath node is not visible and it should be visible'; + $exception = new ExpectationException($msg, $this->getSession()); + + // It will stop spinning once the $args[1]) == $args[2], and method returns true. + $this->spin( + function($context, $args) { + if ($args[0]->getAttribute($args[1]) == $args[2]) { + return true; + } + return false; + }, + array($node, $attribute, $attributevalue), + self::EXTENDED_TIMEOUT, + $exception, + true + ); + } + /** * Ensures that the provided element is visible and we can interact with it. * diff --git a/theme/boost/scss/moodle/debug.scss b/theme/boost/scss/moodle/debug.scss index ddf59f9aaae..46abbf14e35 100644 --- a/theme/boost/scss/moodle/debug.scss +++ b/theme/boost/scss/moodle/debug.scss @@ -11,6 +11,19 @@ body.behat-site { .dropdown-item { margin-top: 4px !important; /* stylelint-disable declaration-no-important */ } + + // Remove following after MDL-57172 is fixed. + &.drawer-ease { + -webkit-transition: initial; + -moz-transition: initial; + transition: initial; + } + + [data-region="drawer"] { + -webkit-transition: initial; + -moz-transition: initial; + transition: initial; + } } .phpinfo table, diff --git a/theme/boost/tests/behat/behat_theme_boost_behat_navigation.php b/theme/boost/tests/behat/behat_theme_boost_behat_navigation.php index a9469d1c3a6..2f64866b32f 100644 --- a/theme/boost/tests/behat/behat_theme_boost_behat_navigation.php +++ b/theme/boost/tests/behat/behat_theme_boost_behat_navigation.php @@ -93,6 +93,7 @@ class behat_theme_boost_behat_navigation extends behat_navigation { $expanded = $node->getAttribute('aria-expanded'); if ($expanded === 'false') { $node->click(); + $this->ensure_node_attribute_is_set($node, 'aria-expanded', 'true'); $this->wait_for_pending_js(); } }