Resolve all lints and deprecation warnings
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
import 'dart:io';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
import 'package:christian_period_tracker/models/scripture.dart';
|
||||
import 'package:christian_period_tracker/models/cycle_entry.dart';
|
||||
import 'package:christian_period_tracker/models/user_profile.dart';
|
||||
@@ -12,7 +11,8 @@ import 'package:hive_flutter/hive_flutter.dart';
|
||||
// Fake ScriptureDatabase implementation for testing
|
||||
class FakeScriptureDatabase implements ScriptureDatabase {
|
||||
final int Function(String phase) getScriptureCountForPhaseFn;
|
||||
final Scripture? Function(String phase, int index) getScriptureForPhaseByIndexFn;
|
||||
final Scripture? Function(String phase, int index)
|
||||
getScriptureForPhaseByIndexFn;
|
||||
final Scripture? Function(String phase)? getRandomScriptureForPhaseFn;
|
||||
|
||||
FakeScriptureDatabase({
|
||||
@@ -22,7 +22,8 @@ class FakeScriptureDatabase implements ScriptureDatabase {
|
||||
});
|
||||
|
||||
@override
|
||||
int getScriptureCountForPhase(String phase) => getScriptureCountForPhaseFn(phase);
|
||||
int getScriptureCountForPhase(String phase) =>
|
||||
getScriptureCountForPhaseFn(phase);
|
||||
|
||||
@override
|
||||
Scripture? getScriptureForPhaseByIndex(String phase, int index) =>
|
||||
@@ -30,7 +31,9 @@ class FakeScriptureDatabase implements ScriptureDatabase {
|
||||
|
||||
@override
|
||||
Scripture? getRandomScriptureForPhase(String phase) =>
|
||||
getRandomScriptureForPhaseFn != null ? getRandomScriptureForPhaseFn!(phase) : null;
|
||||
getRandomScriptureForPhaseFn != null
|
||||
? getRandomScriptureForPhaseFn!(phase)
|
||||
: null;
|
||||
|
||||
// Unimplemented methods (not used by ScriptureNotifier)
|
||||
@override
|
||||
@@ -40,10 +43,12 @@ class FakeScriptureDatabase implements ScriptureDatabase {
|
||||
Scripture getHusbandScripture() => throw UnimplementedError();
|
||||
|
||||
@override
|
||||
Future<void> loadScriptures() => Future.value(); // Can be mocked to do nothing
|
||||
Future<void> loadScriptures() =>
|
||||
Future.value(); // Can be mocked to do nothing
|
||||
|
||||
@override
|
||||
Scripture? getRecommendedScripture(CycleEntry entry) => throw UnimplementedError();
|
||||
Scripture? getRecommendedScripture(CycleEntry entry) =>
|
||||
throw UnimplementedError();
|
||||
|
||||
@override
|
||||
Scripture getScriptureForPhase(String phase) => throw UnimplementedError();
|
||||
@@ -55,7 +60,7 @@ void main() {
|
||||
late String testPath;
|
||||
|
||||
setUpAll(() async {
|
||||
testPath = Directory.current.path + '/test_hive_temp_scripture_provider';
|
||||
testPath = '${Directory.current.path}/test_hive_temp_scripture_provider';
|
||||
final Directory tempDir = Directory(testPath);
|
||||
if (!await tempDir.exists()) {
|
||||
await tempDir.create(recursive: true);
|
||||
@@ -142,22 +147,25 @@ void main() {
|
||||
// Force initial state to 0 for predictable cycling
|
||||
notifier.initializeScripture(CyclePhase.menstrual);
|
||||
// Override currentIndex to 0 for predictable test
|
||||
container.read(scriptureProvider.notifier).state = container.read(scriptureProvider).copyWith(currentIndex: 0);
|
||||
|
||||
container.read(scriptureProvider.notifier).state =
|
||||
container.read(scriptureProvider).copyWith(currentIndex: 0);
|
||||
|
||||
// First next
|
||||
notifier.getNextScripture();
|
||||
expect(container.read(scriptureProvider).currentScripture, testScripture2);
|
||||
expect(
|
||||
container.read(scriptureProvider).currentScripture, testScripture2);
|
||||
expect(container.read(scriptureProvider).currentIndex, 1);
|
||||
|
||||
// Second next
|
||||
notifier.getNextScripture();
|
||||
expect(container.read(scriptureProvider).currentScripture, testScripture3);
|
||||
expect(
|
||||
container.read(scriptureProvider).currentScripture, testScripture3);
|
||||
expect(container.read(scriptureProvider).currentIndex, 2);
|
||||
|
||||
// Wrap around
|
||||
notifier.getNextScripture();
|
||||
expect(container.read(scriptureProvider).currentScripture, testScripture1);
|
||||
expect(
|
||||
container.read(scriptureProvider).currentScripture, testScripture1);
|
||||
expect(container.read(scriptureProvider).currentIndex, 0);
|
||||
});
|
||||
|
||||
@@ -181,22 +189,25 @@ void main() {
|
||||
// Force initial state to 0 for predictable cycling
|
||||
notifier.initializeScripture(CyclePhase.menstrual);
|
||||
// Override currentIndex to 0 for predictable test
|
||||
container.read(scriptureProvider.notifier).state = container.read(scriptureProvider).copyWith(currentIndex: 0);
|
||||
|
||||
container.read(scriptureProvider.notifier).state =
|
||||
container.read(scriptureProvider).copyWith(currentIndex: 0);
|
||||
|
||||
// First previous (wraps around)
|
||||
notifier.getPreviousScripture();
|
||||
expect(container.read(scriptureProvider).currentScripture, testScripture3);
|
||||
expect(
|
||||
container.read(scriptureProvider).currentScripture, testScripture3);
|
||||
expect(container.read(scriptureProvider).currentIndex, 2);
|
||||
|
||||
// Second previous
|
||||
notifier.getPreviousScripture();
|
||||
expect(container.read(scriptureProvider).currentScripture, testScripture2);
|
||||
expect(
|
||||
container.read(scriptureProvider).currentScripture, testScripture2);
|
||||
expect(container.read(scriptureProvider).currentIndex, 1);
|
||||
|
||||
// Third previous
|
||||
notifier.getPreviousScripture();
|
||||
expect(container.read(scriptureProvider).currentScripture, testScripture1);
|
||||
expect(
|
||||
container.read(scriptureProvider).currentScripture, testScripture1);
|
||||
expect(container.read(scriptureProvider).currentIndex, 0);
|
||||
});
|
||||
|
||||
@@ -204,7 +215,8 @@ void main() {
|
||||
final scriptures = [testScripture1, testScripture2, testScripture3];
|
||||
final fakeDb = FakeScriptureDatabase(
|
||||
getScriptureCountForPhaseFn: (phase) => scriptures.length,
|
||||
getScriptureForPhaseByIndexFn: (phase, index) => scriptures[index % scriptures.length], // Ensure it always returns a valid one
|
||||
getScriptureForPhaseByIndexFn: (phase, index) => scriptures[
|
||||
index % scriptures.length], // Ensure it always returns a valid one
|
||||
);
|
||||
|
||||
container = ProviderContainer(
|
||||
@@ -224,7 +236,8 @@ void main() {
|
||||
final state = container.read(scriptureProvider);
|
||||
|
||||
expect(state.currentScripture, isNotNull);
|
||||
expect(state.currentScripture, isIn(scriptures)); // Ensure it's one of the valid scriptures
|
||||
expect(state.currentScripture,
|
||||
isIn(scriptures)); // Ensure it's one of the valid scriptures
|
||||
expect(state.currentIndex, isNonNegative);
|
||||
expect(state.currentIndex, lessThan(scriptures.length));
|
||||
});
|
||||
@@ -259,4 +272,4 @@ void main() {
|
||||
expect(container.read(scriptureProvider), initialState);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user