diff --git a/integration_test/robots/add_member_robot.dart b/integration_test/robots/add_member_robot.dart index 8f8eb6d33..9bf270582 100644 --- a/integration_test/robots/add_member_robot.dart +++ b/integration_test/robots/add_member_robot.dart @@ -66,7 +66,7 @@ class AddMemberRobot extends CoreRobot { Future selectAllFilteredAccounts() async { final accounts = getListOfChatGroup(); for( final account in accounts){ - await account.getCheckBox().tap(); + account.getCheckBox().tap(); } } diff --git a/integration_test/robots/chat_list_robot.dart b/integration_test/robots/chat_list_robot.dart index 90086b288..0b6e33abe 100644 --- a/integration_test/robots/chat_list_robot.dart +++ b/integration_test/robots/chat_list_robot.dart @@ -1,3 +1,4 @@ +import 'package:fluffychat/pages/chat_list/chat_list_bottom_navigator.dart'; import 'package:fluffychat/pages/chat_list/chat_list_item_title.dart'; import 'package:fluffychat/widgets/twake_components/twake_fab.dart'; import 'package:flutter/material.dart'; @@ -23,6 +24,14 @@ class ChatListRobot extends HomeRobot { return $(TwakeFloatingActionButton); } + PatrolFinder getPinIcon(){ + return $(ChatListBottomNavigator).$(InkWell).containing($("Pin")); + } + + PatrolFinder getUnPinIcon(){ + return $(ChatListBottomNavigator).$(InkWell).containing($("Unpin")); + } + Future clickOnPenIcon() async{ await getPenIcon().tap(); await $.waitUntilVisible($(AppBar).$("New chat")); 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 000000000..1edcd2eab --- /dev/null +++ b/integration_test/robots/chat_search_view_robot.dart @@ -0,0 +1,41 @@ +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() { + return $(ChatSearchView).$(TwakeIconButton).containing(find.byTooltip('Back')); + } + + PatrolFinder getTextField() { + return $(ChatSearchView).$(AppBar).$(TextField); + } + + PatrolFinder getSearchIcon() { + return getTextField().$(Icon).at(0); + } + + PatrolFinder getCloseIcon() { + return getTextField().$(IconButton); + } + + Future> getListOfChatSeach() 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/robots/twake_list_item_robot.dart b/integration_test/robots/twake_list_item_robot.dart index 5b09fa82b..d66d2a4e4 100644 --- a/integration_test/robots/twake_list_item_robot.dart +++ b/integration_test/robots/twake_list_item_robot.dart @@ -14,7 +14,7 @@ class TwakeListItemRobot extends CoreRobot { return root.$(Radio).at(0); } - Future getCheckBox() async { + PatrolFinder getCheckBox() { return root.$(Checkbox).at(0); } diff --git a/integration_test/scenarios/chat_detail_scenario.dart b/integration_test/scenarios/chat_detail_scenario.dart new file mode 100644 index 000000000..c70c9cf22 --- /dev/null +++ b/integration_test/scenarios/chat_detail_scenario.dart @@ -0,0 +1,19 @@ +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 SearchRobot($).enterSearchText(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 5f0348910..cd9559e0a 100644 --- a/integration_test/scenarios/chat_scenario.dart +++ b/integration_test/scenarios/chat_scenario.dart @@ -13,6 +13,7 @@ import 'package:fluffychat/pages/chat/events/message_time.dart'; import 'package:fluffychat/pages/chat/seen_by_row.dart'; import 'package:fluffychat/pages/chat_draft/draft_chat_view.dart'; import 'package:fluffychat/pages/chat_list/chat_list_body_view.dart'; +import 'package:fluffychat/pages/chat_list/chat_list_item_title.dart'; import 'package:fluffychat/widgets/context_menu/context_menu_action_item_widget.dart'; import 'package:fluffychat/widgets/twake_components/twake_icon_button.dart'; import 'package:flutter_test/flutter_test.dart'; @@ -30,6 +31,7 @@ import '../robots/menu_robot.dart'; import '../robots/new_chat_robot.dart'; import '../robots/search_robot.dart'; import '../robots/setting_for_new_group.dart'; +import '../robots/twake_list_item_robot.dart'; enum UserLevel { member, admin, owner, moderator } class ChatScenario extends BaseScenario { @@ -481,4 +483,41 @@ class ChatScenario extends BaseScenario { s.softAssertEquals( await CoreRobot($).isActuallyScrollable($,root: $(SingleChildScrollView),), true, 'Chat list is not scrollable',); } + + bool isPinAChat(TwakeListItemRobot takeListItem) { + final title = takeListItem.root.$(ChatListItemTitle); + const pinData = IconData(0xF2D7, fontFamily: 'MaterialIcons'); + final pinFinder = find.descendant(of: title, matching: find.byIcon(pinData)); + final pin = $(pinFinder); + return pin.exists; + } + + Future pinAChat(String title) async { + final twakeListItem = ChatListRobot($).getChatGroupByTitle(title); + if(!isPinAChat(twakeListItem)) + { + await twakeListItem.root.longPress(); + await $.waitUntilVisible(twakeListItem.getCheckBox()); + await ChatListRobot($).getPinIcon().tap(); + await ChatListRobot($).waitUntilAbsent($, ChatListRobot($).getPinIcon()); + } + } + + Future unPinAChat(String title) async { + final twakeListItem = ChatListRobot($).getChatGroupByTitle(title); + if(isPinAChat(twakeListItem)) + { + await twakeListItem.root.longPress(); + await $.waitUntilVisible(twakeListItem.getCheckBox()); + await ChatListRobot($).getUnPinIcon().tap(); + await ChatListRobot($).waitUntilAbsent($, ChatListRobot($).getUnPinIcon()); + } + } + + Future verifyAChatIsPin(String title, bool isPin) async { + final twakeListItem = ChatListRobot($).getChatGroupByTitle(title); + final exists = isPinAChat(twakeListItem); + expect(exists, isPin, reason: 'Expected pin=$isPin but got $exists for "$title"'); + } + } diff --git a/integration_test/tests/chat/chat_group_test.dart b/integration_test/tests/chat/chat_group_test.dart index ba1eaa4d2..08348d61a 100644 --- a/integration_test/tests/chat/chat_group_test.dart +++ b/integration_test/tests/chat/chat_group_test.dart @@ -6,6 +6,8 @@ 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'; @@ -179,4 +181,19 @@ void main() { }, ); + + TestBase().runPatrolTest( + description: 'Search for messages inside a chat', + test: ($) async { + //open chat and make some messages + final receiveMessage = (await prepareTwoMessages($)).$2; + final searchPharse = receiveMessage.substring(receiveMessage.indexOf("sent"), receiveMessage.length); + + //open a chat + await ChatDetailScenario($).makeASearch(searchPharse); + // verify info dialog is shown + final numberOfResult = (await ChatSearchViewRobot($).getListOfChatSeach()).length; + expect(numberOfResult == 2, isTrue, reason: "expect is 2 but got: $numberOfResult"); + }, + ); } diff --git a/integration_test/tests/chat/chat_list_test.dart b/integration_test/tests/chat/chat_list_test.dart index 4bcdaa130..a2d88c27b 100644 --- a/integration_test/tests/chat/chat_list_test.dart +++ b/integration_test/tests/chat/chat_list_test.dart @@ -84,4 +84,22 @@ void main() { reason: "expect the different is 1 but the second is $numberOfUnreadMessage2 and the first is $numberOfUnreadMessage1",); }, ); + + TestBase().runPatrolTest( + description: 'Pin/unpin a chat', + test: ($) async { + const groupTest = String.fromEnvironment('GroupTest'); + // goto chat screen + await HomeRobot($).gotoChatListScreen(); + // pin a chat + await ChatScenario($).pinAChat(groupTest); + // verify the chat is pin + await ChatScenario($).verifyAChatIsPin(groupTest, true); + + // unpin a chat + await ChatScenario($).unPinAChat(groupTest); + // verify the chat is unPin + await ChatScenario($).verifyAChatIsPin(groupTest, false); + }, + ); }