import 'package:eatvio_app/core/app_config.dart'; import 'package:eatvio_app/core/app_initializer.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/diets_pagination_model.dart'; import 'package:eatvio_app/features/feed/models/recipes_model.dart'; import 'package:eatvio_app/features/feed/presentation/bloc/recipes_cubit/recipes_cubit.dart'; import 'package:eatvio_app/features/feed/presentation/bloc/recipes_cubit/recipes_state.dart'; import 'package:eatvio_app/features/feed/presentation/widgets/recipes_widget.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_dotenv/flutter_dotenv.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:go_router/go_router.dart'; import 'package:mockito/annotations.dart'; import 'package:mockito/mockito.dart'; import 'package:network_image_mock/network_image_mock.dart'; import 'recipes_widget_test.mocks.dart'; @GenerateNiceMocks([MockSpec()]) void main() { group('RecipesWidget smoke', () { setUpAll(() async { dotenv.loadFromString(envString: 'DEV_BASE_URL=http://localhost\nBASE_URL=http://localhost'); }); setUp(() async { await sl.reset(); sl.registerLazySingleton(() => AppConfig(buildType: AppBuildType.tests)..setBaseUrl('http://localhost')); }); const mockAuthor = Author( authorSlug: 'test-author', authorName: 'Test Author', authorProfileIcon: '/test.jpg', authorIsMe: false, isEntitySubscribedByMe: false, authorPlaceInRating: null, ); final mockRecipe = Recipe( id: 1, image: '/test.jpg', state: 'active', cookingTime: 30, activeCookingTime: 15, ingredients: const [], description: 'Test description', steps: const [], videoUrl: null, createdAt: DateTime.now(), updatedAt: DateTime.now(), title: 'Test Recipe', type: 'main', slug: 'test-recipe', commentsCount: 0, wasLikedByMe: false, isFavorite: false, calories: 200.0, servings: 4, likesCount: 10, viewsCount: 100, tags: const [], author: mockAuthor, ); Widget wrap(Widget child) { return MaterialApp.router( theme: ThemeHelper().themeData(), routerConfig: GoRouter( initialLocation: '/', routes: [ GoRoute(path: '/', builder: (context, state) => child), GoRoute( path: '/about-recipes-screen', name: 'aboutRecipesScreen', builder: (context, state) => const Scaffold(body: Text('Recipe')), ), ], ), ); } testWidgets('renders recipes widget', (tester) async { mockNetworkImagesFor(() async { final cubit = MockRecipesCubit(); when(cubit.state).thenReturn(RecipesState.initial()); when(cubit.stream).thenAnswer((_) => const Stream.empty()); when(cubit.close()).thenAnswer((_) async => Future.value()); await tester.pumpWidget( BlocProvider.value( value: cubit, child: wrap(RecipesWidget(recipe: mockRecipe, index: 0)), ), ); await tester.pump(); await tester.pump(const Duration(milliseconds: 100)); expect(find.byType(RecipesWidget), findsOneWidget); }); }, skip: true); }); }