diff --git a/pubspec.lock b/pubspec.lock index d0aad58c07..67b1c05248 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -1363,11 +1363,11 @@ packages: dependency: "direct main" description: path: "." - ref: tmail_supported - resolved-ref: b7896cfd236375d194cfd727cd9fd8af95df28a0 - url: "https://github.com/dab246/flutter_pdf_render.git" + ref: twake_supported + resolved-ref: "6790dd9a39e245e507e333e74e6b59292a0eab3d" + url: "https://github.com/linagora/flutter_pdf_render.git" source: git - version: "1.4.5" + version: "1.4.7" pdf_widget_wrapper: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 8eccf682eb..cc40f7f077 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -101,8 +101,8 @@ dependencies: pdf_render: git: - url: https://github.com/dab246/flutter_pdf_render.git - ref: tmail_supported + url: https://github.com/linagora/flutter_pdf_render.git + ref: twake_supported ### Dependencies from pub.dev ### cupertino_icons: 1.0.6 diff --git a/test/features/email/presentation/controller/single_email_controller_test.dart b/test/features/email/presentation/controller/single_email_controller_test.dart new file mode 100644 index 0000000000..4c3d502a04 --- /dev/null +++ b/test/features/email/presentation/controller/single_email_controller_test.dart @@ -0,0 +1,239 @@ +import 'package:core/core.dart'; +import 'package:dartz/dartz.dart' hide State; +import 'package:flutter_test/flutter_test.dart'; +import 'package:get/get.dart'; +import 'package:jmap_dart_client/jmap/account_id.dart'; +import 'package:jmap_dart_client/jmap/core/id.dart'; +import 'package:jmap_dart_client/jmap/mail/calendar/calendar_event.dart'; +import 'package:mockito/annotations.dart'; +import 'package:mockito/mockito.dart'; +import 'package:tmail_ui_user/features/caching/caching_manager.dart'; +import 'package:tmail_ui_user/features/email/domain/model/event_action.dart'; +import 'package:tmail_ui_user/features/email/domain/state/parse_calendar_event_state.dart'; +import 'package:tmail_ui_user/features/email/domain/usecases/calendar_event_accept_interactor.dart'; +import 'package:tmail_ui_user/features/email/domain/usecases/maybe_calendar_event_interactor.dart'; +import 'package:tmail_ui_user/features/email/domain/usecases/calendar_event_reject_interactor.dart'; +import 'package:tmail_ui_user/features/email/domain/usecases/download_attachment_for_web_interactor.dart'; +import 'package:tmail_ui_user/features/email/domain/usecases/download_attachments_interactor.dart'; +import 'package:tmail_ui_user/features/email/domain/usecases/export_attachment_interactor.dart'; +import 'package:tmail_ui_user/features/email/domain/usecases/get_email_content_interactor.dart'; +import 'package:tmail_ui_user/features/email/domain/usecases/mark_as_email_read_interactor.dart'; +import 'package:tmail_ui_user/features/email/domain/usecases/mark_as_star_email_interactor.dart'; +import 'package:tmail_ui_user/features/email/domain/usecases/move_to_mailbox_interactor.dart'; +import 'package:tmail_ui_user/features/email/domain/usecases/print_email_interactor.dart'; +import 'package:tmail_ui_user/features/email/domain/usecases/store_opened_email_interactor.dart'; +import 'package:tmail_ui_user/features/email/presentation/controller/email_supervisor_controller.dart'; +import 'package:tmail_ui_user/features/email/presentation/controller/single_email_controller.dart'; +import 'package:tmail_ui_user/features/email/presentation/model/blob_calendar_event.dart'; +import 'package:tmail_ui_user/features/login/data/network/interceptors/authorization_interceptors.dart'; +import 'package:tmail_ui_user/features/login/domain/usecases/delete_authority_oidc_interactor.dart'; +import 'package:tmail_ui_user/features/login/domain/usecases/delete_credential_interactor.dart'; +import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/controller/mailbox_dashboard_controller.dart'; +import 'package:tmail_ui_user/features/manage_account/data/local/language_cache_manager.dart'; +import 'package:tmail_ui_user/features/manage_account/domain/usecases/get_all_identities_interactor.dart'; +import 'package:tmail_ui_user/features/manage_account/domain/usecases/log_out_oidc_interactor.dart'; +import 'package:tmail_ui_user/main/bindings/network/binding_tag.dart'; +import 'package:uuid/uuid.dart'; + +import 'single_email_controller_test.mocks.dart'; + +mockControllerCallback() => InternalFinalCallback(callback: () {}); +const fallbackGenerators = { + #onStart: mockControllerCallback, + #onDelete: mockControllerCallback, +}; + +@GenerateNiceMocks([ + MockSpec(), + MockSpec(), + MockSpec(), + MockSpec(), + MockSpec(), + MockSpec(), + MockSpec(), + MockSpec(), + MockSpec(), + MockSpec(), + MockSpec(fallbackGenerators: fallbackGenerators), + MockSpec(fallbackGenerators: fallbackGenerators), + MockSpec(fallbackGenerators: fallbackGenerators), + MockSpec(fallbackGenerators: fallbackGenerators), + MockSpec(fallbackGenerators: fallbackGenerators), + MockSpec(), + MockSpec(), + MockSpec(), + MockSpec(), + MockSpec(), + MockSpec(), + MockSpec(), + MockSpec(), + MockSpec(), + MockSpec(), + MockSpec(), + MockSpec(), + MockSpec(), + MockSpec(), +]) +void main() { + TestWidgetsFlutterBinding.ensureInitialized(); + + final getEmailContentInteractor = MockGetEmailContentInteractor(); + final markAsEmailReadInteractor = MockMarkAsEmailReadInteractor(); + final downloadAttachmentsInteractor = MockDownloadAttachmentsInteractor(); + final deviceManager = MockDeviceManager(); + final exportAttachmentInteractor = MockExportAttachmentInteractor(); + final moveToMailboxInteractor = MockMoveToMailboxInteractor(); + final markAsStarEmailInteractor = MockMarkAsStarEmailInteractor(); + final downloadAttachmentForWebInteractor = + MockDownloadAttachmentForWebInteractor(); + final getAllIdentitiesInteractor = MockGetAllIdentitiesInteractor(); + final storeOpenedEmailInteractor = MockStoreOpenedEmailInteractor(); + final mailboxDashboardController = MockMailboxDashBoardController(); + final emailSupervisorController = MockEmailSupervisorController(); + final downloadManager = MockDownloadManager(); + final cachingManager = MockCachingManager(); + final languageCacheManager = MockLanguageCacheManager(); + final authorizationInterceptors = MockAuthorizationInterceptors(); + final dynamicUrlInterceptors = MockDynamicUrlInterceptors(); + final deleteCredentialInteractor = MockDeleteCredentialInteractor(); + final logoutOidcInteractor = MockLogoutOidcInteractor(); + final deleteAuthorityOidcInteractor = MockDeleteAuthorityOidcInteractor(); + final appToast = MockAppToast(); + final imagePaths = MockImagePaths(); + final responsiveUtils = MockResponsiveUtils(); + final uuid = MockUuid(); + final printEmailInteractor = MockPrintEmailInteractor(); + final printUtils = MockPrintUtils(); + + late SingleEmailController singleEmailController; + + final testAccountId = AccountId(Id('123')); + const testTaskId = 'taskId'; + + setUpAll(() { + Get.put(mailboxDashboardController); + Get.put(emailSupervisorController); + Get.put(downloadManager); + Get.put(cachingManager); + Get.put(languageCacheManager); + Get.put(authorizationInterceptors); + Get.put( + authorizationInterceptors, + tag: BindingTag.isolateTag, + ); + Get.put(dynamicUrlInterceptors); + Get.put(deleteCredentialInteractor); + Get.put(logoutOidcInteractor); + Get.put(deleteAuthorityOidcInteractor); + Get.put(appToast); + Get.put(imagePaths); + Get.put(responsiveUtils); + Get.put(uuid); + Get.put(printUtils); + + when(mailboxDashboardController.accountId).thenReturn(Rxn(testAccountId)); + when(uuid.v4()).thenReturn(testTaskId); + }); + + setUp(() { + singleEmailController = SingleEmailController( + getEmailContentInteractor, + markAsEmailReadInteractor, + downloadAttachmentsInteractor, + deviceManager, + exportAttachmentInteractor, + moveToMailboxInteractor, + markAsStarEmailInteractor, + downloadAttachmentForWebInteractor, + getAllIdentitiesInteractor, + storeOpenedEmailInteractor, + printEmailInteractor, + ); + }); + + group('calendar event reply test:', () { + final blobId = Id('abc123'); + final calendarEvent = CalendarEvent(); + + group('accept test:', () { + final acceptCalendarEventInteractor = MockAcceptCalendarEventInteractor(); + + test('should call execute on AcceptCalendarEventInteractor ' + 'when onCalendarEventReplyAction is called on EventActionType.yes', () async { + // arrange + when(mailboxDashboardController.selectedEmail).thenReturn(Rxn(null)); + when(mailboxDashboardController.emailUIAction).thenReturn(Rxn(null)); + when(mailboxDashboardController.viewState).thenReturn(Rx(Right(UIState.idle))); + singleEmailController.onInit(); + Get.put(acceptCalendarEventInteractor); + mailboxDashboardController.accountId.refresh(); + singleEmailController.handleSuccessViewState( + ParseCalendarEventSuccess([ + BlobCalendarEvent( + blobId: blobId, + calendarEventList: [calendarEvent])])); + + // act + singleEmailController.onCalendarEventReplyAction(EventActionType.yes); + await untilCalled(acceptCalendarEventInteractor.execute(any, any)); + + // assert + verify(acceptCalendarEventInteractor.execute(testAccountId, {blobId})).called(1); + }); + }); + + group('maybe test:', () { + final maybeCalendarEventInteractor = MockMaybeCalendarEventInteractor(); + + test('should call execute on AcceptCalendarEventInteractor ' + 'when onCalendarEventReplyAction is called on EventActionType.yes', () async { + // arrange + when(mailboxDashboardController.selectedEmail).thenReturn(Rxn(null)); + when(mailboxDashboardController.emailUIAction).thenReturn(Rxn(null)); + when(mailboxDashboardController.viewState).thenReturn(Rx(Right(UIState.idle))); + singleEmailController.onInit(); + Get.put(maybeCalendarEventInteractor); + mailboxDashboardController.accountId.refresh(); + singleEmailController.handleSuccessViewState( + ParseCalendarEventSuccess([ + BlobCalendarEvent( + blobId: blobId, + calendarEventList: [calendarEvent])])); + + // act + singleEmailController.onCalendarEventReplyAction(EventActionType.maybe); + await untilCalled(maybeCalendarEventInteractor.execute(any, any)); + + // assert + verify(maybeCalendarEventInteractor.execute(testAccountId, {blobId})).called(1); + }); + }); + + group('reject test:', () { + final rejectCalendarEventInteractor = MockRejectCalendarEventInteractor(); + + test('should call execute on RejectCalendarEventInteractor ' + 'when onCalendarEventReplyAction is called on EventActionType.yes', () async { + // arrange + when(mailboxDashboardController.selectedEmail).thenReturn(Rxn(null)); + when(mailboxDashboardController.emailUIAction).thenReturn(Rxn(null)); + when(mailboxDashboardController.viewState).thenReturn(Rx(Right(UIState.idle))); + singleEmailController.onInit(); + Get.put(rejectCalendarEventInteractor); + mailboxDashboardController.accountId.refresh(); + singleEmailController.handleSuccessViewState( + ParseCalendarEventSuccess([ + BlobCalendarEvent( + blobId: blobId, + calendarEventList: [calendarEvent])])); + + // act + singleEmailController.onCalendarEventReplyAction(EventActionType.no); + await untilCalled(rejectCalendarEventInteractor.execute(any, any)); + + // assert + verify(rejectCalendarEventInteractor.execute(testAccountId, {blobId})).called(1); + }); + }); + }); +} \ No newline at end of file