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/register_screen.dart'; class _TestAuthNotifier extends AuthNotifier { _TestAuthNotifier() : super.test(const AuthState(status: AuthStatus.unauthenticated)); @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() { final router = GoRouter( initialLocation: '/auth/register', routes: [ GoRoute( path: '/auth/register', builder: (_, __) => const RegisterScreen(), ), GoRoute( path: '/auth/login', builder: (_, __) => const Scaffold(body: Text('Login Screen')), ), GoRoute( path: '/home', builder: (_, __) => const Scaffold(body: Text('Home Screen')), ), ], ); return ProviderScope( overrides: [ authProvider.overrideWith( (ref) => _TestAuthNotifier(), ), ], child: MaterialApp.router(routerConfig: router), ); } void main() { testWidgets('renders all form fields', (tester) async { await tester.pumpWidget(_buildTestWidget()); await tester.pumpAndSettle(); expect(find.text('Имя'), findsOneWidget); expect(find.text('Email'), findsOneWidget); expect(find.text('Пароль'), findsOneWidget); expect(find.text('Подтверждение пароля'), findsOneWidget); expect(find.text('Зарегистрироваться'), findsOneWidget); }); testWidgets('validates empty name', (tester) async { await tester.pumpWidget(_buildTestWidget()); await tester.pumpAndSettle(); await tester.tap(find.text('Зарегистрироваться')); await tester.pumpAndSettle(); expect(find.text('Введите имя'), findsOneWidget); }); testWidgets('validates password mismatch', (tester) async { await tester.pumpWidget(_buildTestWidget()); await tester.pumpAndSettle(); await tester.enterText( find.widgetWithText(TextFormField, 'Имя'), 'Test'); await tester.enterText( find.widgetWithText(TextFormField, 'Email'), 'test@test.com'); await tester.enterText( find.widgetWithText(TextFormField, 'Пароль'), 'password123'); await tester.enterText( find.widgetWithText(TextFormField, 'Подтверждение пароля'), 'different'); await tester.tap(find.text('Зарегистрироваться')); await tester.pumpAndSettle(); expect(find.text('Пароли не совпадают'), findsOneWidget); }); testWidgets('has link to login', (tester) async { await tester.pumpWidget(_buildTestWidget()); await tester.pumpAndSettle(); expect(find.text('Уже есть аккаунт? Войти'), findsOneWidget); }); testWidgets('shows registration title', (tester) async { await tester.pumpWidget(_buildTestWidget()); await tester.pumpAndSettle(); expect(find.text('Регистрация'), findsOneWidget); }); }