-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TF-2859 Unit test add language when reply calendar invitation
- Loading branch information
1 parent
2e68e7d
commit b207880
Showing
6 changed files
with
219 additions
and
31 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'); | ||
}); | ||
}); | ||
} |
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
Oops, something went wrong.