Skip to content

Commit

Permalink
Updated to v2.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
nixrajput committed Sep 13, 2024
1 parent 4496625 commit 0c3e348
Show file tree
Hide file tree
Showing 12 changed files with 1,333 additions and 34 deletions.
1 change: 1 addition & 0 deletions lib/get_time_ago.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export 'package:get_time_ago/src/messages/languages/ja_msg.dart';
export 'package:get_time_ago/src/messages/languages/ko_msg.dart';
export 'package:get_time_ago/src/messages/languages/oc_msg.dart';
export 'package:get_time_ago/src/messages/languages/pt_br_msg.dart';
export 'package:get_time_ago/src/messages/languages/ro_msg.dart';
export 'package:get_time_ago/src/messages/languages/tr_msg.dart';
export 'package:get_time_ago/src/messages/languages/ur_msg.dart';
export 'package:get_time_ago/src/messages/languages/vi_msg.dart';
Expand Down
2 changes: 1 addition & 1 deletion test/get_time_ago_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ void main() {
return DateTime.now().subtract(duration);
}

group('GetTimeAgo parse function', () {
group('GetTimeAgo Test Cases', () {
test('Test seconds ago (less than 15 seconds)', () {
final dateTime = _getRelativeDateTime(const Duration(seconds: 10));
final result = GetTimeAgo.parse(dateTime);
Expand Down
170 changes: 170 additions & 0 deletions test/messages/language/ar_msg_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
import 'package:get_time_ago/get_time_ago.dart';
import 'package:test/test.dart';

void main() {
final messages = ArabicMessages();

group('ArabicMessages Test', () {
test('prefixAgo should return "قبل"', () {
expect(messages.prefixAgo(), 'قبل');
});

test('suffixAgo should return empty string', () {
expect(messages.suffixAgo(), '');
});

test('justNow should return "الآن"', () {
expect(messages.justNow(10), 'الآن');
});

test('secsAgo should return correct seconds ago format', () {
expect(messages.secsAgo(5), '۵ ثوان');
});

test('minAgo should return "دقيقة واحدة"', () {
expect(messages.minAgo(1), 'دقيقة واحدة');
});

test('minsAgo should return correct plural form for 2 minutes', () {
expect(messages.minsAgo(2), 'دقيقتين');
});

test('minsAgo should return correct plural form for more than 2 minutes',
() {
expect(messages.minsAgo(5), '۵ دقائق');
});

test('hourAgo should return "ساعة واحدة"', () {
expect(messages.hourAgo(60), 'ساعة واحدة');
});

test('hoursAgo should return correct plural form for 2 hours', () {
expect(messages.hoursAgo(2), 'ساعتين');
});

test('hoursAgo should return correct plural form for more than 2 hours',
() {
expect(messages.hoursAgo(5), '۵ ساعات');
});

test('dayAgo should return "يوم واحد"', () {
expect(messages.dayAgo(24), 'يوم واحد');
});

test('daysAgo should return correct plural form for 2 days', () {
expect(messages.daysAgo(2), 'يومين');
});

test('daysAgo should return correct plural form for more than 2 days', () {
expect(messages.daysAgo(5), '۵ أيام');
});

test('wordSeparator should return a space', () {
expect(messages.wordSeparator(), ' ');
});
});

// Helper function to get the DateTime relative to now
DateTime _getRelativeDateTime(Duration duration) {
return DateTime.now().subtract(duration);
}

group('GetTimeAgo Test with Arabic Locale', () {
test('should return الآن for time less than 15 seconds', () {
final result = GetTimeAgo.parse(
_getRelativeDateTime(const Duration(seconds: 0)),
locale: 'ar',
);
expect(result, 'الآن');
});

test('should return correct format for 30 seconds ago', () {
final result = GetTimeAgo.parse(
_getRelativeDateTime(const Duration(seconds: 30)),
locale: 'ar',
);
expect(result, 'قبل ۳۰ ثوان');
});

test('should return دقيقة واحدة for 1 minute ago', () {
final result = GetTimeAgo.parse(
_getRelativeDateTime(const Duration(minutes: 1)),
locale: 'ar',
);
expect(result, 'قبل دقيقة واحدة');
});

test('should return دقيقتين for 2 minutes ago', () {
final result = GetTimeAgo.parse(
_getRelativeDateTime(const Duration(minutes: 2)),
locale: 'ar',
);
print(result.toString() == 'قبل دقيقتين');
expect(result, 'قبل دقيقتين');
});

test('should return correct format for 5 minutes ago', () {
final result = GetTimeAgo.parse(
_getRelativeDateTime(const Duration(minutes: 5)),
locale: 'ar',
);
expect(result, 'قبل ۵ دقائق');
});

test('should return ساعة واحدة for 1 hour ago', () {
final result = GetTimeAgo.parse(
_getRelativeDateTime(const Duration(hours: 1)),
locale: 'ar',
);
expect(result, 'قبل ساعة واحدة');
});

test('should return ساعتين for 2 hours ago', () {
final result = GetTimeAgo.parse(
_getRelativeDateTime(const Duration(hours: 2)),
locale: 'ar',
);
expect(result, 'قبل ساعتين');
});

test('should return correct format for 5 hours ago', () {
final result = GetTimeAgo.parse(
_getRelativeDateTime(const Duration(hours: 5)),
locale: 'ar',
);
expect(result, 'قبل ۵ ساعات');
});

test('should return يوم واحد for 1 day ago', () {
final result = GetTimeAgo.parse(
_getRelativeDateTime(const Duration(days: 1)),
locale: 'ar',
);
expect(result, 'قبل يوم واحد');
});

test('should return يومين for 2 days ago', () {
final result = GetTimeAgo.parse(
_getRelativeDateTime(const Duration(days: 2)),
locale: 'ar',
);
expect(result, 'قبل يومين');
});

test('should return correct format for 5 days ago', () {
final result = GetTimeAgo.parse(
_getRelativeDateTime(const Duration(days: 5)),
locale: 'ar',
);
expect(result, 'قبل ۵ أيام');
});

test('should return formatted date for dates beyond 7 days', () {
final result = GetTimeAgo.parse(
_getRelativeDateTime(const Duration(days: 10)),
locale: 'ar',
);
expect(result, isNot('قبل ۱۰ أيام'));
});
});
}
131 changes: 131 additions & 0 deletions test/messages/language/de_msg_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
import 'package:get_time_ago/get_time_ago.dart';
import 'package:test/test.dart';

void main() {
final messages = GermanMessages();

group('GermanMessages Test', () {
test('prefixAgo should return "vor"', () {
expect(messages.prefixAgo(), 'vor');
});

test('suffixAgo should return an empty string', () {
expect(messages.suffixAgo(), '');
});

test('justNow should return "vorhin"', () {
expect(messages.justNow(10), 'vorhin');
});

test('secsAgo should return correct seconds ago format', () {
expect(messages.secsAgo(25), '25 Sekunden');
});

test('minAgo should return "einer Minute"', () {
expect(messages.minAgo(1), 'einer Minute');
});

test('minsAgo should return correct minutes ago format', () {
expect(messages.minsAgo(5), '5 Minuten');
});

test('hourAgo should return "einer Stunde"', () {
expect(messages.hourAgo(60), 'einer Stunde');
});

test('hoursAgo should return correct hours ago format', () {
expect(messages.hoursAgo(5), '5 Stunden');
});

test('dayAgo should return "einem Tag"', () {
expect(messages.dayAgo(24), 'einem Tag');
});

test('daysAgo should return correct days ago format', () {
expect(messages.daysAgo(5), '5 Tagen');
});

test('wordSeparator should return a space', () {
expect(messages.wordSeparator(), ' ');
});
});

// Helper function to get the DateTime relative to now
DateTime _getRelativeDateTime(Duration duration) {
return DateTime.now().subtract(duration);
}

group('GetTimeAgo Test with German Locale', () {
test('should return vorhin for time less than 15 seconds', () {
final result = GetTimeAgo.parse(
_getRelativeDateTime(const Duration(seconds: 0)),
locale: 'de',
);
expect(result, 'vorhin');
});

test('should return correct format for seconds ago', () {
final result = GetTimeAgo.parse(
_getRelativeDateTime(const Duration(seconds: 20)),
locale: 'de',
);
expect(result, 'vor 20 Sekunden');
});

test('should return einer Minute for 1 minute ago', () {
final result = GetTimeAgo.parse(
_getRelativeDateTime(const Duration(minutes: 1)),
locale: 'de',
);
expect(result, 'vor einer Minute');
});

test('should return correct format for 5 minutes ago', () {
final result = GetTimeAgo.parse(
_getRelativeDateTime(const Duration(minutes: 5)),
locale: 'de',
);
expect(result, 'vor 5 Minuten');
});

test('should return einer Stunde for 1 hour ago', () {
final result = GetTimeAgo.parse(
_getRelativeDateTime(const Duration(hours: 1)),
locale: 'de',
);
expect(result, 'vor einer Stunde');
});

test('should return correct format for 5 hours ago', () {
final result = GetTimeAgo.parse(
_getRelativeDateTime(const Duration(hours: 5)),
locale: 'de',
);
expect(result, 'vor 5 Stunden');
});

test('should return einem Tag for 1 day ago', () {
final result = GetTimeAgo.parse(
_getRelativeDateTime(const Duration(days: 1)),
locale: 'de',
);
expect(result, 'vor einem Tag');
});

test('should return correct format for 5 days ago', () {
final result = GetTimeAgo.parse(
_getRelativeDateTime(const Duration(days: 5)),
locale: 'de',
);
expect(result, 'vor 5 Tagen');
});

test('should return formatted date for dates beyond 7 days', () {
final result = GetTimeAgo.parse(
_getRelativeDateTime(const Duration(days: 10)),
locale: 'de',
);
expect(result, isNot('vor 10 Tagen'));
});
});
}
Loading

0 comments on commit 0c3e348

Please sign in to comment.