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

View File

@@ -0,0 +1,91 @@
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:travel_mate/models/expense.dart';
import 'package:travel_mate/models/expense_split.dart';
void main() {
group('Expense Model Tests', () {
const id = 'expense1';
const groupId = 'group1';
const description = 'Lunch';
const amount = 50.0;
const currency = ExpenseCurrency.eur;
const amountInEur = 50.0;
const category = ExpenseCategory.restaurant;
const paidById = 'user1';
const paidByName = 'Alice';
final date = DateTime(2023, 6, 1);
final createdAt = DateTime(2023, 6, 1);
const split = ExpenseSplit(
userId: 'user1',
userName: 'Alice',
amount: 25.0,
);
const splits = [
split,
ExpenseSplit(userId: 'user2', userName: 'Bob', amount: 25.0),
];
final expense = Expense(
id: id,
groupId: groupId,
description: description,
amount: amount,
currency: currency,
amountInEur: amountInEur,
category: category,
paidById: paidById,
paidByName: paidByName,
date: date,
createdAt: createdAt,
splits: splits,
);
test('supports value equality', () {
final expense2 = Expense(
id: id,
groupId: groupId,
description: description,
amount: amount,
currency: currency,
amountInEur: amountInEur,
category: category,
paidById: paidById,
paidByName: paidByName,
date: date,
createdAt: createdAt,
splits: splits,
);
expect(expense, equals(expense2));
});
group('fromMap', () {
test('parses correctly', () {
final map = {
'groupId': groupId,
'description': description,
'amount': amount,
'currency': 'EUR',
'amountInEur': amountInEur,
'category': 'restaurant', // matching category name
'paidById': paidById,
'paidByName': paidByName,
'date': Timestamp.fromDate(date),
'createdAt': Timestamp.fromDate(createdAt),
'splits': splits.map((s) => s.toMap()).toList(),
};
final fromMapExpense = Expense.fromMap(map, id);
expect(fromMapExpense, equals(expense));
});
});
group('copyWith', () {
test('updates fields correctly', () {
final updated = expense.copyWith(amount: 100.0);
expect(updated.amount, 100.0);
expect(updated.description, description);
});
});
});
}