import 'package:eatvio_app/core/app_config.dart'; import 'package:eatvio_app/core/app_initializer.dart'; import 'package:eatvio_app/core/di/app_config_registration.dart'; import 'package:eatvio_app/core/locator_service.dart'; import 'package:eatvio_app/core/theme/theme_helper.dart'; import 'package:eatvio_app/features/feed/models/feed_consultant_model.dart'; import 'package:eatvio_app/features/feed/presentation/widgets/consultant_widget.dart'; import 'package:eatvio_app/features/profile/models/badge_model.dart'; import 'package:eatvio_app/generated/l10n.dart'; import 'package:flutter/material.dart'; import 'package:flutter_localizations/flutter_localizations.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:go_router/go_router.dart'; import 'package:flutter_dotenv/flutter_dotenv.dart'; import 'package:network_image_mock/network_image_mock.dart'; void main() { TestWidgetsFlutterBinding.ensureInitialized(); setUpAll(() async { // Initialize dotenv for tests dotenv.loadFromString(envString: 'DEV_BASE_URL=http://localhost\nBASE_URL=http://localhost'); }); group('ConsultantWidget', () { setUp(() async { await sl.reset(); dotenv.loadFromString(envString: 'DEV_BASE_URL=http://localhost\nBASE_URL=http://localhost'); AppConfigRegistration.registerAppConfig(buildType: AppBuildType.tests); // Ensure AppConfig has the correct baseUrl for image URL construction sl().setBaseUrl('http://localhost'); }); Widget createTestWidget(FeedConsultantModel consultant) { return MaterialApp.router( theme: ThemeHelper().themeData(), localizationsDelegates: const [ S.delegate, GlobalMaterialLocalizations.delegate, GlobalWidgetsLocalizations.delegate, GlobalCupertinoLocalizations.delegate, ], supportedLocales: const [Locale('ru'), Locale('en')], locale: const Locale('ru'), routerConfig: GoRouter( initialLocation: '/', routes: [ GoRoute( path: '/', builder: (context, state) => Scaffold( body: ConsultantWidget(consultant: consultant), ), ), GoRoute( path: '/profileScreen', name: 'profileScreen', builder: (context, state) => Scaffold( appBar: AppBar(title: const Text('Profile')), body: Center(child: Text('Profile: ${state.extra}')), ), ), ], ), ); } testWidgets('displays consultant information', (tester) async { await mockNetworkImagesFor(() async { const consultant = FeedConsultantModel( slug: 'test-consultant', name: 'Test Consultant', photo: 'https://example.com/photo.jpg', description: 'Test description', totalScores: 100, ratingPlace: 1, badges: [], ); await tester.pumpWidget(createTestWidget(consultant)); await tester.pumpAndSettle(); expect(find.text('Test Consultant'), findsOneWidget); expect(find.text('Рейтинг: 100'), findsOneWidget); expect(find.text('Test description'), findsOneWidget); }); }); testWidgets('displays consultant with badges', (tester) async { await mockNetworkImagesFor(() async { const consultant = FeedConsultantModel( slug: 'test-consultant', name: 'Test Consultant', photo: 'https://example.com/photo.jpg', description: 'Test description', totalScores: 100, ratingPlace: 1, badges: [ BadgeModel(id: 1, title: 'Badge 1', image: 'badge1.png', description: 'Description 1', type: 'test'), BadgeModel(id: 2, title: 'Badge 2', image: 'badge2.png', description: 'Description 2', type: 'test'), ], ); await tester.pumpWidget(createTestWidget(consultant)); await tester.pumpAndSettle(); expect(find.text('Test Consultant'), findsOneWidget); expect(find.byType(ConsultantWidget), findsOneWidget); }); }); testWidgets('displays rating place', (tester) async { await mockNetworkImagesFor(() async { const consultant = FeedConsultantModel( slug: 'test-consultant', name: 'Test Consultant', photo: 'https://example.com/photo.jpg', description: 'Test description', totalScores: 100, ratingPlace: 5, badges: [], ); await tester.pumpWidget(createTestWidget(consultant)); await tester.pumpAndSettle(); expect(find.text('5'), findsOneWidget); }); }); testWidgets('handles photo with https URL', (tester) async { await mockNetworkImagesFor(() async { const consultant = FeedConsultantModel( slug: 'test-consultant', name: 'Test Consultant', photo: 'https://example.com/photo.jpg', description: 'Test description', totalScores: 100, ratingPlace: 1, badges: [], ); await tester.pumpWidget(createTestWidget(consultant)); await tester.pumpAndSettle(); expect(find.byType(CircleAvatar), findsOneWidget); }); }); testWidgets('handles photo without https URL', (tester) async { await mockNetworkImagesFor(() async { const consultant = FeedConsultantModel( slug: 'test-consultant', name: 'Test Consultant', photo: '/storage/photo.jpg', description: 'Test description', totalScores: 100, ratingPlace: 1, badges: [], ); await tester.pumpWidget(createTestWidget(consultant)); await tester.pumpAndSettle(); expect(find.byType(CircleAvatar), findsOneWidget); }); }); }); }