-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TF-3235 Create SeachSnippets for presentation emails and update at in…
…teractors
- Loading branch information
1 parent
5862635
commit 4c1fd74
Showing
12 changed files
with
473 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
mixin SearchSnippetMixin { | ||
String? searchSnippetSubject; | ||
String? searchSnippetPreview; | ||
} |
90 changes: 90 additions & 0 deletions
90
test/features/mailbox_dashboard/domain/usecases/quick_search_email_interactor_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
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/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( | ||
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))), | ||
); | ||
}); | ||
}); | ||
} |
98 changes: 98 additions & 0 deletions
98
test/features/search/email/domain/usecases/refresh_changes_search_email_interactor_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)), | ||
]) | ||
); | ||
}, | ||
); | ||
}); | ||
} |
Oops, something went wrong.