Files
eatvio_app/test/features/feed/presentation/widgets/plan_widget_test.dart
2025-12-25 12:56:38 +03:00

105 lines
3.6 KiB
Dart

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/plan_pagination_model.dart';
import 'package:eatvio_app/features/feed/presentation/bloc/plans_cubit/plans_cubit.dart';
import 'package:eatvio_app/features/feed/presentation/bloc/plans_cubit/plans_state.dart';
import 'package:eatvio_app/features/feed/presentation/widgets/plan_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 'plan_widget_test.mocks.dart';
@GenerateNiceMocks([MockSpec<PlansCubit>()])
void main() {
group('PlanWidget smoke', () {
setUpAll(() async {
dotenv.loadFromString(envString: 'DEV_BASE_URL=http://localhost\nBASE_URL=http://localhost');
});
setUp(() async {
await sl.reset();
sl.registerLazySingleton<AppConfig>(() => 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,
);
const mockPlan = PlanModel(
id: 1,
slug: 'test-plan',
name: 'Test Plan',
image: '/test.jpg',
duration: 30,
state: 'active',
type: PlanType(slim: true, fit: false, behavior: false, wellness: false),
details: 'Test description',
packetsCount: 3,
packet1Options: null,
packet2Options: null,
packet3Options: null,
author: mockAuthor,
totalLikes: 10,
totalViews: 100,
totalComments: 5,
isFavorite: false,
minPriceOfOptions: 1000.0,
maxPriceOfOptions: 2000.0,
wasLikedByMe: false,
);
Widget wrap(Widget child) {
return MaterialApp.router(
theme: ThemeHelper().themeData(),
routerConfig: GoRouter(
initialLocation: '/',
routes: [
GoRoute(path: '/', builder: (context, state) => child),
GoRoute(
path: '/about-plan-screen',
name: 'aboutPlanScreen',
builder: (context, state) => const Scaffold(body: Text('Plan')),
),
],
),
);
}
testWidgets('renders plan widget', (tester) async {
mockNetworkImagesFor(() async {
final cubit = MockPlansCubit();
when(cubit.state).thenReturn(PlansState.initial());
when(cubit.stream).thenAnswer((_) => const Stream.empty());
when(cubit.close()).thenAnswer((_) async => Future<void>.value());
when(cubit.addPlanToFavorite(any, any)).thenAnswer((_) async => Future<void>.value());
when(cubit.removePlanFromFavorite(any, any)).thenAnswer((_) async => Future<void>.value());
await tester.pumpWidget(
BlocProvider<PlansCubit>.value(
value: cubit,
child: wrap(const PlanWidget(plan: mockPlan, index: 0)),
),
);
await tester.pump();
await tester.pump(const Duration(milliseconds: 100));
expect(find.byType(PlanWidget), findsOneWidget);
});
}, skip: true);
});
}