-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Upgrade: Fix the scrollspy which broke on Moodle 4.3, solves #420.
- Loading branch information
Showing
6 changed files
with
42 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -88,7 +88,7 @@ public function i_scroll_page_to_dom_element_with_id($selector) { | |
$scrolljs = "(function(){ | ||
let element = document.getElementById('$selector'); | ||
let y = element.offsetTop; | ||
document.getElementById('page').scrollTo(0, y); | ||
window.scrollTo(0, y); | ||
})();"; | ||
try { | ||
$this->getSession()->executeScript($scrolljs); | ||
|
@@ -97,6 +97,37 @@ public function i_scroll_page_to_dom_element_with_id($selector) { | |
} | ||
} | ||
|
||
/** | ||
* Make the navbar fixed. | ||
* | ||
* This is not really a real Behat step, but it is necessary for the test of the scrollspy feature in the | ||
* 'Setting: Scrollspy - Enable "Scrollspy"' scenario. | ||
* | ||
* The problem is there: | ||
* 1. The 'I scroll page to DOM element with ID' step scrolls the page down as it is needed for the scenario. | ||
* 2. The 'I turn editing mode on' scrolls the page up again to click the edit button as the navbar is not fixed | ||
* in Behat runs. | ||
* | ||
* Because of this, the scrollspy would save the wrong viewport-y value and the scenario would fail. | ||
* Against this background, we have to make the navbar fixed just before turning editing on. | ||
* And that's what this step is here for. | ||
* | ||
* @copyright 2023 Alexander Bias <[email protected]> | ||
* @Then I make the navbar fixed | ||
* @return void | ||
* @throws Exception | ||
*/ | ||
public function i_make_the_navbar_fixed() { | ||
$fixedjs = "(function(){ | ||
document.querySelector('nav.navbar').style.position = 'fixed'; | ||
})();"; | ||
try { | ||
$this->getSession()->executeScript($fixedjs); | ||
} catch (Exception $e) { | ||
throw new \Exception('Making the navbar fixed failed'); | ||
} | ||
} | ||
|
||
/** | ||
* Checks if the top of the page is at the top of the viewport. | ||
* | ||
|
@@ -107,7 +138,7 @@ public function i_scroll_page_to_dom_element_with_id($selector) { | |
public function page_top_is_at_top_of_viewport() { | ||
$posviewportjs = " | ||
return ( | ||
document.getElementById('page').scrollTop | ||
window.scrollY | ||
) | ||
"; | ||
$positionviewport = $this->evaluate_script($posviewportjs); | ||
|
@@ -126,7 +157,7 @@ public function page_top_is_at_top_of_viewport() { | |
public function page_top_is_not_at_top_of_viewport() { | ||
$posviewportjs = " | ||
return ( | ||
document.getElementById('page').scrollTop | ||
window.scrollY | ||
) | ||
"; | ||
$positionviewport = $this->evaluate_script($posviewportjs); | ||
|
@@ -152,7 +183,7 @@ public function dom_element_is_at_top_of_viewport($selector) { | |
$positionelement = $this->evaluate_script($poselementjs); | ||
$posviewportjs = " | ||
return ( | ||
document.getElementById('page').scrollTop | ||
window.scrollY | ||
) | ||
"; | ||
$positionviewport = $this->evaluate_script($posviewportjs); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters