73 lines
2.5 KiB
Dart
73 lines
2.5 KiB
Dart
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:christian_period_tracker/services/cycle_service.dart';
|
|
import 'package:christian_period_tracker/models/user_profile.dart';
|
|
import 'package:christian_period_tracker/models/cycle_entry.dart';
|
|
|
|
void main() {
|
|
group('CycleService Tests', () {
|
|
test('calculateCycleInfo returns follicular phase for null profile', () {
|
|
final info = CycleService.calculateCycleInfo(null, []);
|
|
expect(info.phase, CyclePhase.follicular);
|
|
expect(info.dayOfCycle, 1);
|
|
});
|
|
|
|
test('calculateCycleInfo calculates follicular phase correctly (Day 7)', () {
|
|
final now = DateTime.now();
|
|
final lastPeriod = now.subtract(const Duration(days: 6)); // Today is Day 7
|
|
final user = UserProfile(
|
|
id: '1',
|
|
name: 'Test',
|
|
role: UserRole.wife,
|
|
relationshipStatus: RelationshipStatus.married,
|
|
averageCycleLength: 28,
|
|
lastPeriodStartDate: lastPeriod,
|
|
createdAt: now,
|
|
updatedAt: now,
|
|
);
|
|
|
|
final info = CycleService.calculateCycleInfo(user, []);
|
|
expect(info.dayOfCycle, 7);
|
|
expect(info.phase, CyclePhase.follicular);
|
|
});
|
|
|
|
test('calculateCycleInfo calculates menstrual phase correctly (Day 2)', () {
|
|
final now = DateTime.now();
|
|
final lastPeriod = now.subtract(const Duration(days: 1)); // Today is Day 2
|
|
final user = UserProfile(
|
|
id: '1',
|
|
name: 'Test',
|
|
role: UserRole.wife,
|
|
relationshipStatus: RelationshipStatus.married,
|
|
averageCycleLength: 28,
|
|
lastPeriodStartDate: lastPeriod,
|
|
createdAt: now,
|
|
updatedAt: now,
|
|
);
|
|
|
|
final info = CycleService.calculateCycleInfo(user, []);
|
|
expect(info.dayOfCycle, 2);
|
|
expect(info.phase, CyclePhase.menstrual);
|
|
});
|
|
|
|
test('calculateCycleInfo handles cycle length wrapping', () {
|
|
final now = DateTime.now();
|
|
// Last period was 30 days ago, cycle is 28 days -> Today is Day 3 of next cycle
|
|
final lastPeriod = now.subtract(const Duration(days: 30));
|
|
final user = UserProfile(
|
|
id: '1',
|
|
name: 'Test',
|
|
role: UserRole.wife,
|
|
relationshipStatus: RelationshipStatus.married,
|
|
averageCycleLength: 28,
|
|
lastPeriodStartDate: lastPeriod,
|
|
createdAt: now,
|
|
updatedAt: now,
|
|
);
|
|
|
|
final info = CycleService.calculateCycleInfo(user, []);
|
|
expect(info.dayOfCycle, 3);
|
|
expect(info.phase, CyclePhase.menstrual);
|
|
});
|
|
});
|
|
}
|