diff --git a/tests/behat/behat_theme_ucsf_base_general.php b/tests/behat/behat_theme_ucsf_base_general.php new file mode 100644 index 0000000..110b090 --- /dev/null +++ b/tests/behat/behat_theme_ucsf_base_general.php @@ -0,0 +1,72 @@ +. + +/** + * Theme UCSF - General custom Behat rules + * + * @package theme_ucsf + * @copyright The Regents of the University of California + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +require_once(__DIR__.'/../../../../lib/behat/behat_base.php'); + + +/** + * Class behat_theme_ucsf_base_general + * + * @package theme_ucsf + * @copyright The Regents of the University of California + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class behat_theme_ucsf_base_general extends behat_base { + + /** + * Resets the theme cache. + * @Given /^the theme cache has been reset$/ + */ + public function theme_reset_all_caches() { + theme_reset_all_caches(); + } + + /** + * Purges theme cache and reloads the theme + * @copyright 2022 Alexander Bias, lern.link GmbH + * @see https://github.com/moodle-an-hochschulen/moodle-theme_boost_union + * @Given /^the theme cache is purged and the theme is reloaded$/ + */ + public function purge_theme_cache_and_reload_theme() { + theme_reset_all_caches(); + } + + /** + * Scroll the page to a given coordinate. + * + * @copyright 2016 Shweta Sharma on https://stackoverflow.com/a/39613869. + * @Then /^I scroll page to x "(?P\d+)" y "(?P\d+)"$/ + * @param string $posx The x coordinate to scroll to. + * @param string $posy The y coordinate to scroll to. + * @return void + * @throws Exception + */ + public function i_scroll_page_to_x_y_coordinates_of_page($posx, $posy) { + try { + $this->getSession()->executeScript("(function(){window.scrollTo($posx, $posy);})();"); + } catch (Exception) { + throw new Exception("Scrolling the page to given coordinates failed"); + } + } +} diff --git a/tests/behat/theme_ucsf_backtotop.feature b/tests/behat/theme_ucsf_backtotop.feature new file mode 100644 index 0000000..f7a67e9 --- /dev/null +++ b/tests/behat/theme_ucsf_backtotop.feature @@ -0,0 +1,27 @@ +@theme @theme_ucsf @theme_ucsf_backtotop +Feature: Back-to-top button + Background: + Given the following "users" exist: + | username | + | student1 | + And the following "courses" exist: + | fullname | shortname | + | Course 1 | C1 | + And the following "course enrolments" exist: + | user | course | role | + | student1 | C1 | student | + + @javascript + Scenario: Back-to-top button - is visible and works + Given the theme cache is purged and the theme is reloaded + When I log in as "student1" + And I am on "Course 1" course homepage + Then "#back-to-top" "css_element" should exist + And "#page-footer" "css_element" should appear before "#back-to-top" "css_element" + And "#back-to-top" "css_element" should not be visible + And I scroll page to x "0" y "250" + And "#back-to-top" "css_element" should be visible + And I click on "#back-to-top" "css_element" + # Then I wait 1 second as the scroll up process is animated + And I wait "1" seconds + And "#back-to-top" "css_element" should not be visible