Files
ReelShort/test/formatting/relative_date_time_test.dart
T

58 lines
1.3 KiB
Dart

// Author: fruit.com.cn
import 'package:flutter_test/flutter_test.dart';
import 'package:fruitshorts/core/formatting/relative_date_time.dart';
import 'package:fruitshorts/l10n/app_localizations_en.dart';
void main() {
final l10n = AppLocalizationsEn();
final now = DateTime(2026, 10, 21, 12);
test('should_show_just_now_under_one_minute', () {
expect(
formatRelativeDateTime(
now.subtract(const Duration(seconds: 59)),
l10n,
now: now,
),
'Just now',
);
});
test('should_use_minutes_below_sixty_minutes', () {
expect(
formatRelativeDateTime(
now.subtract(const Duration(minutes: 59)),
l10n,
now: now,
),
'59 min ago',
);
});
test('should_use_hours_below_twenty_four_hours', () {
expect(
formatRelativeDateTime(
now.subtract(const Duration(hours: 23)),
l10n,
now: now,
),
'23 hours ago',
);
});
test('should_use_month_and_day_for_same_year', () {
expect(
formatRelativeDateTime(DateTime(2026, 9, 3), l10n, now: now),
'09-03',
);
});
test('should_use_full_date_for_previous_year', () {
expect(
formatRelativeDateTime(DateTime(2025, 12, 31), l10n, now: now),
'2025-12-31',
);
});
}