Skip to content

Commit

Permalink
fixup! Format calendar event description
Browse files Browse the repository at this point in the history
  • Loading branch information
tddang-linagora committed Dec 16, 2024
1 parent 35e4745 commit 20d9dc5
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,6 @@ class SingleEmailController extends BaseController with AppLoaderMixin {
_parseCalendarEventAction(
accountId: mailboxDashBoardController.accountId.value!,
blobIds: success.attachments?.calendarEventBlobIds ?? {},
emailContents: success.htmlEmailContent
);
} else {
emailContents.value = success.htmlEmailContent;
Expand Down Expand Up @@ -569,7 +568,6 @@ class SingleEmailController extends BaseController with AppLoaderMixin {
_parseCalendarEventAction(
accountId: mailboxDashBoardController.accountId.value!,
blobIds: success.attachments?.calendarEventBlobIds ?? {},
emailContents: success.htmlEmailContent
);
} else {
emailContents.value = success.htmlEmailContent;
Expand Down Expand Up @@ -1471,10 +1469,15 @@ class SingleEmailController extends BaseController with AppLoaderMixin {
CapabilityIdentifier.jamesCalendarEvent.isSupported(session, accountId);
}

@visibleForTesting
parseCalendarEventAction({
required AccountId accountId,
required Set<Id> blobIds,
}) => _parseCalendarEventAction(accountId: accountId, blobIds: blobIds);

void _parseCalendarEventAction({
required AccountId accountId,
required Set<Id> blobIds,
required String emailContents
}) {
log("SingleEmailController::_parseCalendarEventAction:blobIds: $blobIds");
consumeState(_parseCalendarEventInteractor!.execute(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'dart:convert';
import 'dart:ui';

import 'package:core/core.dart';
import 'package:core/utils/application_manager.dart';
import 'package:dartz/dartz.dart' hide State;
import 'package:flutter/foundation.dart';
import 'package:flutter_test/flutter_test.dart';
Expand All @@ -18,7 +18,12 @@ import 'package:jmap_dart_client/jmap/mail/calendar/reply/calendar_event_accept_
import 'package:jmap_dart_client/jmap/mail/email/email.dart';
import 'package:mockito/annotations.dart';
import 'package:mockito/mockito.dart';
import 'package:model/email/presentation_email.dart';
import 'package:tmail_ui_user/features/caching/caching_manager.dart';
import 'package:tmail_ui_user/features/email/data/datasource/calendar_event_datasource.dart';
import 'package:tmail_ui_user/features/email/data/datasource_impl/html_datasource_impl.dart';
import 'package:tmail_ui_user/features/email/data/local/html_analyzer.dart';
import 'package:tmail_ui_user/features/email/data/repository/calendar_event_repository_impl.dart';
import 'package:tmail_ui_user/features/email/domain/model/event_action.dart';
import 'package:tmail_ui_user/features/email/domain/state/calendar_event_accept_state.dart';
import 'package:tmail_ui_user/features/email/domain/state/parse_calendar_event_state.dart';
Expand All @@ -32,9 +37,11 @@ import 'package:tmail_ui_user/features/email/domain/usecases/get_email_content_i
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/parse_calendar_event_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_event_attendance_status_interactor.dart';
import 'package:tmail_ui_user/features/email/domain/usecases/store_opened_email_interactor.dart';
import 'package:tmail_ui_user/features/email/presentation/action/email_ui_action.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';
Expand All @@ -46,10 +53,12 @@ import 'package:tmail_ui_user/features/manage_account/data/local/language_cache_
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:tmail_ui_user/main/exceptions/cache_exception_thrower.dart';
import 'package:tmail_ui_user/main/utils/toast_manager.dart';
import 'package:tmail_ui_user/main/utils/twake_app_manager.dart';
import 'package:uuid/uuid.dart';

import '../../../../fixtures/account_fixtures.dart';
import '../../../../fixtures/email_fixtures.dart';
import 'single_email_controller_test.mocks.dart';

Expand Down Expand Up @@ -93,6 +102,8 @@ const fallbackGenerators = {
MockSpec<ApplicationManager>(),
MockSpec<ToastManager>(),
MockSpec<TwakeAppManager>(),
MockSpec<CalendarEventDataSource>(),
MockSpec<DioClient>(),
])
void main() {
TestWidgetsFlutterBinding.ensureInitialized();
Expand Down Expand Up @@ -367,4 +378,78 @@ void main() {
debugDefaultTargetPlatformOverride = null;
});
});

group('_parseCalendarEventAction method test:', () {
final calendarEventDataSource = MockCalendarEventDataSource();
final calendarEventRepository = CalendarEventRepositoryImpl(
{DataSourceType.network :calendarEventDataSource},
HtmlDataSourceImpl(
HtmlAnalyzer(HtmlTransform(
MockDioClient(),
const HtmlEscape(),
)),
CacheExceptionThrower(),
),
);

setUp(() {
Get.put(ParseCalendarEventInteractor(calendarEventRepository));
});

tearDown(() {
Get.delete<ParseCalendarEventInteractor>();
});

test(
'should transform all calendar event description url to a tag '
'and all new line to <br> tag',
() async {
// arrange
const eventDescription = '\nhttps://example1.com\nhttps://example2.com';
const expectedEventDescription = '<html><head></head><body>'
'<br>'
'<a href="https://example1.com" target="_blank" rel="noreferrer">example1.com</a>'
'<br>'
'<a href="https://example2.com" target="_blank" rel="noreferrer">example2.com</a>'
'</body></html>';
final blobId = Id('abc123');
final calendarEvent = CalendarEvent(
description: eventDescription,
);
final blobCalendarEvents = [
BlobCalendarEvent(
blobId: blobId,
calendarEventList: [calendarEvent],
),
];
when(calendarEventDataSource.parse(any, any))
.thenAnswer((_) async => blobCalendarEvents);

when(mailboxDashboardController.selectedEmail).thenReturn(Rxn(PresentationEmail()));
when(mailboxDashboardController.emailUIAction).thenReturn(Rxn(EmailUIAction()));
when(mailboxDashboardController.viewState).thenReturn(Rx(Right(UIState.idle)));
when(mailboxDashboardController.accountId).thenReturn(Rxn(AccountFixtures.aliceAccountId));
when(emailSupervisorController.scrollPhysicsPageView).thenReturn(Rxn());

singleEmailController.onInit();
mailboxDashboardController.accountId.refresh();

// act
singleEmailController.parseCalendarEventAction(
accountId: AccountFixtures.aliceAccountId,
blobIds: {blobId},
);
await untilCalled(calendarEventDataSource.parse(any, any));
await Future.delayed(Duration.zero);

// assert
expect(
singleEmailController.blobCalendarEvent.value,
BlobCalendarEvent(
blobId: blobId,
calendarEventList: [CalendarEvent(description: expectedEventDescription)],
),
);
});
});
}

0 comments on commit 20d9dc5

Please sign in to comment.