From 35fd32ffb4c347f438d886b316d1e2c596230b57 Mon Sep 17 00:00:00 2001 From: Karjun Loong Date: Mon, 5 Aug 2024 14:42:05 +1000 Subject: [PATCH] MDL-82298 navigation: Add behat tests for secondary menu navigation --- lib/tests/behat/behat_navigation.php | 45 +++++++++ .../menu_navigation_single_activity.feature | 78 ++++++++++++++++ .../behat/menu_navigation_topics.feature | 92 +++++++++++++++++++ 3 files changed, 215 insertions(+) create mode 100644 lib/tests/behat/menu_navigation_single_activity.feature create mode 100644 lib/tests/behat/menu_navigation_topics.feature diff --git a/lib/tests/behat/behat_navigation.php b/lib/tests/behat/behat_navigation.php index 4050304a66d..7d52c72e8d8 100644 --- a/lib/tests/behat/behat_navigation.php +++ b/lib/tests/behat/behat_navigation.php @@ -1628,4 +1628,49 @@ class behat_navigation extends behat_base { set_user_preference('behat_keep_drawer_closed', 1); $this->i_close_block_drawer_if_open(); } + + /** + * Checks if a navigation menu item is active. + * + * @Given menu item :navigationmenuitem should be active + * @param string $navigationmenuitem The navigation menu item name. + */ + public function menu_item_should_be_active(string $navigationmenuitem): void { + $elementselector = "//*//a/following-sibling::*//a[contains(text(), '$navigationmenuitem') and @aria-current='true']"; + $params = [$elementselector, "xpath_element"]; + $this->execute("behat_general::should_exist", $params); + } + + /** + * Checks if a navigation menu item is not active + * + * @Given menu item :navigationmenuitem should not be active + * @param string $navigationmenuitem The navigation menu item name. + */ + public function menu_item_should_not_be_active(string $navigationmenuitem): void { + $elementselector = "//*//a/following-sibling::*//a[contains(text(), '$navigationmenuitem') and @aria-current='true']"; + $params = [$elementselector, "xpath_element"]; + $this->execute("behat_general::should_not_exist", $params); + } + + /** + * Sets a link to no longer navigate when selected. + * + * @When I update the link with selector :selector to go nowhere + * @param string $selector selector for link to go nowhere + */ + public function i_update_the_link_to_go_nowhere(string $selector) { + $script = <<getSession()->executeScript($script); + } } diff --git a/lib/tests/behat/menu_navigation_single_activity.feature b/lib/tests/behat/menu_navigation_single_activity.feature new file mode 100644 index 00000000000..4e85ee40692 --- /dev/null +++ b/lib/tests/behat/menu_navigation_single_activity.feature @@ -0,0 +1,78 @@ +@core +Feature: Menu navigation has accurate checkmarks in single activity course format + In order to correctly navigate the menu items + As an admin + I need to see accurate checkmarks besides the menu items I am currently on while in a single activity format course + + Background: + Given the following "users" exist: + | username | firstname | lastname | email | + | teacher1 | T1 | Teacher1 | teacher1@example.com | + | student1 | Student | 1 | student1@example.com | + And the following "courses" exist: + | fullname | shortname | format | activitytype | + | Course 1 | C1 | singleactivity | quiz | + And the following "course enrolments" exist: + | user | course | role | + | teacher1 | C1 | editingteacher | + | student1 | C1 | student | + And the following "activities" exist: + | activity | name | intro | course | idnumber | + | quiz | Quiz 1 | Quiz 1 for testing the Add menu | C1 | quiz1 | + + Scenario: Admin can see checkmark beside menu item they are currently on in a single activity format course + Given I log in as "admin" + And I am on "Course 1" course homepage + When I navigate to "Backup" in current page administration + Then menu item "Backup" should be active + When I navigate to "Permissions" in current page administration + Then menu item "Permissions" should be active + And menu item "Backup" should not be active + + When I navigate to "Participants" in current page administration + Then menu item "Participants" should be active + And menu item "Backup" should not be active + And menu item "Permissions" should not be active + When I navigate to "Grades" in current page administration + Then menu item "Grades" should be active + And menu item "Backup" should not be active + And menu item "Permissions" should not be active + And menu item "Participants" should not be active + + Scenario: Admin can see checkmark beside menu item they are currently on after pressing browser back button in a single + activity format course + Given I log in as "admin" + And I am on "Course 1" course homepage + When I navigate to "Backup" in current page administration + Then menu item "Backup" should be active + When I navigate to "Permissions" in current page administration + Then menu item "Permissions" should be active + And menu item "Backup" should not be active + When I press the "back" button in the browser + Then menu item "Backup" should be active + And menu item "Permissions" should not be active + + Scenario: Admin can see checkmark beside menu item they are currently on after pressing browser back button when + jumping between course and activity menu in a single activity format course + Given I log in as "admin" + And I am on "Course 1" course homepage + When I navigate to "Backup" in current page administration + Then menu item "Backup" should be active + When I navigate to "Participants" in current page administration + Then menu item "Participants" should be active + And menu item "Backup" should not be active + When I press the "back" button in the browser + Then menu item "Backup" should be active + And menu item "Participants" should not be active + + @javascript + Scenario: Admin should not see checkmark if link is not navigated to in current browser for single activity format quiz + Given I log in as "admin" + And I am on "Course 1" course homepage + And I update the link with selector "//*//a/following-sibling::*//a[contains(text(), 'Participants')]" to go nowhere + When I navigate to "Participants" in current page administration + Then menu item "Participants" should not be active + And I update the link with selector "//*//a/following-sibling::*//a[contains(text(), 'Backup')]" to go nowhere + When I click on "//*//a[contains(text(),'Activity')]" "xpath" + And I click on "//*//a/following-sibling::*//a[contains(text(), 'Backup')]" "xpath" + Then menu item "Backup" should not be active diff --git a/lib/tests/behat/menu_navigation_topics.feature b/lib/tests/behat/menu_navigation_topics.feature new file mode 100644 index 00000000000..723ab845cb6 --- /dev/null +++ b/lib/tests/behat/menu_navigation_topics.feature @@ -0,0 +1,92 @@ +@core +Feature: Menu navigation has accurate checkmarks in topic course format + In order to correctly navigate the menu items + As an admin + I need to see accurate checkmarks besides the menu items I am currently on while in topics format + + Background: + Given the following "users" exist: + | username | firstname | lastname | email | + | teacher1 | T1 | Teacher1 | teacher1@example.com | + | student1 | Student | 1 | student1@example.com | + And the following "courses" exist: + | fullname | shortname | category | + | Course 1 | C1 | 0 | + And the following "course enrolments" exist: + | user | course | role | + | teacher1 | C1 | editingteacher | + | student1 | C1 | student | + And the following "activities" exist: + | activity | name | intro | course | idnumber | + | quiz | Quiz 1 | Quiz 1 for testing the Add menu | C1 | quiz1 | + + @javascript + Scenario: Admin can see checkmark beside menu item they are currently on in the quiz page of a topics format course + Given I log in as "admin" + And I am on "Course 1" course homepage + And I follow "Quiz 1" + When I navigate to "Filters" in current page administration + Then menu item "Filters" should be active + When I navigate to "Permissions" in current page administration + Then menu item "Permissions" should be active + And menu item "Filters" should not be active + When I navigate to "Backup" in current page administration + Then menu item "Backup" should be active + And menu item "Filters" should not be active + And menu item "Permissions" should not be active + + @javascript + Scenario: Admin can see checkmark beside menu item they are currently on in the course page of a topics format course + Given I log in as "admin" + And I am on "Course 1" course homepage + When I navigate to "Filters" in current page administration + Then menu item "Filters" should be active + When I navigate to "Course reuse" in current page administration + Then menu item "Course reuse" should be active + And menu item "Filters" should not be active + + @javascript + Scenario: Admin can see checkmark beside menu item they are currently on after pressing browser back button in the + quiz page of a topics format course + Given I log in as "admin" + And I am on "Course 1" course homepage + And I follow "Quiz 1" + When I navigate to "Filters" in current page administration + Then menu item "Filters" should be active + When I navigate to "Permissions" in current page administration + Then menu item "Permissions" should be active + And menu item "Filters" should not be active + When I press the "back" button in the browser + Then menu item "Filters" should be active + And menu item "Permissions" should not be active + + @javascript + Scenario: Admin can see checkmark beside menu item they are currently on after pressing browser back button in the + course page of a topics format course + Given I log in as "admin" + And I am on "Course 1" course homepage + When I navigate to "Filters" in current page administration + Then menu item "Filters" should be active + When I navigate to "Course reuse" in current page administration + Then menu item "Course reuse" should be active + And menu item "Filters" should not be active + When I press the "back" button in the browser + Then menu item "Filters" should be active + And menu item "Course reuse" should not be active + + @javascript + Scenario: Admin should not see checkmark if link is not navigated to in current browser in course view for topics format + Given I log in as "admin" + And I am on "Course 1" course homepage + And I update the link with selector "//*//a/following-sibling::*//a[contains(text(), 'Filters')]" to go nowhere + And I navigate to "Question bank" in current page administration + Then menu item "Filters" should not be active + + @javascript + Scenario: Admin should not see checkmark if link is not navigated to in current browser in quiz view for topics format + Given I log in as "admin" + And I am on "Course 1" course homepage + And I follow "Quiz 1" + And I update the link with selector "//*//a/following-sibling::*//a[contains(text(), 'Backup')]" to go nowhere + And I navigate to "Backup" in current page administration + Then menu item "Backup" should not be active