Add liked tenders functionality to HomeRepository and ViewModel
- 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.
This commit is contained in:
@@ -3,18 +3,54 @@ import 'package:tm_app/core/utils/date_utils.dart';
|
||||
|
||||
void main() {
|
||||
group('timeConvertor', () {
|
||||
test('returns dash for null and zero', () {
|
||||
test('returns dash for null, zero, and negative', () {
|
||||
expect(timeConvertor(null), '-');
|
||||
expect(timeConvertor(0), '-');
|
||||
expect(timeConvertor(-1), '-');
|
||||
});
|
||||
|
||||
test('formats unix seconds like moment.unix', () {
|
||||
expect(timeConvertor(1700000000), '2023-11-14');
|
||||
test('formats valid seconds as yyyy-MM-dd', () {
|
||||
final formatted = timeConvertor(1700000000);
|
||||
expect(formatted, matches(RegExp(r'^\d{4}-\d{2}-\d{2}$')));
|
||||
});
|
||||
|
||||
test('parses string timestamps from json', () {
|
||||
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);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user