From f05c1013de6cb72cd4c397fa0bc6ed20f096faf0 Mon Sep 17 00:00:00 2001 From: Ryan Wyllie Date: Fri, 14 Oct 2016 00:30:13 +0000 Subject: [PATCH] MDL-55926 message: add behat tests for message ui --- lib/behat/classes/partial_named_selector.php | 14 +++++++ message/tests/behat/behat_message.php | 37 +++++++++++++++---- .../tests/behat/delete_all_messages.feature | 27 ++++++++++++++ message/tests/behat/delete_messages.feature | 31 ++++++++++++++++ message/tests/behat/manage_contacts.feature | 34 +++++++++++++++++ message/tests/behat/reply_message.feature | 22 +++++++++++ message/tests/behat/search_messages.feature | 31 ++++++++++++++++ message/tests/behat/search_users.feature | 36 ++++++++++++++++++ message/tests/behat/view_messages.feature | 23 ++++++++++++ user/tests/behat/view_full_profile.feature | 6 +-- 10 files changed, 251 insertions(+), 10 deletions(-) create mode 100644 message/tests/behat/delete_all_messages.feature create mode 100644 message/tests/behat/delete_messages.feature create mode 100644 message/tests/behat/manage_contacts.feature create mode 100644 message/tests/behat/reply_message.feature create mode 100644 message/tests/behat/search_messages.feature create mode 100644 message/tests/behat/search_users.feature create mode 100644 message/tests/behat/view_messages.feature diff --git a/lib/behat/classes/partial_named_selector.php b/lib/behat/classes/partial_named_selector.php index 3a91bec812e..538e3fc75ef 100644 --- a/lib/behat/classes/partial_named_selector.php +++ b/lib/behat/classes/partial_named_selector.php @@ -59,6 +59,8 @@ class behat_partial_named_selector extends \Behat\Mink\Selector\PartialNamedSele 'dialogue' => 'dialogue', 'fieldset' => 'fieldset', 'list_item' => 'list_item', + 'message_area_region' => 'message_area_region', + 'message_area_region_content' => 'message_area_region_content', 'question' => 'question', 'region' => 'region', 'section' => 'section', @@ -85,6 +87,9 @@ class behat_partial_named_selector extends \Behat\Mink\Selector\PartialNamedSele 'link' => 'link', 'link_or_button' => 'link_or_button', 'list_item' => 'list_item', + 'message_area_action' => 'message_area_action', + 'message_area_region' => 'message_area_region', + 'message_area_region_content' => 'message_area_region_content', 'optgroup' => 'optgroup', 'option' => 'option', 'question' => 'question', @@ -152,6 +157,15 @@ XPATH XPATH , 'form_row' => << << << <<(?:[^"]|\\")*)" user$/ + * @Given /^I view the "(?P(?:[^"]|\\")*)" contact in the message area$/ * @param string $userfullname */ - public function i_view_users_message_profile($userfullname) { + public function i_view_contact_in_messages($userfullname) { // Visit home page and follow messages. $this->execute("behat_general::i_am_on_homepage"); $this->execute("behat_navigation::i_follow_in_the_user_menu", get_string('messages', 'message')); - $this->execute('behat_general::i_click_on', array("[data-action='contacts-view']", 'css_element')); + $this->execute('behat_general::i_click_on', array("contacts-view", 'message_area_action')); $this->execute('behat_general::wait_until_the_page_is_ready'); @@ -59,8 +59,17 @@ class behat_message extends behat_base { $this->execute('behat_general::wait_until_the_page_is_ready'); - $this->execute('behat_general::i_click_on', array("//div[@data-action='view-contact-profile'] - [./div[contains(normalize-space(.), '" . $this->escape($userfullname) . "')]]", 'xpath_element')); + // Need to limit the click to the search results because the 'view-contact-profile' elements + // can occur in two separate divs on the page. + $this->execute('behat_general::i_click_on_in_the', + array( + "//div[@data-action='view-contact-profile'] + [./div[contains(normalize-space(.), '" . $this->escape($userfullname) . "')]]", + 'xpath_element', + "[data-region='messaging-area'] [data-region='search-results-area']", + "css_element", + ) + ); $this->execute('behat_general::wait_until_the_page_is_ready'); } @@ -73,7 +82,7 @@ class behat_message extends behat_base { * @param string $userfullname */ public function i_send_message_to_user($messagecontent, $userfullname) { - $this->i_view_users_message_profile($userfullname); + $this->i_view_contact_in_messages($userfullname); $this->execute("behat_general::i_click_on", array("[data-action='profile-send-message']", 'css_element')); @@ -85,4 +94,18 @@ class behat_message extends behat_base { $this->execute("behat_forms::press_button", get_string('send', 'message')); } + + /** + * Select messages from a user in the messaging ui. + * + * @Given /^I send "(?P(?:[^"]|\\")*)" message in the message area$/ + * @param string $messagecontent + */ + public function i_send_message_in_the_message_area($messagecontent) { + $this->execute('behat_forms::i_set_the_field_with_xpath_to', + array("//textarea[@data-region='send-message-txt']", $this->escape($messagecontent)) + ); + + $this->execute("behat_forms::press_button", get_string('send', 'message')); + } } diff --git a/message/tests/behat/delete_all_messages.feature b/message/tests/behat/delete_all_messages.feature new file mode 100644 index 00000000000..ebfbef7761b --- /dev/null +++ b/message/tests/behat/delete_all_messages.feature @@ -0,0 +1,27 @@ +@core @message @javascript +Feature: Delete all messages + In order to communicate with fellow users + As a user + I need to be able to delete all messages + + Scenario: Delete all messages + Given the following "users" exist: + | username | firstname | lastname | email | + | user1 | User | 1 | user1@example.com | + | user2 | User | 2 | user2@example.com | + And I log in as "user2" + And I send "User 2 to User 1 message 1" message to "User 1" user + And I send "User 2 to User 1 message 2" message in the message area + And I send "User 2 to User 1 message 3" message in the message area + And I log out + When I log in as "user1" + And I follow "Messages" in the user menu + And I click on "start-delete-messages" "message_area_action" + And I click on "Delete all" "button" + # Confirm dialogue. + And I click on "Yes" "button" + # Confirm the interface is immediately updated. + Then I should not see "User 2" in the "conversations" "message_area_region_content" + # Confirm the changes are persisted. + And I reload the page + And I should not see "User 2" in the "conversations" "message_area_region_content" diff --git a/message/tests/behat/delete_messages.feature b/message/tests/behat/delete_messages.feature new file mode 100644 index 00000000000..600eb435b6d --- /dev/null +++ b/message/tests/behat/delete_messages.feature @@ -0,0 +1,31 @@ +@core @message @javascript +Feature: Delete messages + In order to communicate with fellow users + As a user + I need to be able to delete messages + + Scenario: Delete messages + Given the following "users" exist: + | username | firstname | lastname | email | + | user1 | User | 1 | user1@example.com | + | user2 | User | 2 | user2@example.com | + And I log in as "user2" + And I send "User 2 to User 1 message 1" message to "User 1" user + And I send "User 2 to User 1 message 2" message in the message area + And I send "User 2 to User 1 message 3" message in the message area + And I log out + When I log in as "user1" + And I follow "Messages" in the user menu + And I click on "start-delete-messages" "message_area_action" + And I click on "User 2 to User 1 message 1" "text" in the "messages" "message_area_region" + And I click on "User 2 to User 1 message 2" "text" in the "messages" "message_area_region" + And I click on "Delete selected messages" "button" + # Confirm the interface is immediately updated. + Then I should see "User 2 to User 1 message 3" in the "messages" "message_area_region" + And I should not see "User 2 to User 1 message 2" in the "messages" "message_area_region" + And I should not see "User 2 to User 1 message 1" in the "messages" "message_area_region" + # Confirm that the changes are persisted. + And I reload the page + And I should see "User 2 to User 1 message 3" in the "messages" "message_area_region" + And I should not see "User 2 to User 1 message 2" in the "messages" "message_area_region" + And I should not see "User 2 to User 1 message 1" in the "messages" "message_area_region" diff --git a/message/tests/behat/manage_contacts.feature b/message/tests/behat/manage_contacts.feature new file mode 100644 index 00000000000..3a3efed137c --- /dev/null +++ b/message/tests/behat/manage_contacts.feature @@ -0,0 +1,34 @@ +@core @message @javascript +Feature: Search users + In order to communicate with fellow users + As a user + I need to be able to add and remove them from my contacts + + Background: + Given the following "users" exist: + | username | firstname | lastname | email | + | user1 | User | 1 | user1@example.com | + | user2 | User | 2 | user2@example.com | + | user3 | User | 3 | user3@example.com | + And I log in as "user1" + And I view the "User 2" contact in the message area + And I click on "Add contact" "link" + And I view the "User 3" contact in the message area + And I click on "Add contact" "link" + And I log out + + Scenario: Add contact shows in contacts tab + When I log in as "user1" + And I follow "Messages" in the user menu + And I click on "contacts-view" "message_area_action" + Then I should see "User 2" in the "contacts" "message_area_region_content" + And I should see "User 3" in the "contacts" "message_area_region_content" + + Scenario: Remove contact + When I log in as "user1" + And I view the "User 3" contact in the message area + And I click on "Remove contact" "link" + And I reload the page + And I click on "contacts-view" "message_area_action" + Then I should see "User 2" in the "contacts" "message_area_region_content" + And I should not see "User 3" in the "contacts" "message_area_region_content" diff --git a/message/tests/behat/reply_message.feature b/message/tests/behat/reply_message.feature new file mode 100644 index 00000000000..d6eb761cbeb --- /dev/null +++ b/message/tests/behat/reply_message.feature @@ -0,0 +1,22 @@ +@core @message @javascript +Feature: Reply message + In order to communicate with fellow users + As a user + I need to be able to reply to a message + + Scenario: Reply to a message + Given the following "users" exist: + | username | firstname | lastname | email | + | user1 | User | 1 | user1@example.com | + | user2 | User | 2 | user2@example.com | + And I log in as "user2" + And I send "User 2 to User 1" message to "User 1" user + And I log out + When I log in as "user1" + And I follow "Messages" in the user menu + And I click on "User 2" "text" in the "conversations" "message_area_region_content" + And I send "Reply to User 2" message in the message area + And I log out + Then I log in as "user2" + And I follow "Messages" in the user menu + And I should see "Reply to User 2" in the "conversations" "message_area_region_content" diff --git a/message/tests/behat/search_messages.feature b/message/tests/behat/search_messages.feature new file mode 100644 index 00000000000..138caaafc90 --- /dev/null +++ b/message/tests/behat/search_messages.feature @@ -0,0 +1,31 @@ +@core @message @javascript +Feature: Search messages + In order to communicate with fellow users + As a user + I need to be able to search my messages + + Background: + Given the following "users" exist: + | username | firstname | lastname | email | + | user1 | User | 1 | user1@example.com | + | user2 | User | 2 | user2@example.com | + | user3 | User | 3 | user3@example.com | + And I log in as "user2" + And I send "User 2 to User 1" message to "User 1" user + And I log out + And I log in as "user3" + And I send "User 3 to User 1" message to "User 1" user + And I log out + + Scenario: Search for messages + When I log in as "user1" + And I follow "Messages" in the user menu + And I set the field "Search messages" to "User 2 to User 1" + Then I should see "User 2" in the "search-results-area" "message_area_region" + And I should not see "User 3" in the "search-results-area" "message_area_region" + + Scenario: Search for messages no results + When I log in as "user1" + And I follow "Messages" in the user menu + And I set the field "Search messages" to "No message" + Then I should see "No results" in the "search-results-area" "message_area_region" diff --git a/message/tests/behat/search_users.feature b/message/tests/behat/search_users.feature new file mode 100644 index 00000000000..e8c0114fade --- /dev/null +++ b/message/tests/behat/search_users.feature @@ -0,0 +1,36 @@ +@core @message @javascript +Feature: Search users + In order to communicate with fellow users + As a user + I need to be able to search for them + + Background: + Given the following "users" exist: + | username | firstname | lastname | email | + | user1 | User | 1 | user1@example.com | + | user2 | User | 2 | user2@example.com | + | user3 | User | 3 | user3@example.com | + + Scenario: Search for single user + When I log in as "user1" + And I follow "Messages" in the user menu + And I click on "contacts-view" "message_area_action" + And I set the field "Search for a user or course" to "User 2" + Then I should see "User 2" in the "search-results-area" "message_area_region" + And I should not see "User 3" in the "search-results-area" "message_area_region" + + Scenario: Search for multiple user + When I log in as "user1" + And I follow "Messages" in the user menu + And I click on "contacts-view" "message_area_action" + And I set the field "Search for a user or course" to "User" + Then I should see "User 2" in the "search-results-area" "message_area_region" + And I should see "User 3" in the "search-results-area" "message_area_region" + And I should not see "User 1" in the "search-results-area" "message_area_region" + + Scenario: Search for messages no results + When I log in as "user1" + And I follow "Messages" in the user menu + And I click on "contacts-view" "message_area_action" + And I set the field "Search for a user or course" to "No User" + Then I should see "No results" in the "search-results-area" "message_area_region" diff --git a/message/tests/behat/view_messages.feature b/message/tests/behat/view_messages.feature new file mode 100644 index 00000000000..d4ad844aad1 --- /dev/null +++ b/message/tests/behat/view_messages.feature @@ -0,0 +1,23 @@ +@core @message @javascript +Feature: View messages + In order to communicate with fellow users + As a user + I need to be able to view my messages + + Scenario: View messages from multiple users + Given the following "users" exist: + | username | firstname | lastname | email | + | user1 | User | 1 | user1@example.com | + | user2 | User | 2 | user2@example.com | + | user3 | User | 3 | user3@example.com | + And I log in as "user2" + And I send "User 2 to User 1" message to "User 1" user + And I log out + And I log in as "user3" + And I send "User 3 to User 1" message to "User 1" user + And I log out + And I log in as "user1" + When I follow "Messages" in the user menu + Then I should see "User 3 to User 1" in the "conversations" "message_area_region_content" + And I click on "User 2" "text" in the "conversations" "message_area_region_content" + And I should see "User 2 to User 1" in the "conversations" "message_area_region_content" diff --git a/user/tests/behat/view_full_profile.feature b/user/tests/behat/view_full_profile.feature index 5fc34177491..94aa827af7a 100644 --- a/user/tests/behat/view_full_profile.feature +++ b/user/tests/behat/view_full_profile.feature @@ -83,7 +83,7 @@ Feature: Access to full profiles of users And I press "Add" And I log out When I log in as "student1" - And I view the message profile for "Student 3" user + And I view the "Student 3" contact in messages And I follow "View profile" Then I should see "First access to site" @@ -99,7 +99,7 @@ Feature: Access to full profiles of users And I press "Save and display" And I log out When I log in as "student1" - And I view the message profile for "Student 2" user + And I view the "Student 2" contact in messages And I follow "View profile" And I should not see "First access to site" And I should see "The details of this user are not available to you" @@ -117,6 +117,6 @@ Feature: Access to full profiles of users And I add "Student 2 (student2@example.com)" user to "Group 1" group members And I log out And I log in as "student1" - And I view the message profile for "Student 2" user + And I view the "Student 2" contact in messages And I follow "View profile" Then I should see "First access to site"