feat: add local database persistence

This commit is contained in:
2026-06-12 01:01:50 +08:00
parent 9ba681e3c7
commit b88b947e66
10 changed files with 4322 additions and 28 deletions
+20 -10
View File
@@ -1,6 +1,9 @@
import 'package:drift/native.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:focus_seed/src/app/focus_seed_app.dart';
import 'package:focus_seed/src/data/focus_seed_store.dart';
import 'package:focus_seed/src/data/local/focus_seed_database.dart';
import 'package:shared_preferences/shared_preferences.dart';
void main() {
@@ -14,8 +17,7 @@ void main() {
});
testWidgets('Today guides the user from intention to focus', (tester) async {
await tester.pumpWidget(const FocusSeedApp(locale: Locale('en')));
await tester.pumpAndSettle();
await pumpFocusSeedApp(tester, locale: const Locale('en'));
expect(find.text('Focus Seed'), findsOneWidget);
expect(find.text("TODAY'S INTENTION"), findsOneWidget);
@@ -35,8 +37,7 @@ void main() {
});
testWidgets('bottom navigation exposes Journey and Me', (tester) async {
await tester.pumpWidget(const FocusSeedApp(locale: Locale('en')));
await tester.pumpAndSettle();
await pumpFocusSeedApp(tester, locale: const Locale('en'));
await tester.tap(find.text('Journey'));
await tester.pumpAndSettle();
@@ -60,8 +61,7 @@ void main() {
tester.platformDispatcher.clearTextScaleFactorTestValue();
});
await tester.pumpWidget(const FocusSeedApp(locale: Locale('en')));
await tester.pumpAndSettle();
await pumpFocusSeedApp(tester, locale: const Locale('en'));
expect(find.text('Focus Seed'), findsOneWidget);
expect(find.byType(Scrollable), findsWidgets);
@@ -69,8 +69,7 @@ void main() {
});
testWidgets('development default uses concise Chinese copy', (tester) async {
await tester.pumpWidget(const FocusSeedApp());
await tester.pumpAndSettle();
await pumpFocusSeedApp(tester);
expect(find.text('Focus Seed'), findsOneWidget);
expect(find.text('\u4eca\u65e5\u76ee\u6807'), findsOneWidget);
@@ -88,8 +87,7 @@ void main() {
testWidgets('development language switch changes the active locale', (
tester,
) async {
await tester.pumpWidget(const FocusSeedApp());
await tester.pumpAndSettle();
await pumpFocusSeedApp(tester);
await tester.tap(find.text('\u6211\u7684'));
await tester.pumpAndSettle();
@@ -102,3 +100,15 @@ void main() {
expect(find.text('Language'), findsOneWidget);
});
}
Future<void> pumpFocusSeedApp(WidgetTester tester, {Locale? locale}) async {
final database = FocusSeedDatabase(NativeDatabase.memory());
addTearDown(database.close);
await tester.pumpWidget(
FocusSeedApp(
locale: locale,
focusSeedStore: FocusSeedStore(database: database),
),
);
await tester.pumpAndSettle();
}