Skip to content

Commit

Permalink
fix(test): fix formatTimestamp utils test
Browse files Browse the repository at this point in the history
  • Loading branch information
Mo2Hefny committed Nov 29, 2024
1 parent 3ff7a73 commit ee2bd38
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions test/core/utils_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -242,19 +242,27 @@ void main() {

group('formatTimestamp', () {
test('formats timestamp to hh:mm a', () {
final timestamp = DateTime(2024, 11, 23, 15, 17);
expect(formatTimestamp(timestamp), '03:17 PM');
final timestamp = DateTime.now().subtract(const Duration(hours: 2));
final expectedFormat = DateFormat('hh:mm a').format(timestamp);
expect(formatTimestamp(timestamp), expectedFormat);
});

test('formats timestamp to Yesterday', () {
test('formats timestamp to weekday', () {
final timestamp = DateTime.now().subtract(const Duration(days: 1));
expect(formatTimestamp(timestamp), 'Yesterday');
final expectedFormat = DateFormat('E').format(timestamp);
expect(formatTimestamp(timestamp), expectedFormat);
});

test('formats timestamp to weekday', () {
final timestamp = DateTime.now().subtract(const Duration(days: 2));
final expectedDay = DateFormat('E').format(timestamp);
expect(formatTimestamp(timestamp), expectedDay);
test('formats timestamp to MMM dd for past months', () {
final timestamp = DateTime.now().subtract(const Duration(days: 40));
final expectedFormat = DateFormat('MMM dd').format(timestamp);
expect(formatTimestamp(timestamp), expectedFormat);
});

test('formats timestamp to dd.MM.yy for past years', () {
final timestamp = DateTime.now().subtract(const Duration(days: 365));
final expectedFormat = DateFormat('dd.MM.yy').format(timestamp);
expect(formatTimestamp(timestamp), expectedFormat);
});
});
}

0 comments on commit ee2bd38

Please sign in to comment.