TF-2859 Unit test add language when reply calendar invitation
This commit is contained in:
@@ -0,0 +1,168 @@
|
||||
import 'dart:ui';
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/account/account.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/capability/calendar_event_capability.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/capability/capability_identifier.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/capability/empty_capability.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/id.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/session/session.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/state.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/user_name.dart';
|
||||
import 'package:model/extensions/session_extension.dart';
|
||||
|
||||
void main() {
|
||||
final accountId = AccountId(Id('123abc'));
|
||||
|
||||
group('validate calendar event capability test:', () {
|
||||
final account = Account(AccountName('name'), true, true, {});
|
||||
|
||||
test(
|
||||
'should return isAvailable is false '
|
||||
'and calendarEventCapability is null '
|
||||
'when there is no such capability',
|
||||
() {
|
||||
// arrange
|
||||
final session = Session(
|
||||
{},
|
||||
{accountId: account},
|
||||
{}, UserName(''), Uri(), Uri(), Uri(), Uri(), State(''));
|
||||
|
||||
// act
|
||||
final result = session.validateCalendarEventCapability(accountId);
|
||||
|
||||
// assert
|
||||
expect(result.isAvailable, false);
|
||||
expect(result.calendarEventCapability, null);
|
||||
});
|
||||
|
||||
test(
|
||||
'should return isAvailable is true '
|
||||
'and calendarEventCapability is not null '
|
||||
'when calendar event capability is available',
|
||||
() {
|
||||
// arrange
|
||||
final calendarEventCapability = CalendarEventCapability();
|
||||
final session = Session(
|
||||
{CapabilityIdentifier.jamesCalendarEvent: calendarEventCapability},
|
||||
{accountId: account},
|
||||
{}, UserName(''), Uri(), Uri(), Uri(), Uri(), State(''));
|
||||
|
||||
// act
|
||||
final result = session.validateCalendarEventCapability(AccountId(Id('123abc')));
|
||||
|
||||
// assert
|
||||
expect(result.isAvailable, true);
|
||||
expect(result.calendarEventCapability, calendarEventCapability);
|
||||
});
|
||||
});
|
||||
|
||||
group('get language for calendar event test:', () {
|
||||
test(
|
||||
'should return null '
|
||||
'when calendar event capability is not supported',
|
||||
() {
|
||||
// arrange
|
||||
const currentLocale = Locale('en', 'US');
|
||||
final session = Session(
|
||||
{CapabilityIdentifier.jamesCalendarEvent: EmptyCapability()},
|
||||
{}, {}, UserName(''), Uri(), Uri(), Uri(), Uri(), State(''));
|
||||
|
||||
// act
|
||||
final calendarEventLanguage = session.getLanguageForCalendarEvent(
|
||||
currentLocale,
|
||||
accountId);
|
||||
|
||||
// assert
|
||||
expect(calendarEventLanguage, null);
|
||||
});
|
||||
|
||||
test(
|
||||
'should return null '
|
||||
'when calendar event capability supportes no language',
|
||||
() {
|
||||
// arrange
|
||||
final calendarEventCapability = CalendarEventCapability();
|
||||
const currentLocale = Locale('en', 'US');
|
||||
final session = Session(
|
||||
{CapabilityIdentifier.jamesCalendarEvent: calendarEventCapability},
|
||||
{}, {}, UserName(''), Uri(), Uri(), Uri(), Uri(), State(''));
|
||||
|
||||
// act
|
||||
final calendarEventLanguage = session.getLanguageForCalendarEvent(
|
||||
currentLocale,
|
||||
accountId);
|
||||
|
||||
// assert
|
||||
expect(calendarEventLanguage, null);
|
||||
});
|
||||
|
||||
test(
|
||||
'should return current locale language '
|
||||
'when calendar event capability supports current locale',
|
||||
() {
|
||||
// arrange
|
||||
final calendarEventCapability = CalendarEventCapability(
|
||||
replySupportedLanguage: ['en', 'fr'],
|
||||
);
|
||||
const currentLocale = Locale('en', 'US');
|
||||
final session = Session(
|
||||
{CapabilityIdentifier.jamesCalendarEvent: calendarEventCapability},
|
||||
{}, {}, UserName(''), Uri(), Uri(), Uri(), Uri(), State(''));
|
||||
|
||||
// act
|
||||
final calendarEventLanguage = session.getLanguageForCalendarEvent(
|
||||
currentLocale,
|
||||
accountId);
|
||||
|
||||
// assert
|
||||
expect(calendarEventLanguage, currentLocale.languageCode);
|
||||
});
|
||||
|
||||
test(
|
||||
'should return English language '
|
||||
'when calendar event capability doesn\'t support current locale, '
|
||||
'but supports English',
|
||||
() {
|
||||
// arrange
|
||||
final calendarEventCapability = CalendarEventCapability(
|
||||
replySupportedLanguage: ['en'],
|
||||
);
|
||||
const currentLocale = Locale('fr', 'FR');
|
||||
final session = Session(
|
||||
{CapabilityIdentifier.jamesCalendarEvent: calendarEventCapability},
|
||||
{}, {}, UserName(''), Uri(), Uri(), Uri(), Uri(), State(''));
|
||||
|
||||
// act
|
||||
final calendarEventLanguage = session.getLanguageForCalendarEvent(
|
||||
currentLocale,
|
||||
accountId);
|
||||
|
||||
// assert
|
||||
expect(calendarEventLanguage, 'en');
|
||||
});
|
||||
|
||||
test(
|
||||
'should return first supported language '
|
||||
'when calendar event capability doesn\'t support both English and current locale',
|
||||
() {
|
||||
// arrange
|
||||
final calendarEventCapability = CalendarEventCapability(
|
||||
replySupportedLanguage: ['vi'],
|
||||
);
|
||||
const currentLocale = Locale('fr', 'FR');
|
||||
final session = Session(
|
||||
{CapabilityIdentifier.jamesCalendarEvent: calendarEventCapability},
|
||||
{}, {}, UserName(''), Uri(), Uri(), Uri(), Uri(), State(''));
|
||||
|
||||
// act
|
||||
final calendarEventLanguage = session.getLanguageForCalendarEvent(
|
||||
currentLocale,
|
||||
accountId);
|
||||
|
||||
// assert
|
||||
expect(calendarEventLanguage, 'vi');
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -22,6 +22,7 @@ void main() {
|
||||
final calendarEventRepository = CalendarEventRepositoryImpl(calendarEventDataSource);
|
||||
final accountId = AccountId(Id('123'));
|
||||
final blobId = Id('blobId');
|
||||
const language = 'en';
|
||||
|
||||
group('calendar event repository test:', () {
|
||||
final calendarEventAcceptResponseresponse = CalendarEventAcceptResponse(
|
||||
@@ -31,11 +32,11 @@ void main() {
|
||||
|
||||
test('should return response when data source return response', () async {
|
||||
// arrange
|
||||
when(calendarEventNetworkDataSource.acceptEventInvitation(any, any))
|
||||
when(calendarEventNetworkDataSource.acceptEventInvitation(any, any, any))
|
||||
.thenAnswer((_) async => calendarEventAcceptResponseresponse);
|
||||
|
||||
// act
|
||||
final response = await calendarEventRepository.acceptEventInvitation(accountId, {blobId});
|
||||
final response = await calendarEventRepository.acceptEventInvitation(accountId, {blobId}, language);
|
||||
|
||||
// assert
|
||||
expect(response, calendarEventAcceptResponseresponse);
|
||||
@@ -43,12 +44,12 @@ void main() {
|
||||
|
||||
test('should throw exception when data source throw exception', () {
|
||||
// arrange
|
||||
when(calendarEventNetworkDataSource.acceptEventInvitation(any, any))
|
||||
when(calendarEventNetworkDataSource.acceptEventInvitation(any, any, any))
|
||||
.thenThrow(NotAcceptableCalendarEventException());
|
||||
|
||||
// assert
|
||||
expect(
|
||||
() => calendarEventRepository.acceptEventInvitation(accountId, {blobId}),
|
||||
() => calendarEventRepository.acceptEventInvitation(accountId, {blobId}, language),
|
||||
throwsA(isA<NotAcceptableCalendarEventException>()));
|
||||
});
|
||||
});
|
||||
@@ -61,11 +62,11 @@ void main() {
|
||||
|
||||
test('should return response when data source return response', () async {
|
||||
// arrange
|
||||
when(calendarEventNetworkDataSource.maybeEventInvitation(any, any))
|
||||
when(calendarEventNetworkDataSource.maybeEventInvitation(any, any, any))
|
||||
.thenAnswer((_) async => calendarEventMaybeResponse);
|
||||
|
||||
// act
|
||||
final response = await calendarEventRepository.maybeEventInvitation(accountId, {blobId});
|
||||
final response = await calendarEventRepository.maybeEventInvitation(accountId, {blobId}, language);
|
||||
|
||||
// assert
|
||||
expect(response, calendarEventMaybeResponse);
|
||||
@@ -73,12 +74,12 @@ void main() {
|
||||
|
||||
test('should throw exception when data source throw exception', () {
|
||||
// arrange
|
||||
when(calendarEventNetworkDataSource.maybeEventInvitation(any, any))
|
||||
when(calendarEventNetworkDataSource.maybeEventInvitation(any, any, any))
|
||||
.thenThrow(NotMaybeableCalendarEventException());
|
||||
|
||||
// assert
|
||||
expect(
|
||||
() => calendarEventRepository.maybeEventInvitation(accountId, {blobId}),
|
||||
() => calendarEventRepository.maybeEventInvitation(accountId, {blobId}, language),
|
||||
throwsA(isA<NotMaybeableCalendarEventException>()));
|
||||
});
|
||||
});
|
||||
@@ -91,11 +92,11 @@ void main() {
|
||||
|
||||
test('should return response when data source return response', () async {
|
||||
// arrange
|
||||
when(calendarEventNetworkDataSource.rejectEventInvitation(any, any))
|
||||
when(calendarEventNetworkDataSource.rejectEventInvitation(any, any, any))
|
||||
.thenAnswer((_) async => calendarEventRejectResponseresponse);
|
||||
|
||||
// act
|
||||
final response = await calendarEventRepository.rejectEventInvitation(accountId, {blobId});
|
||||
final response = await calendarEventRepository.rejectEventInvitation(accountId, {blobId}, language);
|
||||
|
||||
// assert
|
||||
expect(response, calendarEventRejectResponseresponse);
|
||||
@@ -103,12 +104,12 @@ void main() {
|
||||
|
||||
test('should throw exception when data source throw exception', () {
|
||||
// arrange
|
||||
when(calendarEventNetworkDataSource.rejectEventInvitation(any, any))
|
||||
when(calendarEventNetworkDataSource.rejectEventInvitation(any, any, any))
|
||||
.thenThrow(NotRejectableCalendarEventException());
|
||||
|
||||
// assert
|
||||
expect(
|
||||
() => calendarEventRepository.rejectEventInvitation(accountId, {blobId}),
|
||||
() => calendarEventRepository.rejectEventInvitation(accountId, {blobId}, language),
|
||||
throwsA(isA<NotRejectableCalendarEventException>()));
|
||||
});
|
||||
});
|
||||
|
||||
@@ -21,6 +21,7 @@ void main() {
|
||||
final accountId = AccountId(Id('123'));
|
||||
final blobId = Id('123321');
|
||||
final emailId = EmailId(Id('abcde'));
|
||||
const language = 'en';
|
||||
|
||||
group('calendar event accept interactor test:', () {
|
||||
test('should emit CalendarEventAccepted when repo return data', () {
|
||||
@@ -29,12 +30,12 @@ void main() {
|
||||
accountId,
|
||||
null,
|
||||
accepted: [EventId(blobId.value)]);
|
||||
when(calendarEventRepository.acceptEventInvitation(any, any))
|
||||
when(calendarEventRepository.acceptEventInvitation(any, any, any))
|
||||
.thenAnswer((_) async => calendarEventAcceptResponse);
|
||||
|
||||
// assert
|
||||
expect(
|
||||
acceptCalendarEventInteractor.execute(accountId, {blobId}, emailId),
|
||||
acceptCalendarEventInteractor.execute(accountId, {blobId}, emailId, language),
|
||||
emitsInOrder([
|
||||
Right(CalendarEventAccepting()),
|
||||
Right(CalendarEventAccepted(calendarEventAcceptResponse, emailId))]));
|
||||
@@ -43,11 +44,11 @@ void main() {
|
||||
test('should emit CalendarEventAcceptFailure when repo throw exception', () {
|
||||
// arrange
|
||||
final exception = NotAcceptableCalendarEventException();
|
||||
when(calendarEventRepository.acceptEventInvitation(any, any)).thenThrow(exception);
|
||||
when(calendarEventRepository.acceptEventInvitation(any, any, any)).thenThrow(exception);
|
||||
|
||||
// assert
|
||||
expect(
|
||||
acceptCalendarEventInteractor.execute(accountId, {blobId}, emailId),
|
||||
acceptCalendarEventInteractor.execute(accountId, {blobId}, emailId, language),
|
||||
emitsInOrder([
|
||||
Right(CalendarEventAccepting()),
|
||||
Left(CalendarEventAcceptFailure(exception: exception))]));
|
||||
|
||||
@@ -18,6 +18,7 @@ void main() {
|
||||
final accountId = AccountId(Id('123'));
|
||||
final blobId = Id('123321');
|
||||
final emailId = EmailId(Id('abcde'));
|
||||
const language = 'en';
|
||||
|
||||
group('calendar event reject interactor test:', () {
|
||||
test('should emit CalendarEventRejected when repo return data', () {
|
||||
@@ -26,12 +27,12 @@ void main() {
|
||||
accountId,
|
||||
null,
|
||||
rejected: [EventId(blobId.value)]);
|
||||
when(calendarEventRepository.rejectEventInvitation(any, any))
|
||||
when(calendarEventRepository.rejectEventInvitation(any, any, any))
|
||||
.thenAnswer((_) async => calendarEventRejectResponse);
|
||||
|
||||
// assert
|
||||
expect(
|
||||
rejectCalendarEventInteractor.execute(accountId, {blobId}, emailId),
|
||||
rejectCalendarEventInteractor.execute(accountId, {blobId}, emailId, language),
|
||||
emitsInOrder([
|
||||
Right(CalendarEventRejecting()),
|
||||
Right(CalendarEventRejected(calendarEventRejectResponse, emailId))]));
|
||||
@@ -40,11 +41,11 @@ void main() {
|
||||
test('should emit CalendarEventRejectFailure when repo throw exception', () {
|
||||
// arrange
|
||||
final exception = NotRejectableCalendarEventException();
|
||||
when(calendarEventRepository.rejectEventInvitation(any, any)).thenThrow(exception);
|
||||
when(calendarEventRepository.rejectEventInvitation(any, any, any)).thenThrow(exception);
|
||||
|
||||
// assert
|
||||
expect(
|
||||
rejectCalendarEventInteractor.execute(accountId, {blobId}, emailId),
|
||||
rejectCalendarEventInteractor.execute(accountId, {blobId}, emailId, language),
|
||||
emitsInOrder([
|
||||
Right(CalendarEventRejecting()),
|
||||
Left(CalendarEventRejectFailure(exception: exception))]));
|
||||
|
||||
@@ -18,6 +18,7 @@ void main() {
|
||||
final accountId = AccountId(Id('123'));
|
||||
final blobId = Id('123321');
|
||||
final emailId = EmailId(Id('abcde'));
|
||||
const language = 'en';
|
||||
|
||||
group('calendar event maybe interactor should emit expected states', () {
|
||||
test('when repo return data', () {
|
||||
@@ -26,12 +27,12 @@ void main() {
|
||||
accountId,
|
||||
null,
|
||||
maybe: [EventId(blobId.value)]);
|
||||
when(calendarEventRepository.maybeEventInvitation(any, any))
|
||||
when(calendarEventRepository.maybeEventInvitation(any, any, any))
|
||||
.thenAnswer((_) async => calendarEventMaybeResponse);
|
||||
|
||||
// assert
|
||||
expect(
|
||||
maybeCalendarEventInteractor.execute(accountId, {blobId}, emailId),
|
||||
maybeCalendarEventInteractor.execute(accountId, {blobId}, emailId, language),
|
||||
emitsInOrder([
|
||||
Right(CalendarEventMaybeReplying()),
|
||||
Right(CalendarEventMaybeSuccess(calendarEventMaybeResponse, emailId))]));
|
||||
@@ -40,11 +41,11 @@ void main() {
|
||||
test('when repo throw exception', () {
|
||||
// arrange
|
||||
final exception = NotMaybeableCalendarEventException();
|
||||
when(calendarEventRepository.maybeEventInvitation(any, any)).thenThrow(exception);
|
||||
when(calendarEventRepository.maybeEventInvitation(any, any, any)).thenThrow(exception);
|
||||
|
||||
// assert
|
||||
expect(
|
||||
maybeCalendarEventInteractor.execute(accountId, {blobId}, emailId),
|
||||
maybeCalendarEventInteractor.execute(accountId, {blobId}, emailId, language),
|
||||
emitsInOrder([
|
||||
Right(CalendarEventMaybeReplying()),
|
||||
Left(CalendarEventMaybeFailure(exception: exception))]));
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import 'dart:ui';
|
||||
|
||||
import 'package:core/core.dart';
|
||||
import 'package:dartz/dartz.dart' hide State;
|
||||
import 'package:flutter/foundation.dart';
|
||||
@@ -5,6 +7,8 @@ import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:http_parser/http_parser.dart';
|
||||
import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/capability/calendar_event_capability.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/capability/capability_identifier.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/id.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/session/session.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/state.dart';
|
||||
@@ -125,7 +129,11 @@ void main() {
|
||||
final testAccountId = AccountId(Id('123'));
|
||||
final google = Uri.parse('https://www.google.com');
|
||||
final testSession =
|
||||
Session({}, {}, {}, UserName('data'), google, google, google, google, State('1'));
|
||||
Session({
|
||||
CapabilityIdentifier.jamesCalendarEvent: CalendarEventCapability(
|
||||
replySupportedLanguage: ['en', 'fr'],
|
||||
),
|
||||
}, {}, {}, UserName('data'), google, google, google, google, State('1'));
|
||||
const testTaskId = 'taskId';
|
||||
final testDownloadTaskId = DownloadTaskId(testTaskId);
|
||||
final testBytes = Uint8List(123);
|
||||
@@ -279,6 +287,11 @@ void main() {
|
||||
final blobId = Id('abc123');
|
||||
final emailId = EmailId(Id('xyz123'));
|
||||
final calendarEvent = CalendarEvent();
|
||||
const locale = Locale('en', 'US');
|
||||
|
||||
setUp(() {
|
||||
Get.locale = locale;
|
||||
});
|
||||
|
||||
group('accept test:', () {
|
||||
final acceptCalendarEventInteractor = MockAcceptCalendarEventInteractor();
|
||||
@@ -289,6 +302,7 @@ void main() {
|
||||
when(mailboxDashboardController.selectedEmail).thenReturn(Rxn(null));
|
||||
when(mailboxDashboardController.emailUIAction).thenReturn(Rxn(null));
|
||||
when(mailboxDashboardController.viewState).thenReturn(Rx(Right(UIState.idle)));
|
||||
when(mailboxDashboardController.sessionCurrent).thenReturn(testSession);
|
||||
singleEmailController.onInit();
|
||||
Get.put<AcceptCalendarEventInteractor>(acceptCalendarEventInteractor);
|
||||
mailboxDashboardController.accountId.refresh();
|
||||
@@ -300,10 +314,10 @@ void main() {
|
||||
|
||||
// act
|
||||
singleEmailController.onCalendarEventReplyAction(EventActionType.yes, emailId);
|
||||
await untilCalled(acceptCalendarEventInteractor.execute(any, any, any));
|
||||
await untilCalled(acceptCalendarEventInteractor.execute(any, any, any, any));
|
||||
|
||||
// assert
|
||||
verify(acceptCalendarEventInteractor.execute(testAccountId, {blobId}, emailId)).called(1);
|
||||
verify(acceptCalendarEventInteractor.execute(testAccountId, {blobId}, emailId, locale.languageCode)).called(1);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -316,6 +330,7 @@ void main() {
|
||||
when(mailboxDashboardController.selectedEmail).thenReturn(Rxn(null));
|
||||
when(mailboxDashboardController.emailUIAction).thenReturn(Rxn(null));
|
||||
when(mailboxDashboardController.viewState).thenReturn(Rx(Right(UIState.idle)));
|
||||
when(mailboxDashboardController.sessionCurrent).thenReturn(testSession);
|
||||
singleEmailController.onInit();
|
||||
Get.put<MaybeCalendarEventInteractor>(maybeCalendarEventInteractor);
|
||||
mailboxDashboardController.accountId.refresh();
|
||||
@@ -327,10 +342,10 @@ void main() {
|
||||
|
||||
// act
|
||||
singleEmailController.onCalendarEventReplyAction(EventActionType.maybe, emailId);
|
||||
await untilCalled(maybeCalendarEventInteractor.execute(any, any, any));
|
||||
await untilCalled(maybeCalendarEventInteractor.execute(any, any, any, any));
|
||||
|
||||
// assert
|
||||
verify(maybeCalendarEventInteractor.execute(testAccountId, {blobId}, emailId)).called(1);
|
||||
verify(maybeCalendarEventInteractor.execute(testAccountId, {blobId}, emailId, locale.languageCode)).called(1);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -343,6 +358,7 @@ void main() {
|
||||
when(mailboxDashboardController.selectedEmail).thenReturn(Rxn(null));
|
||||
when(mailboxDashboardController.emailUIAction).thenReturn(Rxn(null));
|
||||
when(mailboxDashboardController.viewState).thenReturn(Rx(Right(UIState.idle)));
|
||||
when(mailboxDashboardController.sessionCurrent).thenReturn(testSession);
|
||||
singleEmailController.onInit();
|
||||
Get.put<RejectCalendarEventInteractor>(rejectCalendarEventInteractor);
|
||||
mailboxDashboardController.accountId.refresh();
|
||||
@@ -354,10 +370,10 @@ void main() {
|
||||
|
||||
// act
|
||||
singleEmailController.onCalendarEventReplyAction(EventActionType.no, emailId);
|
||||
await untilCalled(rejectCalendarEventInteractor.execute(any, any, any));
|
||||
await untilCalled(rejectCalendarEventInteractor.execute(any, any, any, any));
|
||||
|
||||
// assert
|
||||
verify(rejectCalendarEventInteractor.execute(testAccountId, {blobId}, emailId)).called(1);
|
||||
verify(rejectCalendarEventInteractor.execute(testAccountId, {blobId}, emailId, locale.languageCode)).called(1);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user