diff --git a/integration_test/robots/thread_robot.dart b/integration_test/robots/thread_robot.dart index 93356ef6f..f3d1f7045 100644 --- a/integration_test/robots/thread_robot.dart +++ b/integration_test/robots/thread_robot.dart @@ -4,6 +4,7 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:tmail_ui_user/features/base/widget/compose_floating_button.dart'; import 'package:tmail_ui_user/features/thread/presentation/thread_view.dart'; import 'package:tmail_ui_user/features/thread/presentation/widgets/email_tile_builder.dart'; +import 'package:tmail_ui_user/features/thread/presentation/widgets/scroll_to_top_button_widget.dart'; import 'package:tmail_ui_user/main/localizations/app_localizations.dart'; import '../base/core_robot.dart'; @@ -40,4 +41,14 @@ class ThreadRobot extends CoreRobot { Future tapDeleteAllButtonOnEmptyTrashConfirmDialog( AppLocalizations appLocalizations, ) => $(appLocalizations.delete_all).tap(); + + Future scrollToEmailWithSubject(String subject) async { + await $.scrollUntilVisible(finder: $(subject), delta: 300); + await $.pumpAndSettle(); + } + + Future scrollToTop() async { + await $(ScrollToTopButtonWidget).$(InkWell).tap(); + await $.pumpAndSettle(); + } } \ No newline at end of file diff --git a/integration_test/scenarios/mailbox/scroll_list_email_in_mailbox_and_back_to_top_scenario.dart b/integration_test/scenarios/mailbox/scroll_list_email_in_mailbox_and_back_to_top_scenario.dart new file mode 100644 index 000000000..407fd3cce --- /dev/null +++ b/integration_test/scenarios/mailbox/scroll_list_email_in_mailbox_and_back_to_top_scenario.dart @@ -0,0 +1,51 @@ +import 'package:flutter_test/flutter_test.dart'; +import 'package:tmail_ui_user/features/thread/presentation/widgets/scroll_to_top_button_widget.dart'; + +import '../../base/base_test_scenario.dart'; +import '../../models/provisioning_email.dart'; +import '../../robots/thread_robot.dart'; + +class ScrollListEmailInMailboxAndBackToTopScenario extends BaseTestScenario { + const ScrollListEmailInMailboxAndBackToTopScenario(super.$); + + String _getSubjectWithIndex(int emailIndex) => 'scroll email subject $emailIndex'; + + @override + Future runTestLogic() async { + const email = String.fromEnvironment('BASIC_AUTH_EMAIL'); + const totalEmails = 15; + const bottomEmailSubject = 'scroll email subject bottom'; + + final threadRobot = ThreadRobot($); + + await provisionEmail([ProvisioningEmail( + toEmail: email, + subject: bottomEmailSubject, + content: '', + )]); + await $.pumpAndSettle(duration: const Duration(seconds: 2)); + await provisionEmail(List.generate( + totalEmails, + (index) => ProvisioningEmail( + toEmail: email, + subject: _getSubjectWithIndex(index), + content: '$index', + ), + )); + await $.pumpAndSettle(duration: const Duration(seconds: 2)); + + await threadRobot.scrollToEmailWithSubject(bottomEmailSubject); + await _expectScrollToTopButtonVisible(); + + await threadRobot.scrollToTop(); + await _expectScrollToTopButtonInvisible(); + } + + _expectScrollToTopButtonVisible() { + expect($(ScrollToTopButtonWidget), findsOneWidget); + } + + Future _expectScrollToTopButtonInvisible() async { + expect($(ScrollToTopButtonWidget).visible, false); + } +} \ No newline at end of file diff --git a/integration_test/tests/mailbox/scroll_list_email_in_mailbox_and_back_to_top_test.dart b/integration_test/tests/mailbox/scroll_list_email_in_mailbox_and_back_to_top_test.dart new file mode 100644 index 000000000..7b7619b35 --- /dev/null +++ b/integration_test/tests/mailbox/scroll_list_email_in_mailbox_and_back_to_top_test.dart @@ -0,0 +1,10 @@ +import '../../base/test_base.dart'; +import '../../scenarios/mailbox/scroll_list_email_in_mailbox_and_back_to_top_scenario.dart'; + +void main() { + TestBase().runPatrolTest( + description: 'Should see back to top button when scroll list email in mailbox to bottom ' + 'and not see back to top button when scroll list email to top', + scenarioBuilder: ($) => ScrollListEmailInMailboxAndBackToTopScenario($), + ); +} \ No newline at end of file