Resolve all lints and deprecation warnings

This commit is contained in:
2026-01-09 10:04:51 -06:00
parent 512577b092
commit a799e9cf59
56 changed files with 2819 additions and 3159 deletions

View File

@@ -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);
});
});
}
}

View File

@@ -7,7 +7,6 @@ import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:hive_flutter/hive_flutter.dart';
import 'package:path_provider_platform_interface/path_provider_platform_interface.dart';
import 'package:path_provider_linux/path_provider_linux.dart';
import 'package:mockito/mockito.dart';
import 'mocks.mocks.dart'; // Generated mock file
@@ -36,7 +35,7 @@ void main() {
// Initialize path_provider_platform_interface for testing
// This is a common pattern for mocking platform-specific plugins in tests.
PathProviderPlatform.instance = _MockPathProviderPlatform();
testPath = Directory.current.path + '/test_hive_temp';
testPath = '${Directory.current.path}/test_hive_temp';
// Ensure the directory exists
final Directory tempDir = Directory(testPath);
@@ -46,7 +45,8 @@ void main() {
// Create and configure the mock BibleXmlParser
final mockBibleXmlParser = MockBibleXmlParser();
when(mockBibleXmlParser.getVerseFromAsset(any, any)).thenAnswer((invocation) async {
when(mockBibleXmlParser.getVerseFromAsset(any, any))
.thenAnswer((invocation) async {
final String reference = invocation.positionalArguments[1];
// Return a mock verse based on the reference for testing purposes
return 'Mock Verse for $reference';
@@ -58,7 +58,8 @@ void main() {
'flutter/assets',
(ByteData? message) async {
final String key = utf8.decode(message!.buffer.asUint8List());
if (key == 'assets/scriptures.json' || key == 'assets/scriptures_optimized.json') {
if (key == 'assets/scriptures.json' ||
key == 'assets/scriptures_optimized.json') {
final json = {
"menstrual": [
{
@@ -120,8 +121,10 @@ void main() {
Hive.init(testPath);
Hive.registerAdapter(ScriptureAdapter()); // Register your adapter
Hive.registerAdapter(BibleTranslationAdapter()); // Register BibleTranslationAdapter
database = ScriptureDatabase(bibleXmlParser: mockBibleXmlParser); // Instantiate with mock
Hive.registerAdapter(
BibleTranslationAdapter()); // Register BibleTranslationAdapter
database = ScriptureDatabase(
bibleXmlParser: mockBibleXmlParser); // Instantiate with mock
await database.loadScriptures();
});
@@ -145,11 +148,11 @@ void main() {
class _MockPathProviderPlatform extends PathProviderPlatform {
@override
Future<String?> getApplicationSupportPath() async {
return Directory.current.path + '/test_hive_temp';
return '${Directory.current.path}/test_hive_temp';
}
@override
Future<String?> getApplicationDocumentsPath() async {
return Directory.current.path + '/test_hive_temp';
return '${Directory.current.path}/test_hive_temp';
}
}

View File

@@ -1,6 +1,4 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:christian_period_tracker/main.dart';
void main() {
testWidgets('App loads correctly', (WidgetTester tester) async {