import 'package:eatvio_app/app_keys.dart'; import 'package:eatvio_app/core/app_config.dart'; import 'package:eatvio_app/core/app_initializer.dart'; import 'package:eatvio_app/core/locator_service.dart'; import 'package:eatvio_app/core/prefs.dart'; import 'package:eatvio_app/core/theme/theme_helper.dart'; import 'package:shared_preferences/shared_preferences.dart'; import 'package:eatvio_app/features/welcome/presentation/pages/welcome_screen.dart'; import 'package:flutter/material.dart'; import 'package:flutter_dotenv/flutter_dotenv.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:go_router/go_router.dart'; import 'package:mockito/annotations.dart'; import 'package:mockito/mockito.dart'; import 'welcome_screen_test.mocks.dart'; @GenerateNiceMocks([MockSpec()]) void main() { group('WelcomeScreen smoke', () { setUpAll(() async { dotenv.loadFromString( envString: 'DEV_BASE_URL=http://localhost\nBASE_URL=http://localhost', ); }); setUp(() async { SharedPreferences.setMockInitialValues({}); await sl.reset(); sl.registerLazySingleton( () => AppConfig(buildType: AppBuildType.tests) ..setBaseUrl('http://localhost'), ); }); tearDown(() async { await sl.reset(); }); Widget wrap(Widget child, {double textScale = 1}) { return MaterialApp.router( theme: ThemeHelper().themeData(), builder: (context, appChild) { return MediaQuery( data: MediaQuery.of( context, ).copyWith(textScaler: TextScaler.linear(textScale)), child: appChild ?? const SizedBox.shrink(), ); }, routerConfig: GoRouter( initialLocation: '/', routes: [ GoRoute(path: '/', builder: (context, state) => child), GoRoute( path: '/feed-screen', builder: (context, state) => const SizedBox.shrink(), ), GoRoute( path: '/auth-screen', builder: (context, state) => const SizedBox.shrink(), ), ], ), ); } testWidgets('renders welcome screen', (tester) async { final prefs = MockPrefs(); when(prefs.getBool(any)).thenReturn(false); when( prefs.setBool(any, any), ).thenAnswer((_) async => Future.value()); sl.registerLazySingleton(() => prefs); await tester.pumpWidget(wrap(const WelcomeScreen())); await tester.pump(); expect(find.byType(WelcomeScreen), findsOneWidget); expect(find.text('Добро пожаловать!'), findsOneWidget); expect(find.text('Начать пользоваться'), findsOneWidget); }); testWidgets('start button stays tappable when system text is enlarged', ( tester, ) async { final prefs = MockPrefs(); when(prefs.getBool(any)).thenReturn(false); when( prefs.setBool(any, any), ).thenAnswer((_) async => Future.value()); sl.registerLazySingleton(() => prefs); tester.view.physicalSize = const Size(390, 700); tester.view.devicePixelRatio = 1; addTearDown(tester.view.resetPhysicalSize); addTearDown(tester.view.resetDevicePixelRatio); await tester.pumpWidget(wrap(const WelcomeScreen(), textScale: 2.4)); await tester.pump(); final button = find.byKey(AppKeys.welcomeScreenButton); await tester.ensureVisible(button); await tester.pump(); expect(tester.takeException(), isNull); await tester.tap(button); await tester.pumpAndSettle(); expect(find.text('Начать пользоваться'), findsNothing); verify(prefs.setBool(any, true)).called(1); }); }); }