test(localization): fix sentAtText, add remaining tests
Signed-off-by: xsahil03x <[email protected]>
This commit is contained in:
@@ -535,15 +535,18 @@ class DefaultTranslations implements Translations {
|
||||
String get photosLabel => 'Photos';
|
||||
|
||||
String _getDay(DateTime dateTime) {
|
||||
final now = Jiffy(DateTime.now());
|
||||
final date = Jiffy(dateTime);
|
||||
final now = DateTime.now();
|
||||
final today = DateTime(now.year, now.month, now.day);
|
||||
final yesterday = DateTime(now.year, now.month, now.day - 1);
|
||||
|
||||
if (date.isSame(now, Units.DAY)) {
|
||||
final date = DateTime(dateTime.year, dateTime.month, dateTime.day);
|
||||
|
||||
if (date == today) {
|
||||
return 'today';
|
||||
} else if (now.diff(date, Units.HOUR) < 24) {
|
||||
} else if (date == yesterday) {
|
||||
return 'yesterday';
|
||||
} else {
|
||||
return 'on ${date.MMMd}';
|
||||
return 'on ${Jiffy(date).MMMd}';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,174 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:stream_chat_flutter/stream_chat_flutter.dart';
|
||||
|
||||
void main() {
|
||||
test('Default translations should exist', () {
|
||||
final translations = DefaultTranslations.instance;
|
||||
expect(translations.launchUrlError, isNotNull);
|
||||
expect(translations.loadingUsersError, isNotNull);
|
||||
expect(translations.noUsersLabel, isNotNull);
|
||||
expect(translations.retryLabel, isNotNull);
|
||||
expect(translations.userLastOnlineText, isNotNull);
|
||||
expect(translations.userOnlineText, isNotNull);
|
||||
expect(translations.userOnlineText, isNotNull);
|
||||
// no users
|
||||
expect(translations.userTypingText([]), isNotNull);
|
||||
// single user
|
||||
expect(translations.userTypingText([User(id: 'test-id')]), isNotNull);
|
||||
// multiple users
|
||||
expect(
|
||||
translations.userTypingText([
|
||||
User(id: 'test-id-1'),
|
||||
User(id: 'test-id-2'),
|
||||
]),
|
||||
isNotNull,
|
||||
);
|
||||
expect(translations.threadReplyLabel, isNotNull);
|
||||
expect(translations.onlyVisibleToYouText, isNotNull);
|
||||
expect(translations.threadReplyCountText(3), isNotNull);
|
||||
expect(
|
||||
translations.attachmentsUploadProgressText(remaining: 3, total: 10),
|
||||
isNotNull,
|
||||
);
|
||||
expect(
|
||||
translations.pinnedByUserText(
|
||||
pinnedBy: User(id: 'pinned-by-user-id'),
|
||||
currentUser: OwnUser(id: 'current-user-id'),
|
||||
),
|
||||
isNotNull,
|
||||
);
|
||||
expect(translations.emptyMessagesText, isNotNull);
|
||||
expect(translations.genericErrorText, isNotNull);
|
||||
expect(translations.loadingMessagesError, isNotNull);
|
||||
expect(translations.resultCountText(3), isNotNull);
|
||||
expect(translations.messageDeletedText, isNotNull);
|
||||
expect(translations.messageDeletedLabel, isNotNull);
|
||||
expect(translations.messageReactionsLabel, isNotNull);
|
||||
expect(translations.emptyChatMessagesText, isNotNull);
|
||||
expect(translations.threadSeparatorText(3), isNotNull);
|
||||
expect(translations.connectedLabel, isNotNull);
|
||||
expect(translations.disconnectedLabel, isNotNull);
|
||||
expect(translations.reconnectingLabel, isNotNull);
|
||||
expect(translations.alsoSendAsDirectMessageLabel, isNotNull);
|
||||
expect(translations.addACommentOrSendLabel, isNotNull);
|
||||
expect(translations.searchGifLabel, isNotNull);
|
||||
expect(translations.writeAMessageLabel, isNotNull);
|
||||
expect(translations.instantCommandsLabel, isNotNull);
|
||||
expect(translations.fileTooLargeAfterCompressionError, isNotNull);
|
||||
expect(translations.fileTooLargeError, isNotNull);
|
||||
expect(translations.emojiMatchingQueryText('sahil'), isNotNull);
|
||||
expect(translations.addAFileLabel, isNotNull);
|
||||
expect(translations.photoFromCameraLabel, isNotNull);
|
||||
expect(translations.uploadAFileLabel, isNotNull);
|
||||
expect(translations.uploadAPhotoLabel, isNotNull);
|
||||
expect(translations.uploadAVideoLabel, isNotNull);
|
||||
expect(translations.videoFromCameraLabel, isNotNull);
|
||||
expect(translations.okLabel, isNotNull);
|
||||
expect(translations.somethingWentWrongError, isNotNull);
|
||||
expect(translations.addMoreFilesLabel, isNotNull);
|
||||
expect(translations.enablePhotoAndVideoAccessMessage, isNotNull);
|
||||
expect(translations.allowGalleryAccessMessage, isNotNull);
|
||||
expect(translations.flagMessageLabel, isNotNull);
|
||||
expect(translations.flagMessageQuestion, isNotNull);
|
||||
expect(translations.flagLabel, isNotNull);
|
||||
expect(translations.cancelLabel, isNotNull);
|
||||
expect(translations.flagMessageSuccessfulLabel, isNotNull);
|
||||
expect(translations.flagMessageSuccessfulText, isNotNull);
|
||||
expect(translations.deleteLabel, isNotNull);
|
||||
expect(translations.deleteMessageLabel, isNotNull);
|
||||
expect(translations.deleteMessageQuestion, isNotNull);
|
||||
expect(translations.operationCouldNotBeCompletedText, isNotNull);
|
||||
expect(translations.replyLabel, isNotNull);
|
||||
// pinned
|
||||
expect(translations.togglePinUnpinText(pinned: true), isNotNull);
|
||||
// un-pinned
|
||||
expect(translations.togglePinUnpinText(pinned: false), isNotNull);
|
||||
// delete-failed
|
||||
expect(
|
||||
translations.toggleDeleteRetryDeleteMessageText(isDeleteFailed: true),
|
||||
isNotNull,
|
||||
);
|
||||
// first-delete
|
||||
expect(
|
||||
translations.toggleDeleteRetryDeleteMessageText(isDeleteFailed: false),
|
||||
isNotNull,
|
||||
);
|
||||
expect(translations.copyMessageLabel, isNotNull);
|
||||
expect(translations.editMessageLabel, isNotNull);
|
||||
// resend-failed
|
||||
expect(
|
||||
translations.toggleResendOrResendEditedMessage(isUpdateFailed: true),
|
||||
isNotNull,
|
||||
);
|
||||
// first resend
|
||||
expect(
|
||||
translations.toggleResendOrResendEditedMessage(isUpdateFailed: false),
|
||||
isNotNull,
|
||||
);
|
||||
expect(translations.photosLabel, isNotNull);
|
||||
// today
|
||||
expect(
|
||||
translations.sentAtText(
|
||||
date: DateTime.now(),
|
||||
time: DateTime.now(),
|
||||
),
|
||||
isNotNull,
|
||||
);
|
||||
// yesterday
|
||||
expect(
|
||||
translations.sentAtText(
|
||||
date: DateTime.now().subtract(const Duration(days: 1)),
|
||||
time: DateTime.now(),
|
||||
),
|
||||
isNotNull,
|
||||
);
|
||||
// any other day
|
||||
expect(
|
||||
translations.sentAtText(
|
||||
date: DateTime.now().subtract(const Duration(days: 3)),
|
||||
time: DateTime.now(),
|
||||
),
|
||||
isNotNull,
|
||||
);
|
||||
expect(translations.todayLabel, isNotNull);
|
||||
expect(translations.yesterdayLabel, isNotNull);
|
||||
expect(translations.channelIsMutedText, isNotNull);
|
||||
expect(translations.noTitleText, isNotNull);
|
||||
expect(translations.letsStartChattingLabel, isNotNull);
|
||||
expect(translations.sendingFirstMessageLabel, isNotNull);
|
||||
expect(translations.startAChatLabel, isNotNull);
|
||||
expect(translations.loadingChannelsError, isNotNull);
|
||||
expect(translations.deleteConversationLabel, isNotNull);
|
||||
expect(translations.deleteConversationQuestion, isNotNull);
|
||||
expect(translations.streamChatLabel, isNotNull);
|
||||
expect(translations.searchingForNetworkText, isNotNull);
|
||||
expect(translations.offlineLabel, isNotNull);
|
||||
expect(translations.tryAgainLabel, isNotNull);
|
||||
// 1 member
|
||||
expect(translations.membersCountText(1), isNotNull);
|
||||
// 3 members
|
||||
expect(translations.membersCountText(3), isNotNull);
|
||||
// 1 member
|
||||
expect(translations.watchersCountText(1), isNotNull);
|
||||
// 3 members
|
||||
expect(translations.watchersCountText(3), isNotNull);
|
||||
expect(translations.viewInfoLabel, isNotNull);
|
||||
expect(translations.leaveGroupLabel, isNotNull);
|
||||
expect(translations.leaveLabel, isNotNull);
|
||||
expect(translations.leaveConversationLabel, isNotNull);
|
||||
expect(translations.leaveConversationQuestion, isNotNull);
|
||||
expect(translations.showInChatLabel, isNotNull);
|
||||
expect(translations.saveImageLabel, isNotNull);
|
||||
expect(translations.saveVideoLabel, isNotNull);
|
||||
expect(translations.uploadErrorLabel, isNotNull);
|
||||
expect(translations.giphyLabel, isNotNull);
|
||||
expect(translations.shuffleLabel, isNotNull);
|
||||
expect(translations.sendLabel, isNotNull);
|
||||
expect(translations.withText, isNotNull);
|
||||
expect(translations.inText, isNotNull);
|
||||
expect(translations.youText, isNotNull);
|
||||
expect(translations.ofText, isNotNull);
|
||||
expect(translations.fileText, isNotNull);
|
||||
expect(translations.replyToMessageLabel, isNotNull);
|
||||
});
|
||||
}
|
||||
@@ -228,15 +228,18 @@ class StreamChatLocalizationsEn extends GlobalStreamChatLocalizations {
|
||||
String get photosLabel => 'Photos';
|
||||
|
||||
String _getDay(DateTime dateTime) {
|
||||
final now = Jiffy(DateTime.now());
|
||||
final date = Jiffy(dateTime);
|
||||
final now = DateTime.now();
|
||||
final today = DateTime(now.year, now.month, now.day);
|
||||
final yesterday = DateTime(now.year, now.month, now.day - 1);
|
||||
|
||||
if (date.isSame(now, Units.DAY)) {
|
||||
final date = DateTime(dateTime.year, dateTime.month, dateTime.day);
|
||||
|
||||
if (date == today) {
|
||||
return 'today';
|
||||
} else if (now.diff(date, Units.HOUR) < 24) {
|
||||
} else if (date == yesterday) {
|
||||
return 'yesterday';
|
||||
} else {
|
||||
return 'on ${date.MMMd}';
|
||||
return 'on ${Jiffy(date).MMMd}';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -232,15 +232,18 @@ class StreamChatLocalizationsFr extends GlobalStreamChatLocalizations {
|
||||
String get photosLabel => 'Photos';
|
||||
|
||||
String _getDay(DateTime dateTime) {
|
||||
final now = Jiffy(DateTime.now());
|
||||
final date = Jiffy(dateTime);
|
||||
final now = DateTime.now();
|
||||
final today = DateTime(now.year, now.month, now.day);
|
||||
final yesterday = DateTime(now.year, now.month, now.day - 1);
|
||||
|
||||
if (date.isSame(now, Units.DAY)) {
|
||||
final date = DateTime(dateTime.year, dateTime.month, dateTime.day);
|
||||
|
||||
if (date == today) {
|
||||
return "aujourd'hui";
|
||||
} else if (now.diff(date, Units.HOUR) < 24) {
|
||||
} else if (date == yesterday) {
|
||||
return 'hier';
|
||||
} else {
|
||||
return 'le ${date.MMMd}';
|
||||
return 'le ${Jiffy(date).MMMd}';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -227,15 +227,18 @@ class StreamChatLocalizationsHi extends GlobalStreamChatLocalizations {
|
||||
String get photosLabel => 'तस्वीरें';
|
||||
|
||||
String _getDay(DateTime dateTime) {
|
||||
final now = Jiffy(DateTime.now());
|
||||
final date = Jiffy(dateTime);
|
||||
final now = DateTime.now();
|
||||
final today = DateTime(now.year, now.month, now.day);
|
||||
final yesterday = DateTime(now.year, now.month, now.day - 1);
|
||||
|
||||
if (date.isSame(now, Units.DAY)) {
|
||||
final date = DateTime(dateTime.year, dateTime.month, dateTime.day);
|
||||
|
||||
if (date == today) {
|
||||
return 'आज';
|
||||
} else if (now.diff(date, Units.HOUR) < 24) {
|
||||
} else if (date == yesterday) {
|
||||
return 'कल';
|
||||
} else {
|
||||
return '${date.MMMd} को';
|
||||
return '${Jiffy(date).MMMd} को';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -229,21 +229,24 @@ Il file è troppo grande per essere caricato. Il limite è di $limitInMB MB.''';
|
||||
String get photosLabel => 'Foto';
|
||||
|
||||
String _getDay(DateTime dateTime) {
|
||||
final now = Jiffy(DateTime.now());
|
||||
final date = Jiffy(dateTime);
|
||||
final now = DateTime.now();
|
||||
final today = DateTime(now.year, now.month, now.day);
|
||||
final yesterday = DateTime(now.year, now.month, now.day - 1);
|
||||
|
||||
if (date.isSame(now, Units.DAY)) {
|
||||
final date = DateTime(dateTime.year, dateTime.month, dateTime.day);
|
||||
|
||||
if (date == today) {
|
||||
return 'oggi';
|
||||
} else if (now.diff(date, Units.HOUR) < 24) {
|
||||
} else if (date == yesterday) {
|
||||
return 'ieri';
|
||||
} else {
|
||||
return 'il ${date.MMMd}';
|
||||
return 'il ${Jiffy(date).MMMd}';
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
String sentAtText({required DateTime date, required DateTime time}) => '''
|
||||
Inviato il ${_getDay(date)} alle ${Jiffy(time.toLocal()).format('HH:mm')}''';
|
||||
String sentAtText({required DateTime date, required DateTime time}) =>
|
||||
"Inviato ${_getDay(date)} alle ${Jiffy(time.toLocal()).format('HH:mm')}";
|
||||
|
||||
@override
|
||||
String get todayLabel => 'Oggi';
|
||||
|
||||
@@ -114,6 +114,7 @@ void main() {
|
||||
isNotNull,
|
||||
);
|
||||
expect(localizations.photosLabel, isNotNull);
|
||||
// today
|
||||
expect(
|
||||
localizations.sentAtText(
|
||||
date: DateTime.now(),
|
||||
@@ -121,6 +122,22 @@ void main() {
|
||||
),
|
||||
isNotNull,
|
||||
);
|
||||
// yesterday
|
||||
expect(
|
||||
localizations.sentAtText(
|
||||
date: DateTime.now().subtract(const Duration(days: 1)),
|
||||
time: DateTime.now(),
|
||||
),
|
||||
isNotNull,
|
||||
);
|
||||
// any other day
|
||||
expect(
|
||||
localizations.sentAtText(
|
||||
date: DateTime.now().subtract(const Duration(days: 3)),
|
||||
time: DateTime.now(),
|
||||
),
|
||||
isNotNull,
|
||||
);
|
||||
expect(localizations.todayLabel, isNotNull);
|
||||
expect(localizations.yesterdayLabel, isNotNull);
|
||||
expect(localizations.channelIsMutedText, isNotNull);
|
||||
@@ -129,6 +146,7 @@ void main() {
|
||||
expect(localizations.sendingFirstMessageLabel, isNotNull);
|
||||
expect(localizations.startAChatLabel, isNotNull);
|
||||
expect(localizations.loadingChannelsError, isNotNull);
|
||||
expect(localizations.deleteConversationLabel, isNotNull);
|
||||
expect(localizations.deleteConversationQuestion, isNotNull);
|
||||
expect(localizations.streamChatLabel, isNotNull);
|
||||
expect(localizations.searchingForNetworkText, isNotNull);
|
||||
@@ -148,6 +166,7 @@ void main() {
|
||||
expect(localizations.leaveConversationLabel, isNotNull);
|
||||
expect(localizations.leaveConversationQuestion, isNotNull);
|
||||
expect(localizations.showInChatLabel, isNotNull);
|
||||
expect(localizations.saveImageLabel, isNotNull);
|
||||
expect(localizations.saveVideoLabel, isNotNull);
|
||||
expect(localizations.uploadErrorLabel, isNotNull);
|
||||
expect(localizations.giphyLabel, isNotNull);
|
||||
|
||||
Reference in New Issue
Block a user