diff --git a/integration_test/robots/chat_list_robot.dart b/integration_test/robots/chat_list_robot.dart index 90086b2887..93f74a479e 100644 --- a/integration_test/robots/chat_list_robot.dart +++ b/integration_test/robots/chat_list_robot.dart @@ -29,12 +29,12 @@ class ChatListRobot extends HomeRobot { } Future openChatGroupByIndex(int index) async { - await (await getListOfChatGroup())[index].root.tap(); + await (getListOfChatGroup()[index].root).tap(); await $.pumpAndSettle(); return ChatGroupDetailRobot($); } - Future> getListOfChatGroup() async { + List getListOfChatGroup() { final List groupList = []; // Evaluate once to find how many TwakeListItem widgets exist diff --git a/integration_test/robots/chat_search_view_robot.dart b/integration_test/robots/chat_search_view_robot.dart new file mode 100644 index 0000000000..216ac14cd4 --- /dev/null +++ b/integration_test/robots/chat_search_view_robot.dart @@ -0,0 +1,42 @@ +import 'package:fluffychat/pages/chat_search/chat_search_view.dart'; +import 'package:fluffychat/widgets/twake_components/twake_icon_button.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:linagora_design_flutter/list_item/twake_list_item.dart'; +import 'package:patrol/patrol.dart'; +import '../base/core_robot.dart'; +import 'twake_list_item_robot.dart'; + +class ChatSearchViewRobot extends CoreRobot { + ChatSearchViewRobot(super.$); + + PatrolFinder getBackIcon() { + const icon = IconData(0xEF4D, fontFamily: 'MaterialIcons'); + return $(TwakeIconButton).containing(find.byIcon(icon)); + } + + PatrolFinder getTextField() { + return $(ChatSearchView).$(AppBar).$(TextField); + } + + PatrolFinder getSearchIcon() { + return getTextField().$(Icon).at(0); + } + + PatrolFinder getCloseIcon() { + return getTextField().$(IconButton); + } + + Future> getListOfChatSearch() async { + final List groupList = []; + + // Evaluate once to find how many TwakeListItem widgets exist + final matches = $(TwakeListItem).evaluate(); + for (final element in matches) { + final finder = $(element.widget.runtimeType); + groupList.add(TwakeListItemRobot($, finder)); + } + return groupList; + } + +} diff --git a/integration_test/scenarios/chat_detail_scenario.dart b/integration_test/scenarios/chat_detail_scenario.dart new file mode 100644 index 0000000000..f74f758a77 --- /dev/null +++ b/integration_test/scenarios/chat_detail_scenario.dart @@ -0,0 +1,17 @@ +import 'package:flutter_test/flutter_test.dart'; +import 'package:linagora_design_flutter/list_item/twake_list_item.dart'; +import '../base/base_scenario.dart'; +import '../robots/chat_group_detail_robot.dart'; +import 'package:flutter/material.dart'; + +class ChatDetailScenario extends BaseScenario { + ChatDetailScenario(super.$); + + Future makeASearch(String searchText) async { + await ChatGroupDetailRobot($).getSearchIcon().tap(); + await $.waitUntilVisible($(AppBar).$(TextField)); + await $(AppBar).$(TextField).enterText(searchText); + await ChatGroupDetailRobot($).waitForEitherVisible($: $, first: $(TwakeListItem), second: $("No Results"), timeout: const Duration(seconds: 10)); + await Future.delayed(const Duration(seconds: 2)); + } +} diff --git a/integration_test/scenarios/chat_scenario.dart b/integration_test/scenarios/chat_scenario.dart index 5f03489109..6c266052be 100644 --- a/integration_test/scenarios/chat_scenario.dart +++ b/integration_test/scenarios/chat_scenario.dart @@ -42,7 +42,7 @@ class ChatScenario extends BaseScenario { Future openChatGroupByTitle(String groupTitle) async { await enterSearchText(groupTitle); - await (await ChatListRobot($).getListOfChatGroup())[0].root.tap(); + await (ChatListRobot($).getListOfChatGroup())[0].root.tap(); await $.pumpAndSettle(); return ChatGroupDetailRobot($); } @@ -390,7 +390,7 @@ class ChatScenario extends BaseScenario { } Future verifySearchResultContains(String keyword) async { - final items = await ChatListRobot($).getListOfChatGroup(); + final items = ChatListRobot($).getListOfChatGroup(); final length = items.length; var i = 0; @@ -416,7 +416,7 @@ class ChatScenario extends BaseScenario { Future openChatGroup(String title) async { await enterSearchText(title); - await (await ChatListRobot($).getListOfChatGroup())[0].root.tap(); + await (ChatListRobot($).getListOfChatGroup()[0].root).tap(); final chatGroupDetailRobot = ChatGroupDetailRobot($); await chatGroupDetailRobot.confimrAccessMedia(); await $.pumpAndSettle(); diff --git a/integration_test/tests/chat/chat_group_test.dart b/integration_test/tests/chat/chat_group_test.dart index ba1eaa4d28..d4a3e365f4 100644 --- a/integration_test/tests/chat/chat_group_test.dart +++ b/integration_test/tests/chat/chat_group_test.dart @@ -6,15 +6,17 @@ import 'package:flutter_test/flutter_test.dart'; import '../../base/test_base.dart'; import '../../help/soft_assertion_helper.dart'; import '../../robots/chat_group_detail_robot.dart'; +import '../../robots/chat_search_view_robot.dart'; +import '../../scenarios/chat_detail_scenario.dart'; import '../../scenarios/chat_scenario.dart'; import '../../robots/home_robot.dart'; import 'package:patrol/patrol.dart'; // --- Common config --- const defaultTime = Duration(seconds: 60); -const searchPhrase = - String.fromEnvironment('SearchByTitle', defaultValue: 'My Default Group'); -const forwardReceiver = +const groupTest = + String.fromEnvironment('TitleOfGroupTest', defaultValue: 'My Default Group'); +const receiver = String.fromEnvironment('Receiver', defaultValue: 'Receiver Group'); int uniqueId() => DateTime.now().microsecondsSinceEpoch; @@ -25,7 +27,7 @@ Future<(String, String)> prepareTwoMessages(PatrolIntegrationTester $) async { final receiverMsg = 'receiver sent at $id'; await HomeRobot($).gotoChatListScreen(); - await ChatScenario($).openChatGroupByTitle(searchPhrase); + await ChatScenario($).openChatGroupByTitle(groupTest); await ChatScenario($) .sendAMesage(senderMsg); // NOTE: keep current helper name @@ -179,4 +181,27 @@ void main() { }, ); + + TestBase().runPatrolTest( + description: 'Search for messages inside a chat', + test: ($) async { + final s = SoftAssertHelper(); + //open chat and make some messages + final receiveMessage = (await prepareTwoMessages($)).$2; + final searchPhrase = receiveMessage.substring(receiveMessage.indexOf("sent"), receiveMessage.length); + + //search by the word that contained in the text that by sent by both sender and receiver + await ChatDetailScenario($).makeASearch(searchPhrase); + // verify info dialog is shown the search phrase is displayed in the 2 messages + var numberOfResult = (await ChatSearchViewRobot($).getListOfChatSearch()).length; + s.softAssertEquals(numberOfResult == 2, true, "expect is 2 but got: $numberOfResult"); + + //search by the word that not existed in the chat + await ChatDetailScenario($).makeASearch("$searchPhrase no existed"); + //verify there is no result + numberOfResult = (await ChatSearchViewRobot($).getListOfChatSearch()).length; + s.softAssertEquals(numberOfResult, 0, "Expected empty result, but got $numberOfResult"); + s.verifyAll(); + }, + ); } diff --git a/integration_test/tests/chat/chat_list_test.dart b/integration_test/tests/chat/chat_list_test.dart index 4bcdaa1300..cad468494d 100644 --- a/integration_test/tests/chat/chat_list_test.dart +++ b/integration_test/tests/chat/chat_list_test.dart @@ -30,24 +30,24 @@ void main() { await ChatScenario($).verifySearchResultViewIsShown(); await ChatScenario($).verifySearchResultContains(currentAccount.substring(1,3)); //return a list of result - s.softAssertEquals((await ChatListRobot($).getListOfChatGroup()).isNotEmpty, true, 'Searchby $currentAccount.substring(1,3) Expected at least 1 group, but found 0',); + s.softAssertEquals(ChatListRobot($).getListOfChatGroup().isNotEmpty, true, 'Searchby $currentAccount.substring(1,3) Expected at least 1 group, but found 0',); // search by full an address matrix await ChatScenario($).enterSearchText(searchByMatrixAddress); //verify there is one result - s.softAssertEquals((await ChatListRobot($).getListOfChatGroup()).length == 1, true, 'Search by $searchByMatrixAddress Expected number of group is 1 , but found != 1'); + s.softAssertEquals(ChatListRobot($).getListOfChatGroup().length == 1, true, 'Search by $searchByMatrixAddress Expected number of group is 1 , but found != 1'); // search by full an address matrix but make it in case-sensitive format await ChatScenario($).enterSearchText(searchByMatrixAddress.toUpperCase()); //verify there is one result - s.softAssertEquals((await ChatListRobot($).getListOfChatGroup()).length == 1, true, 'Searhc by $searchByMatrixAddress.toUpperCase() Expected number of group is 1 , but found != 1'); + s.softAssertEquals(ChatListRobot($).getListOfChatGroup().length == 1, true, 'Searhc by $searchByMatrixAddress.toUpperCase() Expected number of group is 1 , but found != 1'); // search by current account await ChatScenario($).enterSearchText(currentAccount); //verify items displayed on the TwakeListItem //todo: handle the case list both contact and Message - s.softAssertEquals((await (await ChatListRobot($).getListOfChatGroup())[0].getOwnerLabel()).visible, true, 'Owner is missing!',); - s.softAssertEquals((await (await ChatListRobot($).getListOfChatGroup())[0].getEmailLabelIncaseSearching()).visible, true, 'Email field is not shown',); + s.softAssertEquals((await (ChatListRobot($).getListOfChatGroup()[0]).getOwnerLabel()).visible, true, 'Owner is missing!',); + s.softAssertEquals((await (ChatListRobot($).getListOfChatGroup()[0]).getEmailLabelIncaseSearching()).visible, true, 'Email field is not shown',); // after searching, open a chat by clicking on a result final chatGroupDetailRobot = await ChatScenario($).openChatGroup(searchByTitle);