mirror of
https://github.com/linagora/tmail-flutter.git
synced 2026-12-05 16:08:46 +00:00
208 lines
6.6 KiB
Dart
208 lines
6.6 KiB
Dart
import 'package:core/presentation/views/search/search_bar_view.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:get/get.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/thread/presentation/thread_controller.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';
|
|
import '../utils/test_timeouts.dart';
|
|
import '../utils/wait_for_condition.dart';
|
|
import 'abstract/abstract_thread_assertion_robot.dart';
|
|
import 'abstract/abstract_thread_empty_trash_robot.dart';
|
|
import 'abstract/abstract_thread_selection_robot.dart';
|
|
import 'abstract/abstract_thread_viewport_robot.dart';
|
|
import 'thread_assertion_robot.dart';
|
|
import 'thread_empty_trash_robot.dart';
|
|
import 'thread_selection_robot.dart';
|
|
|
|
class ThreadRobot extends CoreRobot {
|
|
static const Duration _emailOpenPumpDuration = Duration(seconds: 2);
|
|
static const Duration _emailListRefreshInterval = Duration(seconds: 5);
|
|
|
|
final AbstractThreadAssertionRobot assertion;
|
|
final AbstractThreadEmptyTrashRobot emptyTrash;
|
|
final AbstractThreadSelectionRobot selection;
|
|
final AbstractThreadViewportRobot? viewport;
|
|
|
|
ThreadRobot(
|
|
PatrolIntegrationTester $, {
|
|
AbstractThreadEmptyTrashRobot? emptyTrashRobot,
|
|
AbstractThreadSelectionRobot? selectionRobot,
|
|
this.viewport,
|
|
}) : assertion = ThreadAssertionRobot($),
|
|
emptyTrash = emptyTrashRobot ?? ThreadEmptyTrashRobot($),
|
|
selection = selectionRobot ?? ThreadSelectionRobot($),
|
|
super($);
|
|
|
|
Future<void> openComposer() async {
|
|
await $(const ValueKey(UiKeys.composeEmailButton)).$(InkWell).tap();
|
|
}
|
|
|
|
Future<void> openSearchView() async {
|
|
await $(SearchBarView).$(InkWell).tap();
|
|
}
|
|
|
|
Future<void> tapOnSearchField() async {
|
|
await $(ThreadView).$(SearchBarView).tap();
|
|
}
|
|
|
|
Future<void> openEmailWithSubject(String subject) async {
|
|
final email = $(EmailTileBuilder)
|
|
.which<EmailTileBuilder>((view) => view.presentationEmail.subject == subject);
|
|
await openEmailTile(email);
|
|
}
|
|
|
|
Future<void> openEmailWithLabel(String labelDisplayName) async {
|
|
final email = $(EmailTileBuilder).which<EmailTileBuilder>(
|
|
(view) =>
|
|
view.labels
|
|
?.any((label) => label.safeDisplayName == labelDisplayName) ==
|
|
true,
|
|
);
|
|
await openEmailTile(email);
|
|
}
|
|
|
|
/// Provisioned emails go through asynchronous server-side delivery: the single
|
|
/// refresh issued right after provisioning may run before the email lands, and
|
|
/// nothing else is guaranteed to reload the list. Periodically re-query it
|
|
/// until the tile shows up. Each pump also yields to the event loop, which
|
|
/// waitUntilVisible's frame-only retry loop does not (web XHR callbacks).
|
|
Future<void> openEmailTile(PatrolFinder emailFinder) async {
|
|
final sinceLastRefresh = Stopwatch()..start();
|
|
await waitForCondition(
|
|
() async {
|
|
await $.pump();
|
|
if (emailFinder.evaluate().isNotEmpty) return true;
|
|
if (sinceLastRefresh.elapsed >= _emailListRefreshInterval) {
|
|
sinceLastRefresh.reset();
|
|
await Get.find<ThreadController>().refreshAllEmail();
|
|
}
|
|
return false;
|
|
},
|
|
timeout: TestTimeouts.long,
|
|
reason: 'email tile to appear in the list',
|
|
);
|
|
await emailFinder.tap();
|
|
await $.pump(_emailOpenPumpDuration);
|
|
}
|
|
|
|
Future<void> openMailbox() async {
|
|
await $(const ValueKey(UiKeys.mobileMailboxMenuButton)).tap();
|
|
}
|
|
|
|
Future<void> tapDeleteAllButtonOnEmptyTrashConfirmDialog(
|
|
AppLocalizations appLocalizations,
|
|
) => $(appLocalizations.delete_all).tap();
|
|
|
|
Future<void> scrollToEmailWithSubject(String subject) async {
|
|
await $.scrollUntilVisible(finder: $(subject), delta: 300);
|
|
await $.pumpAndSettle();
|
|
}
|
|
|
|
Future<void> scrollToTop() async {
|
|
await $(ScrollToTopButtonWidget).$(InkWell).tap();
|
|
await $.pumpAndSettle();
|
|
}
|
|
|
|
Future<void> openQuickFilter() async {
|
|
await $(#mobile_filter_message_button).tap();
|
|
}
|
|
|
|
Future<void> selectAttachmentFilter() async {
|
|
await $(#attachments_filter).tap();
|
|
}
|
|
|
|
Future<void> selectUnreadFilter() async {
|
|
await $(#unread_filter).tap();
|
|
}
|
|
|
|
Future<void> selectStarredFilter() async {
|
|
await $(#starred_filter).tap();
|
|
}
|
|
|
|
Future<void> pullToRefreshByEmailSubject(String subject) async {
|
|
await $(subject).waitUntilVisible();
|
|
await $.tester.fling(
|
|
$(subject),
|
|
const Offset(0, 300),
|
|
1000,
|
|
);
|
|
await $.pumpAndSettle();
|
|
}
|
|
|
|
Future<void> deepPullToRefreshByEmailSubject(String subject) async {
|
|
await $(subject).waitUntilVisible();
|
|
await $.tester.fling(
|
|
$(subject),
|
|
const Offset(0, 400),
|
|
2000,
|
|
);
|
|
await $.pumpAndSettle();
|
|
}
|
|
|
|
Future<void> tapOnMailboxWithName(String name) async {
|
|
await $(name).tap();
|
|
await $.pumpAndSettle();
|
|
}
|
|
|
|
Future<void> tapEmptySpamBanner() async {
|
|
await $(' ${AppLocalizations().deleteAllSpamEmailsNow}').tap();
|
|
}
|
|
|
|
Future<void> confirmEmptySpam() async {
|
|
await $(AppLocalizations().delete_all).tap();
|
|
}
|
|
|
|
Future<void> tapEmptyTrashAfterLongPress() async {
|
|
await $(AppLocalizations().emptyTrash).tap();
|
|
}
|
|
|
|
Future<void> tapConfirmEmptyTrashAfterLongPress() async {
|
|
await $(AppLocalizations().delete).tap();
|
|
await $.pumpAndSettle(duration: const Duration(seconds: 2));
|
|
}
|
|
|
|
Future<void> tapLabelAsButton() async {
|
|
await $(#moreAction_selected_email_button).tap();
|
|
await $.pumpAndTrySettle();
|
|
await $(#labelAs_action).tap();
|
|
}
|
|
|
|
Future<void> tapEmptySpamAfterLongPress() async {
|
|
await $(AppLocalizations().deleteAllSpamEmails).tap();
|
|
}
|
|
|
|
Future<void> moveEmailToMailboxWithName(String mailboxName) async {
|
|
await $(#moreAction_selected_email_button).tap();
|
|
|
|
await $(#moveToMailbox_action).tap();
|
|
|
|
await $(mailboxName).tap();
|
|
}
|
|
|
|
Future<void> moveEmailToTrash() async {
|
|
await $(#moveToTrash_selected_email_button).tap();
|
|
await $.pumpAndTrySettle();
|
|
}
|
|
|
|
Future<void> tapMarkAsReadButton() async {
|
|
await $(#markAsRead_selected_email_button).tap();
|
|
await $.pumpAndTrySettle();
|
|
}
|
|
|
|
|
|
Future<void> tapMarkAsSpamAction() async {
|
|
await $(#moreAction_selected_email_button).tap();
|
|
await $.pumpAndTrySettle();
|
|
await $(#moveToSpam_action).tap();
|
|
await $.pumpAndTrySettle();
|
|
}
|
|
}
|