35af3e94ea
- Integrated LikedTendersService into HomeRepository to fetch the count of user-liked tenders. - Updated HomeViewModel to load and manage the userLikedTendersCount. - Adjusted UI components across home pages to display the liked tenders count. - Refactored date handling in date_utils.dart to improve timestamp parsing and validation. - Enhanced unit tests for date utilities to cover new edge cases.
57 lines
1.9 KiB
Dart
57 lines
1.9 KiB
Dart
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:tm_app/core/utils/date_utils.dart';
|
|
|
|
void main() {
|
|
group('timeConvertor', () {
|
|
test('returns dash for null, zero, and negative', () {
|
|
expect(timeConvertor(null), '-');
|
|
expect(timeConvertor(0), '-');
|
|
expect(timeConvertor(-1), '-');
|
|
});
|
|
|
|
test('formats valid seconds as yyyy-MM-dd', () {
|
|
final formatted = timeConvertor(1700000000);
|
|
expect(formatted, matches(RegExp(r'^\d{4}-\d{2}-\d{2}$')));
|
|
});
|
|
|
|
test('formats valid seconds with time when hasTime is true', () {
|
|
final formatted = timeConvertor(1700000000, hasTime: true);
|
|
expect(
|
|
formatted,
|
|
matches(RegExp(r'^\d{4}-\d{2}-\d{2} \d{2}:\d{2}$')),
|
|
);
|
|
});
|
|
|
|
test('treats values above 9999999999 as milliseconds', () {
|
|
// 1700000000000 ms and 1700000000 s should format to the same day.
|
|
expect(timeConvertor(1700000000000), timeConvertor(1700000000));
|
|
});
|
|
});
|
|
|
|
group('unixTimestampFromJson', () {
|
|
test('parses int and num', () {
|
|
expect(unixTimestampFromJson(1700000000), 1700000000);
|
|
expect(unixTimestampFromJson(1700000000.7), 1700000000);
|
|
});
|
|
|
|
test('parses numeric strings', () {
|
|
expect(unixTimestampFromJson('1700000000'), 1700000000);
|
|
expect(unixTimestampFromJson(' 1700000000 '), 1700000000);
|
|
});
|
|
|
|
test('returns null for empty, null, and non-numeric input', () {
|
|
expect(unixTimestampFromJson(null), isNull);
|
|
expect(unixTimestampFromJson(''), isNull);
|
|
expect(unixTimestampFromJson('abc'), isNull);
|
|
expect(unixTimestampFromJson(true), isNull);
|
|
});
|
|
|
|
test('rejects non-positive values', () {
|
|
expect(unixTimestampFromJson(0), isNull);
|
|
expect(unixTimestampFromJson(-1), isNull);
|
|
expect(unixTimestampFromJson('-1'), isNull);
|
|
expect(unixTimestampFromJson('0'), isNull);
|
|
});
|
|
});
|
|
}
|