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
Some checks failed
Deploy to Play Store / build_and_deploy (push) Has been cancelled
This commit is contained in:
91
test/models/expense_test.dart
Normal file
91
test/models/expense_test.dart
Normal 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);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user