Skip to content

Commit

Permalink
TF-3292 Write integration test for search emails by date and then sor…
Browse files Browse the repository at this point in the history
…t them by relevance
  • Loading branch information
dab246 authored and hoangdat committed Dec 2, 2024
1 parent eaee8a0 commit e59fc1f
Show file tree
Hide file tree
Showing 5 changed files with 189 additions and 10 deletions.
18 changes: 18 additions & 0 deletions integration_test/robots/search_robot.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,22 @@ class SearchRobot extends CoreRobot {
await $.waitUntilVisible($(AppLocalizations().showingResultsFor));
await $(AppLocalizations().showingResultsFor).tap();
}

Future<void> scrollToDateTimeButtonFilter() async {
await $.scrollUntilVisible(
finder: $(#mobile_dateTime_search_filter_button),
view: $(#search_filter_list_view),
scrollDirection: AxisDirection.right,
delta: 300,
);
}

Future<void> openDateTimeBottomDialog() async {
await $(#mobile_dateTime_search_filter_button).tap();
}

Future<void> selectDateTime(String dateTimeType) async {
await $(find.text(dateTimeType)).tap();
await $.pump(const Duration(seconds: 2));
}
}
Original file line number Diff line number Diff line change
@@ -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<ProvisioningEmail> listProvisioningEmail;

@override
Future<void> 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<void> _expectSearchViewVisible() async {
await expectViewVisible($(SearchEmailView));
}

Future<void> _expectSuggestionSearchListViewVisible() async {
await expectViewVisible($(#suggestion_search_list_view));
}

Future<void> _expectDateTimeSearchFilterButtonVisible() async {
await expectViewVisible($(#mobile_dateTime_search_filter_button));
}

Future<void> _expectDateTimeFilterContextMenuVisible() async {
await expectViewVisible($(#date_time_filter_context_menu));
}

Future<void> _expectSearchResultEmailListVisible() async {
await expectViewVisible($(#search_email_list_notification_listener));
}

Future<void> _expectSortFilterContextMenuVisible() async {
await expectViewVisible($(#sort_filter_context_menu));
}

Future<void> _expectEmailListDisplayedCorrectly() async {
expect(find.byType(EmailTileBuilder), findsNWidgets(listProvisioningEmail.length));
}
}
Original file line number Diff line number Diff line change
@@ -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();
},
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,8 @@ class SearchEmailView extends GetWidget<SearchEmailController>
context,
receiveTime
)
)
),
key: const Key('date_time_filter_context_menu'),
);
}

Expand Down

0 comments on commit e59fc1f

Please sign in to comment.