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() { setUp(() { SharedPreferences.setMockInitialValues({}); }); test('locale policy defaults to English for release and Chinese for dev', () { expect(focusSeedDefaultLocale(isRelease: true), const Locale('en')); expect(focusSeedDefaultLocale(), const Locale('zh')); }); testWidgets('Today guides the user from intention to focus', (tester) async { await pumpFocusSeedApp(tester, locale: const Locale('en')); expect(find.text('Focus Seed'), findsOneWidget); expect(find.text("TODAY'S INTENTION"), findsOneWidget); expect(find.text("Set today's intention"), findsOneWidget); await tester.tap(find.text('Choose one outcome')); await tester.pumpAndSettle(); await tester.enterText( find.byType(TextField), 'Finish the launch checklist', ); await tester.tap(find.text('Save')); await tester.pumpAndSettle(); expect(find.text('Finish the launch checklist'), findsOneWidget); expect(find.text('Start 25 min'), findsOneWidget); }); testWidgets('bottom navigation exposes Journey and Me', (tester) async { await pumpFocusSeedApp(tester, locale: const Locale('en')); await tester.tap(find.text('Journey')); await tester.pumpAndSettle(); expect(find.text("Today's journey"), findsOneWidget); await tester.tap(find.text('Me')); await tester.pumpAndSettle(); expect(find.text('Your space'), findsOneWidget); 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('Journey opens history detail with empty states', (tester) async { await pumpFocusSeedApp(tester, locale: const Locale('en')); await tester.tap(find.text('Journey')); await tester.pumpAndSettle(); final journeyScroll = find.byType(Scrollable).first; await tester.scrollUntilVisible( find.text('This week'), 180, scrollable: journeyScroll, ); expect(find.text('This week'), findsOneWidget); await tester.scrollUntilVisible( find.text('View history'), 180, scrollable: journeyScroll, ); expect(find.text('View history'), findsOneWidget); await tester.tap(find.text('View history')); await tester.pumpAndSettle(); expect(find.text('History'), findsOneWidget); expect(find.text('No focus sessions yet'), findsOneWidget); await tester.tap(find.text('Notes')); await tester.pumpAndSettle(); expect(find.text('No notes yet'), findsOneWidget); }); testWidgets('Today remains usable at narrow width and 200 percent text', ( tester, ) async { tester.view.physicalSize = const Size(320, 700); tester.view.devicePixelRatio = 1; tester.platformDispatcher.textScaleFactorTestValue = 2; addTearDown(() { tester.view.resetPhysicalSize(); tester.view.resetDevicePixelRatio(); tester.platformDispatcher.clearTextScaleFactorTestValue(); }); await pumpFocusSeedApp(tester, locale: const Locale('en')); expect(find.text('Focus Seed'), findsOneWidget); expect(find.byType(Scrollable), findsWidgets); expect(tester.takeException(), isNull); }); testWidgets('development default uses concise Chinese copy', (tester) async { await pumpFocusSeedApp(tester); expect(find.text('Focus Seed'), findsOneWidget); expect(find.text('\u4eca\u65e5\u76ee\u6807'), findsOneWidget); expect(find.text('\u8bbe\u7f6e\u4eca\u65e5\u76ee\u6807'), findsOneWidget); await tester.scrollUntilVisible( find.text('\u8ba1\u5212\u4e00\u4e2a\u660e\u786e\u4efb\u52a1'), 180, ); expect( find.text('\u8ba1\u5212\u4e00\u4e2a\u660e\u786e\u4efb\u52a1'), findsOneWidget, ); }); testWidgets('development language switch changes the active locale', ( tester, ) async { await pumpFocusSeedApp(tester); await tester.tap(find.text('\u6211\u7684')); await tester.pumpAndSettle(); expect(find.text('\u8bed\u8a00'), findsOneWidget); await tester.tap(find.text('English')); await tester.pumpAndSettle(); expect(find.text('Your space'), findsOneWidget); expect(find.text('Language'), findsOneWidget); }); } Future 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(); }