Implement initial features for husband's companion app, including mock data service and husband notes screen. Refactor scripture and cycle services for improved stability and testability. Address iOS Safari web app startup issue by removing deprecated initialization. - Implemented MockDataService and HusbandNotesScreen. - Converted _DashboardTab and DevotionalScreen to StatefulWidgets for robust scripture provider initialization. - Refactored CycleService to use immutable CycleInfo class, reducing UI rebuilds. - Removed deprecated window.flutterConfiguration from index.html, resolving Flutter web app startup failure on iOS Safari. - Updated and fixed related tests.
73 lines
2.4 KiB
Dart
73 lines
2.4 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);
|
|
});
|
|
});
|
|
}
|