import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:go_router/go_router.dart'; import 'package:food_ai/core/auth/auth_provider.dart'; import 'package:food_ai/features/auth/login_screen.dart'; class _TestAuthNotifier extends AuthNotifier { _TestAuthNotifier(super.initialState) : super.test(); @override Future signInWithEmail(String email, String password) async {} @override Future signInWithGoogle() async {} @override Future register(String email, String password, String name) async {} @override Future signOut() async {} } Widget _buildTestWidget({AuthState? initialState}) { final authState = initialState ?? const AuthState(status: AuthStatus.unauthenticated); final router = GoRouter( initialLocation: '/auth/login', routes: [ GoRoute( path: '/auth/login', builder: (_, __) => const LoginScreen(), ), GoRoute( path: '/auth/register', builder: (_, __) => const Scaffold(body: Text('Register Screen')), ), GoRoute( path: '/home', builder: (_, __) => const Scaffold(body: Text('Home Screen')), ), ], ); return ProviderScope( overrides: [ authProvider.overrideWith( (ref) => _TestAuthNotifier(authState), ), ], child: MaterialApp.router(routerConfig: router), ); } void main() { testWidgets('renders email and password fields and buttons', (tester) async { await tester.pumpWidget(_buildTestWidget()); await tester.pumpAndSettle(); expect(find.text('Email'), findsOneWidget); expect(find.text('Пароль'), findsOneWidget); expect(find.text('Войти'), findsOneWidget); expect(find.text('Войти через Google'), findsOneWidget); expect(find.text('Нет аккаунта? Регистрация'), findsOneWidget); }); testWidgets('validates empty email', (tester) async { await tester.pumpWidget(_buildTestWidget()); await tester.pumpAndSettle(); await tester.tap(find.text('Войти')); await tester.pumpAndSettle(); expect(find.text('Введите email'), findsOneWidget); }); testWidgets('validates invalid email format', (tester) async { await tester.pumpWidget(_buildTestWidget()); await tester.pumpAndSettle(); await tester.enterText( find.widgetWithText(TextFormField, 'Email'), 'abc'); await tester.tap(find.text('Войти')); await tester.pumpAndSettle(); expect(find.text('Некорректный email'), findsOneWidget); }); testWidgets('validates short password', (tester) async { await tester.pumpWidget(_buildTestWidget()); await tester.pumpAndSettle(); await tester.enterText( find.widgetWithText(TextFormField, 'Email'), 'test@test.com'); await tester.enterText( find.widgetWithText(TextFormField, 'Пароль'), '123'); await tester.tap(find.text('Войти')); await tester.pumpAndSettle(); expect(find.text('Минимум 6 символов'), findsOneWidget); }); testWidgets('shows FoodAI branding', (tester) async { await tester.pumpWidget(_buildTestWidget()); await tester.pumpAndSettle(); expect(find.text('FoodAI'), findsOneWidget); expect(find.text('Управляйте питанием\nс помощью AI'), findsOneWidget); }); }