feat: replace json tools with local data controls
This commit is contained in:
@@ -0,0 +1,80 @@
|
||||
import 'package:drift/native.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:focus_seed/src/application/focus_seed_controller.dart';
|
||||
import 'package:focus_seed/src/core/date_keys.dart';
|
||||
import 'package:focus_seed/src/data/focus_seed_store.dart';
|
||||
import 'package:focus_seed/src/data/local/focus_seed_database.dart';
|
||||
import 'package:focus_seed/src/models/app_state.dart';
|
||||
import 'package:focus_seed/src/models/focus_session.dart';
|
||||
import 'package:focus_seed/src/models/habit.dart';
|
||||
import 'package:focus_seed/src/models/mood.dart';
|
||||
import 'package:focus_seed/src/models/reflection_entry.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
void main() {
|
||||
setUp(() {
|
||||
SharedPreferences.setMockInitialValues({});
|
||||
});
|
||||
|
||||
test('clearToday removes only current-day progress', () async {
|
||||
final database = FocusSeedDatabase(NativeDatabase.memory());
|
||||
addTearDown(database.close);
|
||||
final store = FocusSeedStore(database: database);
|
||||
final today = todayKey();
|
||||
final yesterday = dateKey(DateTime.now().subtract(const Duration(days: 1)));
|
||||
final habit = Habit(
|
||||
id: 'habit-1',
|
||||
title: 'Keep scope clear',
|
||||
createdAt: DateTime.now().subtract(const Duration(days: 2)),
|
||||
completedDates: {today, yesterday},
|
||||
);
|
||||
await store.save(
|
||||
AppState(
|
||||
anchor: 'Finish the cleanup',
|
||||
anchorDateKey: today,
|
||||
habits: [habit],
|
||||
sessions: [
|
||||
FocusSession(
|
||||
id: 'session-today',
|
||||
minutes: 25,
|
||||
completedAt: DateTime.now(),
|
||||
),
|
||||
FocusSession(
|
||||
id: 'session-yesterday',
|
||||
minutes: 15,
|
||||
completedAt: DateTime.now().subtract(const Duration(days: 1)),
|
||||
),
|
||||
],
|
||||
reflections: [
|
||||
ReflectionEntry(
|
||||
id: 'reflection-today',
|
||||
dateKey: today,
|
||||
note: 'Today note',
|
||||
mood: Mood.clear,
|
||||
createdAt: DateTime.now(),
|
||||
),
|
||||
ReflectionEntry(
|
||||
id: 'reflection-yesterday',
|
||||
dateKey: yesterday,
|
||||
note: 'Yesterday note',
|
||||
mood: Mood.calm,
|
||||
createdAt: DateTime.now().subtract(const Duration(days: 1)),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
final controller = FocusSeedController(store: store);
|
||||
await controller.load();
|
||||
|
||||
final cleared = await controller.clearToday();
|
||||
final state = controller.state!;
|
||||
|
||||
expect(cleared, isTrue);
|
||||
expect(state.activeAnchor(today), isEmpty);
|
||||
expect(state.habits.single.completedDates, {yesterday});
|
||||
expect(state.sessions.map((session) => session.id), ['session-yesterday']);
|
||||
expect(state.reflections.map((reflection) => reflection.id), [
|
||||
'reflection-yesterday',
|
||||
]);
|
||||
});
|
||||
}
|
||||
@@ -49,6 +49,20 @@ void main() {
|
||||
expect(find.text('Appearance'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('Me manages local data without JSON tools', (tester) async {
|
||||
await pumpFocusSeedApp(tester, locale: const Locale('en'));
|
||||
|
||||
await tester.tap(find.text('Me'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('Local data'), findsOneWidget);
|
||||
expect(find.text('Clear today'), findsOneWidget);
|
||||
await tester.scrollUntilVisible(find.text('Delete all local data'), 180);
|
||||
expect(find.text('Delete all local data'), findsOneWidget);
|
||||
expect(find.text('Export JSON'), findsNothing);
|
||||
expect(find.text('Import JSON'), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('Today remains usable at narrow width and 200 percent text', (
|
||||
tester,
|
||||
) async {
|
||||
|
||||
Reference in New Issue
Block a user