From eb538dac4bc412ae8ea276cb32ad53f514eef8e2 Mon Sep 17 00:00:00 2001 From: "Dat H. Pham" Date: Wed, 3 Jun 2026 10:11:35 +0700 Subject: [PATCH] Search suggestion highlight (#4565) --- .../factories/mobile_robot_factory.dart | 5 +++ integration_test/factories/robot_factory.dart | 2 ++ .../factories/web_robot_factory.dart | 5 +++ .../abstract/abstract_search_robot.dart | 4 +++ .../abstract/abstract_thread_robot.dart | 1 + .../robots/mobile/mobile_search_robot.dart | 17 ++++++++++ integration_test/robots/search_robot.dart | 2 +- .../robots/web/web_search_robot.dart | 32 +++++++++++++++++++ .../robots/web/web_thread_robot.dart | 31 ++++++++++++++++-- ...search_suggestion_highlights_scenario.dart | 27 ++++++---------- .../search_suggestion_highlights_test.dart | 4 ++- 11 files changed, 107 insertions(+), 23 deletions(-) create mode 100644 integration_test/robots/abstract/abstract_search_robot.dart create mode 100644 integration_test/robots/mobile/mobile_search_robot.dart create mode 100644 integration_test/robots/web/web_search_robot.dart diff --git a/integration_test/factories/mobile_robot_factory.dart b/integration_test/factories/mobile_robot_factory.dart index 34d61d598..da1da19d3 100644 --- a/integration_test/factories/mobile_robot_factory.dart +++ b/integration_test/factories/mobile_robot_factory.dart @@ -9,6 +9,7 @@ import '../robots/abstract/abstract_email_robot.dart'; import '../robots/abstract/abstract_login_robot.dart'; import '../robots/abstract/abstract_mailbox_menu_robot.dart'; import '../robots/abstract/abstract_rules_filter_creator_robot.dart'; +import '../robots/abstract/abstract_search_robot.dart'; import '../robots/abstract/abstract_thread_robot.dart'; import '../robots/mobile/mobile_app_grid_robot.dart'; import '../robots/mobile/mobile_composer_robot.dart'; @@ -17,6 +18,7 @@ import '../robots/mobile/mobile_email_robot.dart'; import '../robots/mobile/mobile_login_robot.dart'; import '../robots/mobile/mobile_mailbox_menu_robot.dart'; import '../robots/mobile/mobile_rules_filter_creator_robot.dart'; +import '../robots/mobile/mobile_search_robot.dart'; import '../robots/mobile/mobile_thread_robot.dart'; import 'robot_factory.dart'; @@ -51,4 +53,7 @@ class MobileRobotFactory implements RobotFactory { @override AbstractEmailRobot emailRobot() => MobileEmailRobot($); + + @override + AbstractSearchRobot searchRobot() => MobileSearchRobot($); } diff --git a/integration_test/factories/robot_factory.dart b/integration_test/factories/robot_factory.dart index 910e7fb7a..65eed06a0 100644 --- a/integration_test/factories/robot_factory.dart +++ b/integration_test/factories/robot_factory.dart @@ -6,6 +6,7 @@ import '../robots/abstract/abstract_email_robot.dart'; import '../robots/abstract/abstract_login_robot.dart'; import '../robots/abstract/abstract_mailbox_menu_robot.dart'; import '../robots/abstract/abstract_rules_filter_creator_robot.dart'; +import '../robots/abstract/abstract_search_robot.dart'; import '../robots/abstract/abstract_thread_robot.dart'; abstract class RobotFactory { @@ -18,4 +19,5 @@ abstract class RobotFactory { AbstractRulesFilterCreatorRobot rulesFilterCreatorRobot(); AbstractEmailRulesSettingRobot emailRulesSettingRobot(); AbstractEmailRobot emailRobot(); + AbstractSearchRobot searchRobot(); } diff --git a/integration_test/factories/web_robot_factory.dart b/integration_test/factories/web_robot_factory.dart index 8102ba858..99faf87af 100644 --- a/integration_test/factories/web_robot_factory.dart +++ b/integration_test/factories/web_robot_factory.dart @@ -10,6 +10,7 @@ import '../robots/abstract/abstract_email_robot.dart'; import '../robots/abstract/abstract_login_robot.dart'; import '../robots/abstract/abstract_mailbox_menu_robot.dart'; import '../robots/abstract/abstract_rules_filter_creator_robot.dart'; +import '../robots/abstract/abstract_search_robot.dart'; import '../robots/abstract/abstract_thread_robot.dart'; import '../robots/web/web_app_grid_robot.dart'; import '../robots/web/web_composer_robot.dart'; @@ -17,6 +18,7 @@ import '../robots/web/web_email_rules_setting_robot.dart'; import '../robots/web/web_login_robot.dart'; import '../robots/web/web_mailbox_menu_robot.dart'; import '../robots/web/web_rules_filter_creator_robot.dart'; +import '../robots/web/web_search_robot.dart'; import '../robots/web/web_thread_robot.dart'; import 'robot_factory.dart'; @@ -51,4 +53,7 @@ class WebRobotFactory implements RobotFactory { @override AbstractEmailRobot emailRobot() => WebEmailRobot($); + + @override + AbstractSearchRobot searchRobot() => WebSearchRobot($); } diff --git a/integration_test/robots/abstract/abstract_search_robot.dart b/integration_test/robots/abstract/abstract_search_robot.dart new file mode 100644 index 000000000..b8b9cbe90 --- /dev/null +++ b/integration_test/robots/abstract/abstract_search_robot.dart @@ -0,0 +1,4 @@ +abstract class AbstractSearchRobot { + Future enterKeyword(String keyword); + Future verifySearchSuggestionHighlights(String keyword); +} diff --git a/integration_test/robots/abstract/abstract_thread_robot.dart b/integration_test/robots/abstract/abstract_thread_robot.dart index 37df61354..0f3396f06 100644 --- a/integration_test/robots/abstract/abstract_thread_robot.dart +++ b/integration_test/robots/abstract/abstract_thread_robot.dart @@ -4,4 +4,5 @@ abstract class AbstractThreadRobot { Future openAppGrid(); Future openMailbox(); Future openEmailWithSubject(String subject); + Future tapOnSearchField(); } diff --git a/integration_test/robots/mobile/mobile_search_robot.dart b/integration_test/robots/mobile/mobile_search_robot.dart new file mode 100644 index 000000000..4fdb6fae1 --- /dev/null +++ b/integration_test/robots/mobile/mobile_search_robot.dart @@ -0,0 +1,17 @@ +import 'package:patrol/patrol.dart'; +import 'package:core/presentation/views/text/rich_text_builder.dart'; +import 'package:flutter_test/flutter_test.dart'; + +import '../abstract/abstract_search_robot.dart'; +import '../search_robot.dart'; + +class MobileSearchRobot extends SearchRobot implements AbstractSearchRobot { + MobileSearchRobot(PatrolIntegrationTester $) : super($); + + @override + Future verifySearchSuggestionHighlights(String keyword) async { + // Mobile: SearchEmailView renders suggestions directly in its widget tree + await $.waitUntilVisible($(RichTextBuilder)); + expect($(RichTextBuilder).$(keyword.split(' ').first).evaluate().length, 10); + } +} diff --git a/integration_test/robots/search_robot.dart b/integration_test/robots/search_robot.dart index fa94a1c07..014125457 100644 --- a/integration_test/robots/search_robot.dart +++ b/integration_test/robots/search_robot.dart @@ -1,6 +1,6 @@ +import 'package:core/presentation/views/text/text_field_builder.dart'; import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; -import 'package:core/presentation/views/text/text_field_builder.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'; diff --git a/integration_test/robots/web/web_search_robot.dart b/integration_test/robots/web/web_search_robot.dart new file mode 100644 index 000000000..bafbce5df --- /dev/null +++ b/integration_test/robots/web/web_search_robot.dart @@ -0,0 +1,32 @@ +import 'package:core/presentation/views/text/rich_text_builder.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:patrol/patrol.dart'; +import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/widgets/quick_search/email_quick_search_item_tile_widget.dart'; +import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/widgets/search_input_form_widget.dart'; + +import '../../extensions/patrol_finder_extension.dart'; +import '../abstract/abstract_search_robot.dart'; +import '../search_robot.dart'; + +class WebSearchRobot extends SearchRobot implements AbstractSearchRobot { + WebSearchRobot(PatrolIntegrationTester $) : super($); + + @override + Future enterKeyword(String keyword) async { + final finder = $(SearchInputFormWidget).$(TextField); + await finder.tap(); + await finder.enterTextWithoutTapAction(keyword); + } + + @override + Future verifySearchSuggestionHighlights(String keyword) async { + // Web: suggestions render inside an OverlayEntry wrapped by PointerInterceptor, + // so they are not hit-testable. Use waitUntilExists instead of waitUntilVisible. + await $.waitUntilExists($(EmailQuickSearchItemTileWidget)); + expect( + $(EmailQuickSearchItemTileWidget).$(RichTextBuilder).evaluate().isNotEmpty, + isTrue, + ); + } +} diff --git a/integration_test/robots/web/web_thread_robot.dart b/integration_test/robots/web/web_thread_robot.dart index 204182d16..103243277 100644 --- a/integration_test/robots/web/web_thread_robot.dart +++ b/integration_test/robots/web/web_thread_robot.dart @@ -1,12 +1,14 @@ -import 'package:flutter/foundation.dart'; +import 'package:flutter/material.dart'; import 'package:labels/extensions/label_extension.dart'; import 'package:patrol/patrol.dart'; import 'package:tmail_ui_user/features/base/model/ui_keys.dart'; +import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/widgets/search_input_form_widget.dart'; import 'package:tmail_ui_user/features/thread/presentation/widgets/email_tile_web_builder.dart'; -import '../mobile/mobile_thread_robot.dart'; +import '../abstract/abstract_thread_robot.dart'; +import '../thread_robot.dart'; -class WebThreadRobot extends MobileThreadRobot { +class WebThreadRobot extends ThreadRobot implements AbstractThreadRobot { WebThreadRobot(super.$); static const Duration _emailOpenPumpDuration = Duration(seconds: 2); @@ -16,6 +18,11 @@ class WebThreadRobot extends MobileThreadRobot { await $(const ValueKey(UiKeys.toggleAppGridButton)).waitUntilVisible(); } + @override + Future openAppGrid() async { + await $(const ValueKey(UiKeys.toggleAppGridButton)).tap(); + } + @override Future openEmailWithSubject(String subject) async { final email = $(EmailTileBuilder).which( @@ -37,6 +44,24 @@ class WebThreadRobot extends MobileThreadRobot { await _openEmailTile(email); } + @override + Future tapOnSearchField() async { + await $(SearchInputFormWidget).$(TextField).tap(); + // Give the dashboard's background sync (Email/changes, Mailbox/changes, + // triggered by the test's email provisioning) time to finish before typing. + // + // Quick-search suggestions are held in a transient overlay widget. If a sync + // response arrives while the suggestion request is in flight, the dashboard + // rebuilds and disposes that overlay, so the returned suggestions are dropped + // and no tiles ever render — the test then fails even though the search worked. + // + // This is a wall-clock wait on purpose: the dependency is real backend/network + // time, which pumpAndSettle()/waitForCondition() cannot observe (the Flutter + // frame scheduler goes idle between network responses, so they return too early). + // Scoped to web only; it does not affect mobile or production code. + await $.pump(const Duration(seconds: 3)); + } + Future _openEmailTile(PatrolFinder emailFinder) async { await $.waitUntilVisible(emailFinder); await emailFinder.tap(); diff --git a/integration_test/scenarios/search_suggestion_highlights_scenario.dart b/integration_test/scenarios/search_suggestion_highlights_scenario.dart index cb7479fbe..d555316ac 100644 --- a/integration_test/scenarios/search_suggestion_highlights_scenario.dart +++ b/integration_test/scenarios/search_suggestion_highlights_scenario.dart @@ -1,10 +1,5 @@ -import 'package:core/presentation/views/text/rich_text_builder.dart'; -import 'package:flutter_test/flutter_test.dart'; - import '../base/base_test_scenario.dart'; import '../models/provisioning_email.dart'; -import '../robots/search_robot.dart'; -import '../robots/thread_robot.dart'; class SearchSuggestionHighlightsScenario extends BaseTestScenario { SearchSuggestionHighlightsScenario(super.$, super.robots); @@ -19,33 +14,29 @@ class SearchSuggestionHighlightsScenario extends BaseTestScenario { @override Future runTestLogic() async { const email = String.fromEnvironment('BASIC_AUTH_EMAIL'); - // Robots - final threadRobot = ThreadRobot($); - final searchRobot = SearchRobot($); - // Prepare attachment file - final file = await preparingTxtFile(keyword); + final commonRobot = robots.commonRobot(); + final threadRobot = robots.threadRobot(); + final searchRobot = robots.searchRobot(); - // Provisioning some emails - await provisionEmail(longEmailContents + final file = await commonRobot.prepareTxtFile(keyword); + + await commonRobot.provisionEmail(longEmailContents .map( (emailContent) => ProvisioningEmail( toEmail: email, subject: keyword, content: emailContent, - attachmentPaths: emailContent == longEmailContents.first - ? [file.path] + fileInfos: emailContent == longEmailContents.first + ? [file] : [], ), ) .toList()); await $.waitUntilVisible($(keyword)); - // Search await threadRobot.tapOnSearchField(); await searchRobot.enterKeyword(keyword); - await $.waitUntilVisible($(RichTextBuilder)); - // Maximum 10 suggestions - expect($(RichTextBuilder).$(keyword.split(' ').first).evaluate().length, 10); + await searchRobot.verifySearchSuggestionHighlights(keyword); } } \ No newline at end of file diff --git a/integration_test/tests/search/search_suggestion_highlights_test.dart b/integration_test/tests/search/search_suggestion_highlights_test.dart index b3011a779..814dbc2a5 100644 --- a/integration_test/tests/search/search_suggestion_highlights_test.dart +++ b/integration_test/tests/search/search_suggestion_highlights_test.dart @@ -1,9 +1,11 @@ import '../../base/test_base.dart'; +import '../../models/test_tags.dart'; import '../../scenarios/search_suggestion_highlights_scenario.dart'; void main() { TestBase().runPatrolTest( description: 'Should see highlighted keyword in search suggestion', scenarioBuilder: ($, robots) => SearchSuggestionHighlightsScenario($, robots), + tags: [TestTags.android, TestTags.ios, TestTags.web], ); -} \ No newline at end of file +}