feat: Introduce comprehensive unit tests for models and BLoCs using mockito and bloc_test, and refine TripBloc error handling.
Some checks failed
Deploy to Play Store / build_and_deploy (push) Has been cancelled

This commit is contained in:
Van Leemput Dayron
2025-12-05 11:55:20 +01:00
parent 9b11836409
commit cac0770467
17 changed files with 1608 additions and 48 deletions

100
test/models/group_test.dart Normal file
View File

@@ -0,0 +1,100 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:travel_mate/models/group.dart';
void main() {
group('Group Model Tests', () {
const id = 'group1';
const name = 'Paris Trip Group';
const tripId = 'trip1';
const createdBy = 'user1';
final createdAt = DateTime(2023, 1, 1);
final updatedAt = DateTime(2023, 1, 2);
const memberIds = ['user1', 'user2'];
final groupInstance = Group(
id: id,
name: name,
tripId: tripId,
createdBy: createdBy,
createdAt: createdAt,
updatedAt: updatedAt,
memberIds: memberIds,
);
test('props correct', () {
expect(groupInstance.id, id);
expect(groupInstance.name, name);
expect(groupInstance.tripId, tripId);
expect(groupInstance.createdBy, createdBy);
expect(groupInstance.createdAt, createdAt);
expect(groupInstance.updatedAt, updatedAt);
expect(groupInstance.memberIds, memberIds);
expect(groupInstance.members, isEmpty);
});
group('fromMap', () {
test('returns correct group from valid map', () {
final map = {
'name': name,
'tripId': tripId,
'createdBy': createdBy,
'createdAt': createdAt.millisecondsSinceEpoch,
'updatedAt': updatedAt.millisecondsSinceEpoch,
'memberIds': memberIds,
};
final fromMapGroup = Group.fromMap(map, id);
expect(fromMapGroup.id, id);
expect(fromMapGroup.name, name);
expect(fromMapGroup.tripId, tripId);
expect(fromMapGroup.createdBy, createdBy);
expect(fromMapGroup.createdAt, createdAt);
expect(fromMapGroup.updatedAt, updatedAt);
expect(fromMapGroup.memberIds, memberIds);
});
test('handles missing values gracefully', () {
final map = <String, dynamic>{};
final fromMapGroup = Group.fromMap(map, id);
expect(fromMapGroup.id, id);
expect(fromMapGroup.name, '');
expect(fromMapGroup.tripId, '');
expect(fromMapGroup.createdBy, '');
expect(fromMapGroup.memberIds, isEmpty);
});
});
group('toMap', () {
test('returns correct map', () {
final map = groupInstance.toMap();
expect(map['name'], name);
expect(map['tripId'], tripId);
expect(map['createdBy'], createdBy);
expect(map['createdAt'], createdAt.millisecondsSinceEpoch);
expect(map['updatedAt'], updatedAt.millisecondsSinceEpoch);
expect(map['memberIds'], memberIds);
});
});
group('copyWith', () {
test('returns object with updated values', () {
const newName = 'London Trip Group';
final updatedGroup = groupInstance.copyWith(name: newName);
expect(updatedGroup.name, newName);
expect(updatedGroup.id, id);
expect(updatedGroup.tripId, tripId);
});
test('returns distinct object but same values if no args', () {
final copy = groupInstance.copyWith();
expect(copy.id, groupInstance.id);
expect(copy.name, groupInstance.name);
// Note: Group does not implement == so we check reference inequality but value equality manually or trust fields are copied
expect(identical(copy, groupInstance), isFalse);
});
});
});
}