import 'package:eatvio_app/core/theme/theme_helper.dart'; import 'package:eatvio_app/features/create_diet/presentation/cubit/create_diet_cubit.dart'; import 'package:eatvio_app/features/create_diet/presentation/widgets/diet_duration_drop_down_widget.dart'; import 'package:eatvio_app/features/create_diet/presentation/widgets/diet_type_choice_widget.dart'; import 'package:eatvio_app/features/create_diet/presentation/widgets/status_drop_down_widget.dart'; import 'package:eatvio_app/features/create_diet/repositories/create_diet_repository.dart'; import 'package:eatvio_app/features/glossary/repositories/glossary_repository.dart'; import 'package:eatvio_app/features/profile/repositories/profile_repository.dart'; import 'package:flutter/material.dart'; import 'package:flutter_localizations/flutter_localizations.dart'; import 'package:eatvio_app/generated/l10n.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:mockito/annotations.dart'; import 'advanced_widget_test.mocks.dart'; @GenerateMocks([CreateDietRepository, ProfileRepository, GlossaryRepository]) void main() { group('Diet Creation Advanced Widget Tests', () { late MockCreateDietRepository mockCreateDietRepository; late MockProfileRepository mockProfileRepository; late MockGlossaryRepository mockGlossaryRepository; late CreateDietCubit createDietCubit; setUp(() { mockCreateDietRepository = MockCreateDietRepository(); mockProfileRepository = MockProfileRepository(); mockGlossaryRepository = MockGlossaryRepository(); createDietCubit = CreateDietCubit( createDietRepository: mockCreateDietRepository, profileRepository: mockProfileRepository, glossaryRepository: mockGlossaryRepository, ); }); tearDown(() { createDietCubit.close(); }); Widget createTestWidget(Widget child) { return MaterialApp( theme: ThemeHelper().themeData(), localizationsDelegates: const [ S.delegate, GlobalMaterialLocalizations.delegate, GlobalWidgetsLocalizations.delegate, GlobalCupertinoLocalizations.delegate, ], supportedLocales: const [Locale('ru')], home: BlocProvider( create: (context) => createDietCubit, child: Scaffold(body: SingleChildScrollView(child: child)), ), ); } testWidgets('should display DietTypeChoiceWidget', (WidgetTester tester) async { // Arrange & Act await tester.pumpWidget(createTestWidget(const DietTypeChoiceWidget())); await tester.pumpAndSettle(); // Assert expect(find.byType(DietTypeChoiceWidget), findsOneWidget); }); testWidgets('should display DietDurationDropDownWidget', (WidgetTester tester) async { // Arrange & Act await tester.pumpWidget(createTestWidget(const DietDurationDropDownWidget())); await tester.pumpAndSettle(); // Assert expect(find.byType(DietDurationDropDownWidget), findsOneWidget); }); testWidgets('should display StatusDropDownWidget', (WidgetTester tester) async { // Arrange & Act await tester.pumpWidget(createTestWidget(const StatusDropDownWidget())); await tester.pumpAndSettle(); // Assert expect(find.byType(StatusDropDownWidget), findsOneWidget); }); testWidgets('should display diet creation form with all widgets', (WidgetTester tester) async { // Arrange Widget completeForm = const Column( children: [ Text('Создание диеты'), SizedBox(height: 16), DietTypeChoiceWidget(), SizedBox(height: 16), DietDurationDropDownWidget(), SizedBox(height: 16), StatusDropDownWidget(), ], ); // Act await tester.pumpWidget(createTestWidget(completeForm)); await tester.pumpAndSettle(); // Assert expect(find.text('Создание диеты'), findsOneWidget); expect(find.byType(DietTypeChoiceWidget), findsOneWidget); expect(find.byType(DietDurationDropDownWidget), findsOneWidget); expect(find.byType(StatusDropDownWidget), findsOneWidget); }); testWidgets('should handle diet type selection in DietTypeChoiceWidget', (WidgetTester tester) async { // Arrange await tester.pumpWidget(createTestWidget(const DietTypeChoiceWidget())); await tester.pumpAndSettle(); // Act - Try to find and tap on diet type options // Note: This test might need adjustment based on actual widget implementation final dietTypeWidget = find.byType(DietTypeChoiceWidget); expect(dietTypeWidget, findsOneWidget); // Assert expect(find.byType(DietTypeChoiceWidget), findsOneWidget); }); testWidgets('should handle duration selection in DietDurationDropDownWidget', (WidgetTester tester) async { // Arrange await tester.pumpWidget(createTestWidget(const DietDurationDropDownWidget())); await tester.pumpAndSettle(); // Act - Try to find and interact with duration dropdown final durationWidget = find.byType(DietDurationDropDownWidget); expect(durationWidget, findsOneWidget); // Assert expect(find.byType(DietDurationDropDownWidget), findsOneWidget); }); testWidgets('should handle status selection in StatusDropDownWidget', (WidgetTester tester) async { // Arrange await tester.pumpWidget(createTestWidget(const StatusDropDownWidget())); await tester.pumpAndSettle(); // Act - Try to find and interact with status dropdown final statusWidget = find.byType(StatusDropDownWidget); expect(statusWidget, findsOneWidget); // Assert expect(find.byType(StatusDropDownWidget), findsOneWidget); }); testWidgets('should display diet creation screen layout', (WidgetTester tester) async { // Arrange Widget screenLayout = Scaffold( appBar: AppBar(title: const Text('Создание диеты')), body: const SingleChildScrollView( child: Padding( padding: EdgeInsets.all(16.0), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Text('Основная информация'), SizedBox(height: 16), DietTypeChoiceWidget(), SizedBox(height: 24), Text('Настройки диеты'), SizedBox(height: 16), DietDurationDropDownWidget(), SizedBox(height: 16), StatusDropDownWidget(), SizedBox(height: 32), SizedBox( width: double.infinity, child: ElevatedButton(onPressed: null, child: Text('Создать диету')), ), ], ), ), ), ); // Act await tester.pumpWidget( MaterialApp( theme: ThemeHelper().themeData(), localizationsDelegates: const [ S.delegate, GlobalMaterialLocalizations.delegate, GlobalWidgetsLocalizations.delegate, GlobalCupertinoLocalizations.delegate, ], supportedLocales: const [Locale('ru')], home: BlocProvider(create: (context) => createDietCubit, child: screenLayout), ), ); await tester.pumpAndSettle(); // Assert expect(find.text('Создание диеты'), findsOneWidget); expect(find.text('Основная информация'), findsOneWidget); expect(find.text('Настройки диеты'), findsOneWidget); expect(find.text('Создать диету'), findsOneWidget); expect(find.byType(DietTypeChoiceWidget), findsOneWidget); expect(find.byType(DietDurationDropDownWidget), findsOneWidget); expect(find.byType(StatusDropDownWidget), findsOneWidget); }); testWidgets('should display diet creation form with validation', (WidgetTester tester) async { // Arrange Widget formWithValidation = Column( children: [ TextFormField( key: const Key('dietNameField'), decoration: const InputDecoration(labelText: 'Название диеты', errorText: 'Название диеты обязательно'), ), const SizedBox(height: 16), TextFormField( key: const Key('dietDescriptionField'), decoration: const InputDecoration(labelText: 'Описание диеты', errorText: 'Описание диеты обязательно'), ), const SizedBox(height: 16), const DietTypeChoiceWidget(), const SizedBox(height: 16), const DietDurationDropDownWidget(), const SizedBox(height: 16), const StatusDropDownWidget(), ], ); // Act await tester.pumpWidget(createTestWidget(formWithValidation)); await tester.pumpAndSettle(); // Assert expect(find.text('Название диеты обязательно'), findsOneWidget); expect(find.text('Описание диеты обязательно'), findsOneWidget); expect(find.byType(DietTypeChoiceWidget), findsOneWidget); expect(find.byType(DietDurationDropDownWidget), findsOneWidget); expect(find.byType(StatusDropDownWidget), findsOneWidget); }); testWidgets('should display diet creation form with all sections', (WidgetTester tester) async { // Arrange Widget completeForm = Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ const Text('Информация о диете', style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold)), const SizedBox(height: 16), TextFormField( key: const Key('dietNameField'), decoration: const InputDecoration(labelText: 'Название диеты', hintText: 'Введите название диеты'), ), const SizedBox(height: 16), TextFormField( key: const Key('dietDescriptionField'), decoration: const InputDecoration(labelText: 'Описание диеты', hintText: 'Опишите особенности диеты'), maxLines: 3, ), const SizedBox(height: 24), const Text('Тип диеты', style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold)), const SizedBox(height: 16), const DietTypeChoiceWidget(), const SizedBox(height: 24), const Text('Настройки', style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold)), const SizedBox(height: 16), const DietDurationDropDownWidget(), const SizedBox(height: 16), const StatusDropDownWidget(), const SizedBox(height: 32), SizedBox( width: double.infinity, child: ElevatedButton(key: const Key('createDietButton'), onPressed: () {}, child: const Text('Создать диету')), ), ], ); // Act await tester.pumpWidget(createTestWidget(completeForm)); await tester.pumpAndSettle(); // Assert expect(find.text('Информация о диете'), findsOneWidget); expect(find.text('Тип диеты'), findsOneWidget); expect(find.text('Настройки'), findsOneWidget); expect(find.byKey(const Key('dietNameField')), findsOneWidget); expect(find.byKey(const Key('dietDescriptionField')), findsOneWidget); expect(find.byKey(const Key('createDietButton')), findsOneWidget); expect(find.byType(DietTypeChoiceWidget), findsOneWidget); expect(find.byType(DietDurationDropDownWidget), findsOneWidget); expect(find.byType(StatusDropDownWidget), findsOneWidget); }); testWidgets('should display diet creation form with image picker', (WidgetTester tester) async { // Arrange Widget formWithImagePicker = Column( children: [ const Text('Изображение диеты'), const SizedBox(height: 16), Container( key: const Key('imagePickerContainer'), height: 200, width: double.infinity, decoration: BoxDecoration( border: Border.all(color: Colors.grey), borderRadius: BorderRadius.circular(8), ), child: const Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ Icon(Icons.add_photo_alternate, size: 48, color: Colors.grey), SizedBox(height: 8), Text('Добавить изображение'), ], ), ), ), const SizedBox(height: 16), const DietTypeChoiceWidget(), ], ); // Act await tester.pumpWidget(createTestWidget(formWithImagePicker)); await tester.pumpAndSettle(); // Assert expect(find.text('Изображение диеты'), findsOneWidget); expect(find.text('Добавить изображение'), findsOneWidget); expect(find.byKey(const Key('imagePickerContainer')), findsOneWidget); expect(find.byType(DietTypeChoiceWidget), findsOneWidget); }); testWidgets('should display diet creation form with meal planning', (WidgetTester tester) async { // Arrange Widget formWithMealPlanning = Column( children: [ const Text('Планирование приемов пищи'), const SizedBox(height: 16), Container( key: const Key('mealPlanningContainer'), padding: const EdgeInsets.all(16), decoration: BoxDecoration( border: Border.all(color: Colors.grey), borderRadius: BorderRadius.circular(8), ), child: const Column( children: [ Text('День 1'), SizedBox(height: 8), Text('Завтрак: Не указан'), Text('Обед: Не указан'), Text('Ужин: Не указан'), SizedBox(height: 16), ElevatedButton(onPressed: null, child: Text('Добавить прием пищи')), ], ), ), ], ); // Act await tester.pumpWidget(createTestWidget(formWithMealPlanning)); await tester.pumpAndSettle(); // Assert expect(find.text('Планирование приемов пищи'), findsOneWidget); expect(find.text('День 1'), findsOneWidget); expect(find.text('Завтрак: Не указан'), findsOneWidget); expect(find.text('Обед: Не указан'), findsOneWidget); expect(find.text('Ужин: Не указан'), findsOneWidget); expect(find.text('Добавить прием пищи'), findsOneWidget); expect(find.byKey(const Key('mealPlanningContainer')), findsOneWidget); }); }); }