import 'package:eatvio_app/core/app_initializer.dart'; import 'package:eatvio_app/core/di/app_config_registration.dart'; import 'package:eatvio_app/core/models/pagination_model.dart'; import 'package:eatvio_app/features/bottom_navigation_bar/presentation/bloc/profile_avatar_cubit/profile_avatar_cubit.dart'; import 'package:eatvio_app/features/bottom_navigation_bar/presentation/bloc/profile_avatar_cubit/profile_avatar_state.dart'; import 'package:eatvio_app/features/feed/models/comment_model.dart'; import 'package:eatvio_app/features/feed/presentation/widgets/comments_widget.dart'; import 'package:eatvio_app/features/profile/models/profile_model.dart'; import 'package:eatvio_app/generated/l10n.dart'; import 'package:flutter/material.dart'; import 'package:flutter_dotenv/flutter_dotenv.dart'; import 'package:flutter_localizations/flutter_localizations.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:get_it/get_it.dart'; import 'package:mocktail/mocktail.dart'; import 'package:network_image_mock/network_image_mock.dart'; class MockProfileAvatarCubit extends Mock implements ProfileAvatarCubit {} void main() { late MockProfileAvatarCubit mockProfileAvatarCubit; setUpAll(() async { GetIt.instance.reset(); // Инициализируем dotenv для AppConfig dotenv.loadFromString(envString: 'DEV_BASE_URL=http://localhost\nBASE_URL=http://localhost'); }); setUp(() { mockProfileAvatarCubit = MockProfileAvatarCubit(); GetIt.instance.registerSingleton(mockProfileAvatarCubit); // Регистрируем AppConfig для тестов AppConfigRegistration.registerAppConfig(buildType: AppBuildType.tests); }); tearDown(() { GetIt.instance.reset(); }); group('CommentsWidget', () { testWidgets('отображается как виджет', (WidgetTester tester) async { const testProfile = ProfileModel( id: 1, slug: 'test-user', name: 'Test User', email: 'test@example.com', phoneConfirmationState: 'confirmed', isPublicProfile: true, isBlockedByMe: false, isBlockedByAuthor: false, isBlockedByUser: false, isEntitySubscribedByMe: false, profilePhotoUrl: '', roles: [], badges: [], subscriptions: [], subscribers: [], ); when(() => mockProfileAvatarCubit.state).thenReturn(const ProfileAvatarState.loaded(profile: testProfile)); const commentModel = CommentModel( data: [], links: Links(first: '', last: '', prev: null, next: null), meta: Meta(currentPage: 1, from: null, lastPage: 1, links: [], perPage: 10, to: null, total: 0), ); await tester.pumpWidget( MaterialApp( localizationsDelegates: const [ S.delegate, GlobalMaterialLocalizations.delegate, GlobalWidgetsLocalizations.delegate, GlobalCupertinoLocalizations.delegate, ], supportedLocales: S.delegate.supportedLocales, home: const Scaffold( body: CommentsWidget(id: '1', commentSourceType: CommentSourceType.blogPost, comment: commentModel), ), ), ); expect(find.byType(CommentsWidget), findsOneWidget); }); testWidgets('отображает комментарии', (WidgetTester tester) async { const testProfile = ProfileModel( id: 1, slug: 'test-author', name: 'Test Author', email: 'test@example.com', phoneConfirmationState: 'confirmed', isPublicProfile: true, isBlockedByMe: false, isBlockedByAuthor: false, isBlockedByUser: false, isEntitySubscribedByMe: false, profilePhotoUrl: '', roles: [], badges: [], subscriptions: [], subscribers: [], ); when(() => mockProfileAvatarCubit.state).thenReturn(const ProfileAvatarState.loaded(profile: testProfile)); final comment = Comment( id: 1, authorName: 'Test Author', authorSlug: 'test-author', authorProfileIcon: '', body: 'Test comment', childrenComments: [], createdAt: DateTime.now(), ); final commentModel = CommentModel( data: [comment], links: const Links(first: '', last: '', prev: null, next: null), meta: const Meta(currentPage: 1, from: null, lastPage: 1, links: [], perPage: 10, to: null, total: 0), ); // Используем mockNetworkImages для обработки NetworkImage в тестах await mockNetworkImagesFor(() async { await tester.pumpWidget( MaterialApp( localizationsDelegates: const [ S.delegate, GlobalMaterialLocalizations.delegate, GlobalWidgetsLocalizations.delegate, GlobalCupertinoLocalizations.delegate, ], supportedLocales: S.delegate.supportedLocales, home: Scaffold( body: CommentsWidget(id: '1', commentSourceType: CommentSourceType.blogPost, comment: commentModel), ), ), ); await tester.pumpAndSettle(); expect(find.byType(CommentsWidget), findsOneWidget); }); }); }); }