From 061ba34e07d9a75e35a24a9a670cccef2333c3fb Mon Sep 17 00:00:00 2001 From: Noel De Martin Date: Thu, 3 Jun 2021 11:21:50 +0200 Subject: [PATCH] MOBILE-3320 behat: Update messages tests --- .../tests/behat/app_basic_usage.feature | 318 +++++++++--------- tests/behat/app_behat_runtime.js | 83 +++-- 2 files changed, 221 insertions(+), 180 deletions(-) diff --git a/mod/messages/tests/behat/app_basic_usage.feature b/mod/messages/tests/behat/app_basic_usage.feature index a2aa8fa3f..8aebbbae3 100755 --- a/mod/messages/tests/behat/app_basic_usage.feature +++ b/mod/messages/tests/behat/app_basic_usage.feature @@ -1,4 +1,4 @@ -@mod @mod_messages @app @app_upto3.9.4 @javascript +@mod @mod_messages @app @javascript Feature: Test basic usage of messages in app In order to participate with messages while using the mobile app As a student @@ -19,23 +19,23 @@ Feature: Test basic usage of messages in app | student1 | C1 | student | | student2 | C1 | student | - @app @3.8.0 Scenario: View recent conversations and contacts When I enter the app And I log in as "teacher1" And I press "Messages" in the app And I press "Contacts" in the app - Then I should see "No contacts" + Then I should find "No contacts" in the app - When I press "addon.messages.search" in the app + When I press "Search people and messages" in the app And I set the field "Search" to "student" in the app - And I press "search" in the app + And I press "Search" "button" in the app And I press "Student1 student1" in the app And I set the field "New message" to "heeey student" in the app And I press "Send" in the app - And I press "Conversation actions menu" in the app + And I press "Display options" in the app And I press "Add to contacts" in the app - And I press "Add" in the app + And I press "Add" near "Are you sure you want to add Student1 student1 to your contacts?" in the app + Then I should find "Contact request sent" in the app When I enter the app And I log in as "student1" @@ -44,86 +44,91 @@ Feature: Test basic usage of messages in app And I press "Requests" in the app And I press "Teacher teacher" in the app And I press "Accept and add to contacts" in the app - And I press the back button in the app - And I press "Contacts" near "Requests" in the app + Then I should not find "Teacher teacher would like to contact you" in the app + + When I press the back button in the app + And I press "Contacts" near "No contact requests" in the app Then the header should be "Contacts" in the app - And I should see "Teacher teacher" + And I should find "Teacher teacher" in the app When I press the back button in the app And I press "Teacher teacher" in the app Then the header should be "Teacher teacher" in the app - And I should see "heeey student" + And I should find "heeey student" in the app - @app @3.8.0 Scenario: Search users When I enter the app And I log in as "student1" And I press "Messages" in the app - And I press "addon.messages.search" in the app + And I press "Search people and messages" in the app And I set the field "Search" to "student2" in the app - And I press "search" in the app - Then I should see "Student2 student2" + And I press "Search" "button" in the app + Then I should find "Student2 student2" in the app When I set the field "Search" to "Teacher" in the app - And I press "search" in the app - Then I should see "Teacher teacher" + And I press "Search" "button" in the app + Then I should find "Teacher teacher" in the app - @app @3.8.0 Scenario: Send/receive messages in existing conversations When I enter the app And I log in as "teacher1" And I press "Messages" in the app And I press "Contacts" in the app - And I press "addon.messages.search" in the app + And I press "Search people and messages" in the app And I set the field "Search" to "student1" in the app - And I press "search" in the app + And I press "Search" "button" in the app And I press "Student1 student1" in the app And I set the field "New message" to "heeey student" in the app And I press "Send" in the app - And I enter the app + Then I should find "heeey student" in the app + + When I enter the app And I log in as "student1" And I press "Messages" in the app And I press "Contacts" in the app - And I press "addon.messages.search" in the app + And I press "Search people and messages" in the app And I set the field "Search" to "teacher" in the app - And I press "search" in the app + And I press "Search" "button" in the app And I press "Teacher teacher" in the app - Then I should see "heeey student" + Then I should find "heeey student" in the app When I set the field "New message" to "hi" in the app And I press "Send" in the app - And I enter the app + Then I should find "hi" in the app + + When I enter the app And I log in as "teacher1" And I press "Messages" in the app - And I press "Contacts" in the app - And I press "addon.messages.search" in the app + And I press "Search people and messages" in the app And I set the field "Search" to "student1" in the app - And I press "search" in the app + And I press "Search" "button" in the app And I press "Student1 student1" in the app - Then I should see "heeey student" - And I should see "hi" - And I set the field "New message" to "byee" in the app - And I press "Send" in the app - Then I should see "heeey student" - And I should see "hi" - And I should see "byee" + Then I should find "heeey student" in the app + And I should find "hi" in the app + + When I set the field "New message" to "byee" in the app + And I press "Send" in the app + Then I should find "heeey student" in the app + And I should find "hi" in the app + And I should find "byee" in the app - @app @3.8.0 Scenario: User profile: send message, add/remove contact When I enter the app And I log in as "teacher1" And I press "Messages" in the app And I press "Contacts" in the app - And I press "addon.messages.search" in the app + And I press "Search people and messages" in the app And I set the field "Search" to "student" in the app - And I press "search" in the app + And I press "Search" "button" in the app And I press "Student1 student1" in the app And I set the field "New message" to "heeey student" in the app And I press "Send" in the app - And I press "Conversation actions menu" in the app + Then I should find "heeey student" in the app + + When I press "Display options" in the app And I press "Add to contacts" in the app And I press "Add" in the app - Then I should see "Contact request sent" + Then I should find "Contact request sent" in the app When I enter the app And I log in as "student1" @@ -131,159 +136,170 @@ Feature: Test basic usage of messages in app And I press "Contacts" in the app And I press "Requests" in the app And I press "Teacher teacher" in the app - Then I should see "Teacher teacher would like to contact you" + Then I should find "Teacher teacher would like to contact you" in the app When I press "Accept and add to contacts" in the app - Then I should not see "Teacher teacher would like to contact you" + Then I should not find "Teacher teacher would like to contact you" in the app - When I press "Teacher teacher" in the app + When I press "Display options" in the app + And I press "User info" in the app And I press "Message" in the app And I set the field "New message" to "hi" in the app - And I press "Send" in the app - Then I should see "heeey student" - And I should see "hi" + And I press "Send" "button" in the app + Then I should find "heeey student" in the app + And I should find "hi" in the app - When I press the back button in the app + When I press "Display options" in the app And I press "Remove from contacts" in the app And I press "Remove" in the app - Then I should see "Add to contacts" + And I wait loading to finish in the app + And I press the back button in the app + And I press the back button in the app + And I press "Display options" in the app + Then I should find "Add to contacts" in the app - When I press the back button in the app - And I press "Conversation actions menu" in the app - Then I should see "Add to contacts" + When I press "Display options" in the app + And I press "Delete conversation" in the app + And I press "Delete" near "Are you sure you would like to delete this entire conversation?" in the app + Then I should not find "heeey student" in the app + And I should not find "hi" in the app - When I press "Delete conversation" in the app - And I press "Delete" in the app - And I should not see "heeey student" - And I should not see "hi" - - @app @3.8.0 Scenario: Send message offline When I enter the app And I log in as "teacher1" And I press "Messages" in the app And I press "Contacts" in the app - And I press "addon.messages.search" in the app + And I press "Search people and messages" in the app And I set the field "Search" to "student1" in the app - And I press "search" in the app + And I press "Search" "button" in the app And I press "Student1 student1" in the app And I switch offline mode to "true" And I set the field "New message" to "heeey student" in the app And I press "Send" in the app - And I set the field "New message" to "byee" in the app + Then I should find "heeey student" in the app + + When I set the field "New message" to "byee" in the app And I press "Send" in the app - And I switch offline mode to "false" + Then I should find "byee" in the app + + When I switch offline mode to "false" And I press the back button in the app And I press "Student1 student1" in the app - And I enter the app + Then I should find "heeey student" in the app + And I should find "byee" in the app + + When I enter the app And I log in as "student1" And I press "Messages" in the app And I press "Teacher teacher" in the app - Then I should see "heeey student" - And I should see "byee" + Then I should find "heeey student" in the app + And I should find "byee" in the app - @app @3.8.0 Scenario: Auto-sync messages When I enter the app And I log in as "teacher1" And I press "Messages" in the app And I press "Contacts" in the app - And I press "addon.messages.search" in the app + And I press "Search people and messages" in the app And I set the field "Search" to "student1" in the app - And I press "search" in the app + And I press "Search" "button" in the app And I press "Student1 student1" in the app And I switch offline mode to "true" And I set the field "New message" to "heeey student" in the app And I press "Send" in the app And I set the field "New message" to "byee" in the app And I press "Send" in the app - And I switch offline mode to "false" + Then I should find "byee" in the app + + When I switch offline mode to "false" And I run cron tasks in the app And I enter the app And I log in as "student1" And I press "Messages" in the app And I press "Teacher teacher" in the app - Then I should see "heeey student" - And I should see "byee" + Then I should find "heeey student" in the app + And I should find "byee" in the app - @app @3.8.0 Scenario: Search for messages When I enter the app And I log in as "teacher1" And I press "Messages" in the app - And I press "addon.messages.search" in the app + And I press "Search people and messages" in the app And I set the field "Search" to "student1" in the app - And I press "search" in the app + And I press "Search" "button" in the app And I press "Student1 student1" in the app And I set the field "New message" to "test message" in the app And I press "Send" in the app - And I set the field "New message" to "search this message" in the app + Then I should find "test message" in the app + + When I set the field "New message" to "search this message" in the app And I press "Send" in the app - And I enter the app + Then I should find "search this message" in the app + + When I enter the app And I log in as "student1" And I press "Messages" in the app - And I press "addon.messages.search" in the app + And I press "Search people and messages" in the app And I set the field "Search" to "search this message" in the app - And I press "search" in the app - Then I should see "Messages" - And I should see "search this message" + And I press "Search" "button" in the app + Then I should find "Messages" in the app + And I should find "search this message" in the app When I press "search this message" near "Teacher teacher" in the app - Then I should see "test message" - And I should see "search this message" + Then I should find "test message" in the app + And I should find "search this message" in the app - @app @3.8.0 Scenario: Star/Unstar When I enter the app And I log in as "teacher1" And I press "Messages" in the app - And I press "addon.messages.search" in the app + And I press "Search people and messages" in the app And I set the field "Search" to "student1" in the app - And I press "search" in the app + And I press "Search" "button" in the app And I press "Student1 student1" in the app And I set the field "New message" to "star message" in the app And I press "Send" in the app - And I enter the app + Then I should find "star message" in the app + + When I enter the app And I log in as "student2" And I press "Messages" in the app - And I press "addon.messages.search" in the app + And I press "Search people and messages" in the app And I set the field "Search" to "student1" in the app - And I press "search" in the app + And I press "Search" "button" in the app And I press "Student1 student1" in the app And I set the field "New message" to "test message student2" in the app And I press "Send" in the app - And I enter the app + Then I should find "test message student2" in the app + + When I enter the app And I log in as "student1" And I press "Messages" in the app - Then I should see "Private (2)" - And I should see "Starred (1)" + Then I should find "Private (2)" in the app + And I should find "Starred (1)" in the app When I press "star message" in the app - And I press "Conversation actions menu" in the app + And I press "Display options" in the app And I press "Star conversation" in the app And I press the back button in the app - Then I should see "Private (1)" - And I should see "Starred (2)" + Then I should find "Private (1)" in the app + And I should find "Starred (2)" in the app When I press "Starred (2)" in the app - Then I should see "Teacher teacher" - And I should see "Student1 student1" + Then I should find "Teacher teacher" in the app + And I should find "Student1 student1" in the app - @app @3.8.0 Scenario: User blocking feature When I enter the app And I log in as "student2" And I press "Course 1" near "Recently accessed courses" in the app And I press "Participants" in the app And I press "Student1 student1" in the app + And I press "Message" in the app + And I press "Display options" in the app And I press "Block user" in the app - And I should see "Are you sure you want to block Student1 student1?" - And I press "Cancel" in the app - And I should see "Block user" - And I press "Block user" in the app - And I press "Block user" near "Cancel" in the app - Then I should see "Unblock user" - But I should not see "Block user" + And I press "Block user" near "Are you sure you want to block Student1 student1?" in the app + Then I should find "You have blocked this user" in the app When I enter the app And I log in as "student1" @@ -291,25 +307,21 @@ Feature: Test basic usage of messages in app And I press "Participants" in the app And I press "Student2 student2" in the app And I press "Message" in the app - Then I should see "You are unable to message this user" + Then I should find "You are unable to message this user" in the app When I enter the app And I log in as "student2" And I press "Course 1" near "Recently accessed courses" in the app And I press "Participants" in the app And I press "Student1 student1" in the app - Then I should see "Unblock user" - But I should not see "Block user" + And I press "Message" in the app + And I press "Display options" in the app + Then I should find "Unblock user" in the app + But I should not find "Block user" in the app When I press "Unblock user" in the app - And I press "Cancel" in the app - Then I should see "Unblock user" - But I should not see "Block user" - - When I press "Unblock user" in the app - And I press "Unblock user" near "Cancel" in the app - Then I should see "Block user" - But I should not see "Unblock user" + And I press "Unblock user" near "Are you sure you want to unblock Student1 student1?" in the app + Then I should not find "You have blocked this user" in the app When I enter the app And I log in as "student1" @@ -319,10 +331,9 @@ Feature: Test basic usage of messages in app And I press "Message" in the app And I set the field "New message" to "test message" in the app And I press "Send" in the app - Then I should see "test message" - But I should not see "You are unable to message this user" + Then I should find "test message" in the app + But I should not find "You are unable to message this user" in the app - @app @3.8.0 Scenario: Mute Unmute conversations When I enter the app And I log in as "student1" @@ -332,73 +343,80 @@ Feature: Test basic usage of messages in app And I press "Message" in the app And I set the field "New message" to "test message" in the app And I press "Send" in the app - And I press "Conversation actions menu" in the app + Then I should find "test message" in the app + + When I press "Display options" in the app And I press "Mute" in the app - And I press "Muted conversation" in the app - And I press "Conversation actions menu" in the app - Then I should not see "Mute" + Then I should find "Muted conversation" in the app - When I press "Unmute" in the app - And I press "Conversation actions menu" in the app - Then I should not see "Unmute" + When I press "Display options" in the app + And I press "Unmute" in the app + Then I should not find "Muted conversation" in the app + When I press "Display options" in the app When I press "Mute" in the app - And I press "Messages" in the app + Then I should find "Muted conversation" in the app + + When I press "Messages" in the app And I press "Private (1)" in the app And I press "Student2 student2" in the app - And I press "Conversation actions menu" in the app - Then I should see "Unmute" - But I should not see "Mute" + Then I should find "test message" in the app + And I should find "Muted conversation" in the app - @app @3.8.0 Scenario: Self conversations When I enter the app And I log in as "student1" And I press "Messages" in the app - Then I should see "Starred (1)" + Then I should find "Starred (1)" in the app When I press "Student1 student1" in the app And I set the field "New message" to "self conversation online" in the app And I press "Send" in the app - And I switch offline mode to "true" + Then I should find "self conversation online" in the app + + When I switch offline mode to "true" And I set the field "New message" to "self conversation offline" in the app And I press "Send" in the app - And I switch offline mode to "false" + Then I should find "self conversation offline" in the app + + When I switch offline mode to "false" And I press the back button in the app And I press "Student1 student1" in the app - And I press "Conversation actions menu" in the app - Then I should see "Show delete messages" - And I should see "Delete conversation" + And I press "Display options" in the app + Then I should find "Show delete messages" in the app + And I should find "Delete conversation" in the app When I press "Unstar conversation" in the app - And I press "Conversation actions menu" in the app - Then I should see "Star conversation" - And I should see "Delete conversation" + And I press "Display options" in the app + Then I should find "Star conversation" in the app + And I should find "Delete conversation" in the app When I press "Show delete messages" in the app - Then I should see "self conversation online" - And I should see "self conversation offline" + Then I should find "self conversation online" in the app + And I should find "self conversation offline" in the app When I press "Delete message" near "self conversation offline" in the app And I press "OK" in the app - Then I should see "self conversation online" - But I should not see "self conversation offline" + Then I should find "self conversation online" in the app + But I should not find "self conversation offline" in the app - When I press "Conversation actions menu" in the app + When I press "Display options" in the app And I press "Delete conversation" in the app - And I press "Delete" in the app - Then I should not see "self conversation online" - And I should not see "self conversation offline" + And I press "Delete" near "Are you sure you would like to delete this entire personal conversation?" in the app + Then I should not find "self conversation online" in the app + And I should not find "self conversation offline" in the app When I press the back button in the app - And I press "addon.messages.search" in the app + And I press "Search people and messages" in the app And I set the field "Search" to "Student1 student1" in the app - And I press "search" in the app + And I press "Search" "button" in the app And I press "Student1 student1" in the app And I set the field "New message" to "auto search test" in the app And I press "Send" in the app - And I press the back button in the app + Then I should find "auto search test" in the app + + When I press the back button in the app And I press the back button in the app And I press "Private" in the app And I press "Student1 student1" in the app - Then I should see "auto search test" + Then I should find "auto search test" in the app diff --git a/tests/behat/app_behat_runtime.js b/tests/behat/app_behat_runtime.js index 0f2ee103e..8945cc458 100644 --- a/tests/behat/app_behat_runtime.js +++ b/tests/behat/app_behat_runtime.js @@ -406,6 +406,57 @@ return []; }; + /** + * Press an element. + * + * @param {HTMLElement} element Element to press. + */ + var pressElement = function(element) { + if (window.BehatMoodleAppLegacy) { + var mainContent = getNavCtrl().getActive().contentRef().nativeElement; + var rect = element.getBoundingClientRect(); + + // Scroll the item into view. + mainContent.scrollTo(rect.x, rect.y); + + // Simulate a mouse click on the button. + var eventOptions = { + clientX: rect.left + rect.width / 2, + clientY: rect.top + rect.height / 2, + bubbles: true, + view: window, + cancelable: true, + }; + setTimeout(() => element.dispatchEvent(new MouseEvent('mousedown', eventOptions)), 0); + setTimeout(() => element.dispatchEvent(new MouseEvent('mouseup', eventOptions)), 0); + setTimeout(() => element.dispatchEvent(new MouseEvent('click', eventOptions)), 0); + } else { + // Scroll the item into view. + element.scrollIntoView(); + + // Events don't bubble up across Shadow DOM boundaries, and some buttons + // may not work without doing this. + const parentElement = getParentElement(element); + + if (parentElement?.matches('ion-button, ion-back-button')) { + element = parentElement; + } + + // There are some buttons in the app that don't respond to click events, for example + // buttons using the core-supress-events directive. That's why we need to send both + // click and mouse events. + element.dispatchEvent(new MouseEvent('mousedown', eventOptions)); + + setTimeout(() => { + element.dispatchEvent(new MouseEvent('mouseup', eventOptions)); + element.click(); + }, 300); + } + + // Mark busy until the button click finishes processing. + addPendingDelay(); + }; + /** * Function to find and click an app standard button. * @@ -472,10 +523,7 @@ } // Click button - foundButton.click(); - - // Mark busy until the button click finishes processing. - addPendingDelay(); + pressElement(foundButton); return 'OK'; }; @@ -591,32 +639,7 @@ return 'ERROR: ' + error.message; } - if (window.BehatMoodleAppLegacy) { - var mainContent = getNavCtrl().getActive().contentRef().nativeElement; - var rect = found.getBoundingClientRect(); - - // Scroll the item into view. - mainContent.scrollTo(rect.x, rect.y); - - // Simulate a mouse click on the button. - var eventOptions = {clientX: rect.left + rect.width / 2, clientY: rect.top + rect.height / 2, - bubbles: true, view: window, cancelable: true}; - setTimeout(function() { - found.dispatchEvent(new MouseEvent('mousedown', eventOptions)); - }, 0); - setTimeout(function() { - found.dispatchEvent(new MouseEvent('mouseup', eventOptions)); - }, 0); - setTimeout(function() { - found.dispatchEvent(new MouseEvent('click', eventOptions)); - }, 0); - } else { - found.scrollIntoView(); - setTimeout(() => found.click(), 300); - } - - // Mark busy until the button click finishes processing. - addPendingDelay(); + pressElement(found); return 'OK'; };