Skip to content

Commit

Permalink
TF-3235 Create SeachSnippets for presentation emails and update at in…
Browse files Browse the repository at this point in the history
…teractors
  • Loading branch information
tddang-linagora committed Nov 8, 2024
1 parent 990f162 commit ec40694
Show file tree
Hide file tree
Showing 12 changed files with 476 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ class QuickSearchEmailInteractor {
properties: properties);

final presentationEmailList = emailList
.map((email) => email.toPresentationEmail())
.map((email) => email.toPresentationEmail(
searchSnippetSubject: email.searchSnippetSubject,
searchSnippetPreview: email.searchSnippetPreview,
))
.toList();

return Right(QuickSearchEmailSuccess(presentationEmailList));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ class RefreshChangesSearchEmailInteractor {
properties: properties);

final presentationEmailList = emailList
.map((email) => email.toPresentationEmail())
.map((email) => email.toPresentationEmail(
searchSnippetSubject: email.searchSnippetSubject,
searchSnippetPreview: email.searchSnippetPreview,
))
.toList();

yield Right(RefreshChangesSearchEmailSuccess(presentationEmailList));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ class SearchEmailInteractor {
properties: properties);

final presentationEmailList = emailList
.map((email) => email.toPresentationEmail())
.map((email) => email.toPresentationEmail(
searchSnippetSubject: email.searchSnippetSubject,
searchSnippetPreview: email.searchSnippetPreview,
))
.toList();

yield Right(SearchEmailSuccess(presentationEmailList));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ class SearchMoreEmailInteractor {

final presentationEmailList = emailList
.where((email) => email.id != lastEmailId)
.map((email) => email.toPresentationEmail())
.map((email) => email.toPresentationEmail(
searchSnippetSubject: email.searchSnippetSubject,
searchSnippetPreview: email.searchSnippetPreview,
))
.toList();

yield Right(SearchMoreEmailSuccess(presentationEmailList));
Expand Down
5 changes: 4 additions & 1 deletion model/lib/email/presentation_email.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ import 'package:model/extensions/keyword_identifier_extension.dart';
import 'package:model/extensions/media_type_nullable_extension.dart';
import 'package:model/mailbox/presentation_mailbox.dart';
import 'package:model/mailbox/select_mode.dart';
import 'package:model/mixin/search_snippet_mixin.dart';

class PresentationEmail with EquatableMixin {
class PresentationEmail with EquatableMixin, SearchSnippetMixin {

final EmailId? id;
final Id? blobId;
Expand Down Expand Up @@ -172,5 +173,7 @@ class PresentationEmail with EquatableMixin {
htmlBody,
bodyValues,
headerCalendarEvent,
searchSnippetSubject,
searchSnippetPreview,
];
}
10 changes: 8 additions & 2 deletions model/lib/extensions/email_extension.dart
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,11 @@ extension EmailExtension on Email {
);
}

PresentationEmail toPresentationEmail({SelectMode selectMode = SelectMode.INACTIVE}) {
PresentationEmail toPresentationEmail({
SelectMode selectMode = SelectMode.INACTIVE,
String? searchSnippetSubject,
String? searchSnippetPreview,
}) {
return PresentationEmail(
id: id,
blobId: blobId,
Expand All @@ -114,7 +118,9 @@ extension EmailExtension on Email {
selectMode: selectMode,
emailHeader: headers?.toList(),
headerCalendarEvent: headerCalendarEvent
);
)
..searchSnippetSubject = searchSnippetSubject
..searchSnippetPreview = searchSnippetPreview;
}

Email combineEmail(Email newEmail, Properties updatedProperties) {
Expand Down
24 changes: 18 additions & 6 deletions model/lib/extensions/presentation_email_extension.dart
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ extension PresentationEmailExtension on PresentationEmail {
routeWeb: routeWeb,
mailboxContain: mailboxContain,
headerCalendarEvent: headerCalendarEvent
);
)
..searchSnippetSubject = searchSnippetSubject
..searchSnippetPreview = searchSnippetPreview;
}

PresentationEmail toSelectedEmail({required SelectMode selectMode}) {
Expand All @@ -88,7 +90,9 @@ extension PresentationEmailExtension on PresentationEmail {
routeWeb: routeWeb,
mailboxContain: mailboxContain,
headerCalendarEvent: headerCalendarEvent
);
)
..searchSnippetSubject = searchSnippetSubject
..searchSnippetPreview = searchSnippetPreview;
}

Email toEmail() {
Expand Down Expand Up @@ -169,7 +173,9 @@ extension PresentationEmailExtension on PresentationEmail {
routeWeb: routeWeb,
mailboxContain: matchedMailbox,
headerCalendarEvent: headerCalendarEvent
);
)
..searchSnippetSubject = searchSnippetSubject
..searchSnippetPreview = searchSnippetPreview;
}

PresentationMailbox? findMailboxContain(Map<MailboxId, PresentationMailbox> mapMailbox) {
Expand Down Expand Up @@ -206,7 +212,9 @@ extension PresentationEmailExtension on PresentationEmail {
routeWeb: routeWeb,
mailboxContain: mailboxContain,
headerCalendarEvent: headerCalendarEvent
);
)
..searchSnippetSubject = searchSnippetSubject
..searchSnippetPreview = searchSnippetPreview;
}

PresentationEmail updateKeywords(Map<KeyWordIdentifier, bool>? newKeywords) {
Expand All @@ -230,7 +238,9 @@ extension PresentationEmailExtension on PresentationEmail {
routeWeb: routeWeb,
mailboxContain: mailboxContain,
headerCalendarEvent: headerCalendarEvent
);
)
..searchSnippetSubject = searchSnippetSubject
..searchSnippetPreview = searchSnippetPreview;
}

PresentationEmail syncPresentationEmail({PresentationMailbox? mailboxContain, Uri? routeWeb}) {
Expand All @@ -254,7 +264,9 @@ extension PresentationEmailExtension on PresentationEmail {
routeWeb: routeWeb,
mailboxContain: mailboxContain,
headerCalendarEvent: headerCalendarEvent
);
)
..searchSnippetSubject = searchSnippetSubject
..searchSnippetPreview = searchSnippetPreview;
}

bool isBelongToOneOfTheMailboxes(List<MailboxId> mailboxIdsSource) {
Expand Down
4 changes: 4 additions & 0 deletions model/lib/mixin/search_snippet_mixin.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
mixin SearchSnippetMixin {
String? searchSnippetSubject;
String? searchSnippetPreview;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import 'package:dartz/dartz.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:jmap_dart_client/jmap/core/id.dart';
import 'package:jmap_dart_client/jmap/mail/email/email.dart';
import 'package:jmap_dart_client/jmap/mail/email/email_filter_condition.dart';
import 'package:mockito/annotations.dart';
import 'package:mockito/mockito.dart';
import 'package:model/extensions/email_extension.dart';
import 'package:tmail_ui_user/features/mailbox_dashboard/domain/state/quick_search_email_state.dart';
import 'package:tmail_ui_user/features/mailbox_dashboard/domain/usecases/quick_search_email_interactor.dart';
import 'package:tmail_ui_user/features/thread/domain/model/search_email.dart';
import 'package:tmail_ui_user/features/thread/domain/repository/thread_repository.dart';

import '../../../../fixtures/account_fixtures.dart';
import '../../../../fixtures/session_fixtures.dart';
import 'quick_search_email_interactor_test.mocks.dart';

@GenerateNiceMocks([MockSpec<ThreadRepository>()])
void main() {
final threadRepository = MockThreadRepository();
final quickSearchEmailInteractor = QuickSearchEmailInteractor(threadRepository);

group('quick search email interactor test:', () {
test(
'should return list of presentation emails '
'when threadRepository.searchEmails returns list of emails',
() async {
// arrange
final searchEmail = SearchEmail(
id: EmailId(Id('someId')),
searchSnippetSubject: 'searchSnippetSubject',
searchSnippetPreview: 'searchSnippetPreview',
);
when(
threadRepository.searchEmails(
any,
any,
limit: anyNamed('limit'),
sort: anyNamed('sort'),
filter: anyNamed('filter'),
properties: anyNamed('properties'),
),
).thenAnswer((_) async => [searchEmail]);

// act
final result = await quickSearchEmailInteractor.execute(
SessionFixtures.aliceSession,
AccountFixtures.aliceAccountId,
filter: EmailFilterCondition(text: 'test'),
);

// assert
expect(
result,
equals(Right(QuickSearchEmailSuccess([searchEmail.toPresentationEmail(
searchSnippetSubject: searchEmail.searchSnippetSubject,
searchSnippetPreview: searchEmail.searchSnippetPreview,
)]))),
);
});

test(
'should return failure '
'when threadRepository.searchEmails throws exception',
() async {
// arrange
final exception = Exception();
when(
threadRepository.searchEmails(
any,
any,
limit: anyNamed('limit'),
sort: anyNamed('sort'),
filter: anyNamed('filter'),
properties: anyNamed('properties'),
),
).thenThrow(exception);

// act
final result = await quickSearchEmailInteractor.execute(
SessionFixtures.aliceSession,
AccountFixtures.aliceAccountId,
filter: EmailFilterCondition(text: 'test'),
);

// assert
expect(
result,
equals(Left(QuickSearchEmailFailure(exception))),
);
});
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
import 'package:dartz/dartz.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:jmap_dart_client/jmap/mail/email/email_filter_condition.dart';
import 'package:mockito/annotations.dart';
import 'package:mockito/mockito.dart';
import 'package:model/extensions/email_extension.dart';
import 'package:tmail_ui_user/features/search/email/domain/state/refresh_changes_search_email_state.dart';
import 'package:tmail_ui_user/features/search/email/domain/usecases/refresh_changes_search_email_interactor.dart';
import 'package:tmail_ui_user/features/thread/domain/model/search_email.dart';
import 'package:tmail_ui_user/features/thread/domain/repository/thread_repository.dart';

import '../../../../../fixtures/account_fixtures.dart';
import '../../../../../fixtures/session_fixtures.dart';
import 'refresh_changes_search_email_interactor_test.mocks.dart';

@GenerateNiceMocks([MockSpec<ThreadRepository>()])
void main() {
final threadRepository = MockThreadRepository();
final refreshChangesSearchEmailInteractor = RefreshChangesSearchEmailInteractor(
threadRepository);

group('refresh changes search email interactor test:', () {
test(
'should return list of presentation emails '
'when threadRepository.searchEmails returns list of emails',
() {
// arrange
final searchEmail = SearchEmail(
searchSnippetSubject: 'searchSnippetSubject',
searchSnippetPreview: 'searchSnippetPreview',
);
when(
threadRepository.searchEmails(
any,
any,
limit: anyNamed('limit'),
sort: anyNamed('sort'),
filter: anyNamed('filter'),
properties: anyNamed('properties'),
),
).thenAnswer((_) async => [searchEmail]);

// act
final result = refreshChangesSearchEmailInteractor.execute(
SessionFixtures.aliceSession,
AccountFixtures.aliceAccountId,
filter: EmailFilterCondition(text: 'test'),
);

// assert
expect(
result,
emitsInOrder([
Right(RefreshingChangeSearchEmailState()),
Right(RefreshChangesSearchEmailSuccess([searchEmail.toPresentationEmail(
searchSnippetSubject: searchEmail.searchSnippetSubject,
searchSnippetPreview: searchEmail.searchSnippetPreview,
)])),
])
);
});

test(
'should return failure '
'when threadRepository.searchEmails throw exception',
() {
// arrange
final exception = Exception();
when(
threadRepository.searchEmails(
any,
any,
limit: anyNamed('limit'),
sort: anyNamed('sort'),
filter: anyNamed('filter'),
properties: anyNamed('properties'),
),
).thenThrow(exception);

// act
final result = refreshChangesSearchEmailInteractor.execute(
SessionFixtures.aliceSession,
AccountFixtures.aliceAccountId,
filter: EmailFilterCondition(text: 'test'),
);

// assert
expect(
result,
emitsInOrder([
Right(RefreshingChangeSearchEmailState()),
Left(RefreshChangesSearchEmailFailure(exception)),
])
);
},
);
});
}
Loading

0 comments on commit ec40694

Please sign in to comment.