Skip to content

Commit

Permalink
MDL-55926 message: add behat tests for message ui
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanwyllie committed Oct 18, 2016
1 parent 6a69cda commit f05c101
Show file tree
Hide file tree
Showing 10 changed files with 251 additions and 10 deletions.
14 changes: 14 additions & 0 deletions lib/behat/classes/partial_named_selector.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ public function __construct() {
'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',
Expand All @@ -85,6 +87,9 @@ public function __construct() {
'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',
Expand Down Expand Up @@ -152,6 +157,15 @@ public function __construct() {
XPATH
, 'form_row' => <<<XPATH
.//*[self::label or self::div[contains(concat(' ', @class, ' '), ' fstaticlabel ')]][contains(., %locator%)]/ancestor::*[contains(concat(' ', @class, ' '), ' fitem ')]
XPATH
, 'message_area_region' => <<<XPATH
.//div[@data-region='messaging-area']/descendant::*[@data-region = %locator%]
XPATH
, 'message_area_region_content' => <<<XPATH
.//div[@data-region='messaging-area']/descendant::*[@data-region-content = %locator%]
XPATH
, 'message_area_action' => <<<XPATH
.//div[@data-region='messaging-area']/descendant::*[@data-action = %locator%]
XPATH
);

Expand Down
37 changes: 30 additions & 7 deletions message/tests/behat/behat_message.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,18 @@
class behat_message extends behat_base {

/**
* Sends a message to the specified user from the logged user. The user full name should contain the first and last names.
* View the contact information of a user in the messages ui.
*
* @Given /^I view the message profile for "(?P<user_full_name_string>(?:[^"]|\\")*)" user$/
* @Given /^I view the "(?P<user_full_name_string>(?:[^"]|\\")*)" 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');

Expand All @@ -59,8 +59,17 @@ public function i_view_users_message_profile($userfullname) {

$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');
}
Expand All @@ -73,7 +82,7 @@ public function i_view_users_message_profile($userfullname) {
* @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'));

Expand All @@ -85,4 +94,18 @@ public function i_send_message_to_user($messagecontent, $userfullname) {

$this->execute("behat_forms::press_button", get_string('send', 'message'));
}

/**
* Select messages from a user in the messaging ui.
*
* @Given /^I send "(?P<message_contents_string>(?:[^"]|\\")*)" 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'));
}
}
27 changes: 27 additions & 0 deletions message/tests/behat/delete_all_messages.feature
Original file line number Diff line number Diff line change
@@ -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"
31 changes: 31 additions & 0 deletions message/tests/behat/delete_messages.feature
Original file line number Diff line number Diff line change
@@ -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"
34 changes: 34 additions & 0 deletions message/tests/behat/manage_contacts.feature
Original file line number Diff line number Diff line change
@@ -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"
22 changes: 22 additions & 0 deletions message/tests/behat/reply_message.feature
Original file line number Diff line number Diff line change
@@ -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"
31 changes: 31 additions & 0 deletions message/tests/behat/search_messages.feature
Original file line number Diff line number Diff line change
@@ -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"
36 changes: 36 additions & 0 deletions message/tests/behat/search_users.feature
Original file line number Diff line number Diff line change
@@ -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"
23 changes: 23 additions & 0 deletions message/tests/behat/view_messages.feature
Original file line number Diff line number Diff line change
@@ -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"
6 changes: 3 additions & 3 deletions user/tests/behat/view_full_profile.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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"
Expand All @@ -117,6 +117,6 @@ Feature: Access to full profiles of users
And I add "Student 2 ([email protected])" 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"

0 comments on commit f05c101

Please sign in to comment.