From c4fe2029994ad1fdcd70ac2bf62881afc37ef5cf Mon Sep 17 00:00:00 2001 From: dab246 Date: Wed, 27 Nov 2024 12:31:03 +0700 Subject: [PATCH] TF-3292 Write integration test for search emails by date and then sort them by relevance --- integration_test/robots/search_robot.dart | 18 ++++ ...ime_and_sort_order_relevance_scenario.dart | 101 ++++++++++++++++++ ...te_time_and_sort_order_relevance_test.dart | 44 ++++++++ .../model/search/email_receive_time_type.dart | 33 ++++-- .../email/presentation/search_email_view.dart | 3 +- 5 files changed, 189 insertions(+), 10 deletions(-) create mode 100644 integration_test/scenarios/search_email_by_date_time_and_sort_order_relevance_scenario.dart create mode 100644 integration_test/tests/search/search_email_by_date_time_and_sort_order_relevance_test.dart diff --git a/integration_test/robots/search_robot.dart b/integration_test/robots/search_robot.dart index 549ad0f605..cd98d39721 100644 --- a/integration_test/robots/search_robot.dart +++ b/integration_test/robots/search_robot.dart @@ -39,4 +39,22 @@ class SearchRobot extends CoreRobot { await $.waitUntilVisible($(AppLocalizations().showingResultsFor)); await $(AppLocalizations().showingResultsFor).tap(); } + + Future scrollToDateTimeButtonFilter() async { + await $.scrollUntilVisible( + finder: $(#mobile_dateTime_search_filter_button), + view: $(#search_filter_list_view), + scrollDirection: AxisDirection.right, + delta: 300, + ); + } + + Future openDateTimeBottomDialog() async { + await $(#mobile_dateTime_search_filter_button).tap(); + } + + Future selectDateTime(String dateTimeType) async { + await $(find.text(dateTimeType)).tap(); + await $.pump(const Duration(seconds: 2)); + } } \ No newline at end of file diff --git a/integration_test/scenarios/search_email_by_date_time_and_sort_order_relevance_scenario.dart b/integration_test/scenarios/search_email_by_date_time_and_sort_order_relevance_scenario.dart new file mode 100644 index 0000000000..22a1e1295a --- /dev/null +++ b/integration_test/scenarios/search_email_by_date_time_and_sort_order_relevance_scenario.dart @@ -0,0 +1,101 @@ + +import 'package:flutter_test/flutter_test.dart'; +import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/model/search/email_receive_time_type.dart'; +import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/model/search/email_sort_order_type.dart'; +import 'package:tmail_ui_user/features/search/email/presentation/search_email_view.dart'; +import 'package:tmail_ui_user/features/thread/presentation/widgets/email_tile_builder.dart'; +import 'package:tmail_ui_user/main/localizations/app_localizations.dart'; + +import '../base/base_scenario.dart'; +import '../models/provisioning_email.dart'; +import '../robots/search_robot.dart'; +import '../robots/thread_robot.dart'; +import '../utils/scenario_utils_mixin.dart'; +import 'login_with_basic_auth_scenario.dart'; + +class SearchEmailByDatetimeAndSortOrderRelevanceScenario extends BaseScenario + with ScenarioUtilsMixin { + + const SearchEmailByDatetimeAndSortOrderRelevanceScenario( + super.$, + { + required this.loginWithBasicAuthScenario, + required this.queryString, + required this.listProvisioningEmail, + } + ); + + final LoginWithBasicAuthScenario loginWithBasicAuthScenario; + final String queryString; + final List listProvisioningEmail; + + @override + Future execute() async { + await loginWithBasicAuthScenario.execute(); + + await provisionEmail(listProvisioningEmail); + await $.pumpAndSettle(); + + final threadRobot = ThreadRobot($); + await threadRobot.openSearchView(); + await _expectSearchViewVisible(); + + final searchRobot = SearchRobot($); + await searchRobot.enterQueryString(queryString); + await _expectSuggestionSearchListViewVisible(); + + await searchRobot.scrollToDateTimeButtonFilter(); + await _expectDateTimeSearchFilterButtonVisible(); + + await Future.delayed(const Duration(seconds: 2)); + + await searchRobot.openDateTimeBottomDialog(); + await _expectDateTimeFilterContextMenuVisible(); + + final appLocalizations = AppLocalizations(); + await searchRobot.selectDateTime( + EmailReceiveTimeType.last7Days.getTitleByAppLocalizations(appLocalizations), + ); + await _expectSearchResultEmailListVisible(); + + await Future.delayed(const Duration(seconds: 2)); + + await searchRobot.openSortOrderBottomDialog(); + await _expectSortFilterContextMenuVisible(); + await searchRobot.selectSortOrder( + EmailSortOrderType.relevance.getTitleByAppLocalizations(appLocalizations), + ); + await _expectSearchResultEmailListVisible(); + + await _expectEmailListDisplayedCorrectly(); + } + + + Future _expectSearchViewVisible() async { + await expectViewVisible($(SearchEmailView)); + } + + Future _expectSuggestionSearchListViewVisible() async { + await expectViewVisible($(#suggestion_search_list_view)); + } + + Future _expectDateTimeSearchFilterButtonVisible() async { + await expectViewVisible($(#mobile_dateTime_search_filter_button)); + } + + Future _expectDateTimeFilterContextMenuVisible() async { + await expectViewVisible($(#date_time_filter_context_menu)); + } + + Future _expectSearchResultEmailListVisible() async { + await expectViewVisible($(#search_email_list_notification_listener)); + } + + Future _expectSortFilterContextMenuVisible() async { + await expectViewVisible($(#sort_filter_context_menu)); + } + + Future _expectEmailListDisplayedCorrectly() async { + expect(find.byType(EmailTileBuilder), findsNWidgets(listProvisioningEmail.length)); + } +} \ No newline at end of file diff --git a/integration_test/tests/search/search_email_by_date_time_and_sort_order_relevance_test.dart b/integration_test/tests/search/search_email_by_date_time_and_sort_order_relevance_test.dart new file mode 100644 index 0000000000..6fd8e39875 --- /dev/null +++ b/integration_test/tests/search/search_email_by_date_time_and_sort_order_relevance_test.dart @@ -0,0 +1,44 @@ +import '../../base/test_base.dart'; +import '../../models/provisioning_email.dart'; +import '../../scenarios/login_with_basic_auth_scenario.dart'; +import '../../scenarios/search_email_by_date_time_and_sort_order_relevance_scenario.dart'; + +void main() { + TestBase().runPatrolTest( + description: 'Should see list email displayed by date time `Last 7 days` and sort order `Relevance` when search email successfully', + test: ($) async { + const username = String.fromEnvironment('USERNAME'); + const password = String.fromEnvironment('PASSWORD'); + const hostUrl = String.fromEnvironment('BASIC_AUTH_URL'); + const email = String.fromEnvironment('BASIC_AUTH_EMAIL'); + + final loginWithBasicAuthScenario = LoginWithBasicAuthScenario( + $, + username: username, + password: password, + hostUrl: hostUrl, + email: email, + ); + + const queryString = 'relevance'; + const listUsername = ['Alice', 'Brian', 'Charlotte', 'David', 'Emma']; + + final listProvisioningEmail = listUsername + .map((username) => ProvisioningEmail( + toEmail: '${username.toLowerCase()}@example.com', + subject: queryString, + content: '$queryString to user $username', + )) + .toList(); + + final searchEmailByDatetimeAndSortOrderRelevanceScenario = SearchEmailByDatetimeAndSortOrderRelevanceScenario( + $, + loginWithBasicAuthScenario: loginWithBasicAuthScenario, + queryString: queryString, + listProvisioningEmail: listProvisioningEmail, + ); + + await searchEmailByDatetimeAndSortOrderRelevanceScenario.execute(); + }, + ); +} \ No newline at end of file diff --git a/lib/features/mailbox_dashboard/presentation/model/search/email_receive_time_type.dart b/lib/features/mailbox_dashboard/presentation/model/search/email_receive_time_type.dart index b54d7bcf60..7f16167b66 100644 --- a/lib/features/mailbox_dashboard/presentation/model/search/email_receive_time_type.dart +++ b/lib/features/mailbox_dashboard/presentation/model/search/email_receive_time_type.dart @@ -13,26 +13,41 @@ enum EmailReceiveTimeType { customRange; String getTitle(BuildContext context, {DateTime? startDate, DateTime? endDate}) { + return getTitleByAppLocalizations( + AppLocalizations.of(context), + startDate: startDate, + endDate: endDate, + ); + } + + String getTitleByAppLocalizations( + AppLocalizations appLocalizations, + { + DateTime? startDate, + DateTime? endDate, + } + ) { switch(this) { case EmailReceiveTimeType.allTime: - return AppLocalizations.of(context).allTime; + return appLocalizations.allTime; case EmailReceiveTimeType.last7Days: - return AppLocalizations.of(context).last7Days; + return appLocalizations.last7Days; case EmailReceiveTimeType.last30Days: - return AppLocalizations.of(context).last30Days; + return appLocalizations.last30Days; case EmailReceiveTimeType.last6Months: - return AppLocalizations.of(context).last6Months; + return appLocalizations.last6Months; case EmailReceiveTimeType.lastYear: - return AppLocalizations.of(context).lastYears; + return appLocalizations.lastYears; case EmailReceiveTimeType.customRange: if (startDate != null && endDate != null) { final startDateString = startDate.formatDate(pattern: 'yyyy-dd-MM'); final endDateString = endDate.formatDate(pattern: 'yyyy-dd-MM'); - return AppLocalizations.of(context).dateRangeAdvancedSearchFilter( - startDateString, - endDateString); + return appLocalizations.dateRangeAdvancedSearchFilter( + startDateString, + endDateString, + ); } else { - return AppLocalizations.of(context).customRange; + return appLocalizations.customRange; } } } diff --git a/lib/features/search/email/presentation/search_email_view.dart b/lib/features/search/email/presentation/search_email_view.dart index 264f741c80..262e6deb75 100644 --- a/lib/features/search/email/presentation/search_email_view.dart +++ b/lib/features/search/email/presentation/search_email_view.dart @@ -355,7 +355,8 @@ class SearchEmailView extends GetWidget context, receiveTime ) - ) + ), + key: const Key('date_time_filter_context_menu'), ); }