feat(tests): increased tests coverage

This commit is contained in:
misha
2025-12-25 12:56:38 +03:00
parent 5b705dfb72
commit 99659f7ea1
132 changed files with 10304 additions and 6226 deletions

View File

@@ -0,0 +1,108 @@
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/my_plans/presentation/cubit/my_plans_cubit.dart';
import 'package:eatvio_app/features/my_plans/presentation/cubit/my_plans_state.dart';
import 'package:eatvio_app/features/my_plans/presentation/widgets/my_plan_widget.dart';
import 'package:eatvio_app/generated/l10n.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_dotenv/flutter_dotenv.dart';
import 'package:flutter_localizations/flutter_localizations.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 'my_plan_widget_test.mocks.dart';
@GenerateNiceMocks([MockSpec<MyPlansCubit>()])
void main() {
group('MyPlanWidget 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'));
});
tearDown(() async {
await sl.reset();
});
Widget wrap(Widget child, MyPlansCubit? cubit) {
return MaterialApp.router(
theme: ThemeHelper().themeData(),
localizationsDelegates: const [
S.delegate,
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
],
supportedLocales: const [Locale('ru')],
routerConfig: GoRouter(
routes: [
GoRoute(
path: '/',
builder: (context, state) => Scaffold(
body: cubit != null
? BlocProvider<MyPlansCubit>.value(value: cubit, child: child)
: child,
),
),
GoRoute(
path: '/plan/:slug',
name: 'aboutPlanScreen',
builder: (context, state) => const SizedBox.shrink(),
),
],
),
);
}
testWidgets('renders my plan widget', (tester) async {
final cubit = MockMyPlansCubit();
final state = MyPlansState(selectedStateIndex: 0);
when(cubit.state).thenReturn(state);
when(cubit.stream).thenAnswer((_) => Stream.value(state));
when(cubit.close()).thenAnswer((_) async => Future<void>.value());
const plan = PlanModel(
id: 1,
slug: 'test-plan',
name: 'Test Plan',
image: '/test.jpg',
duration: 30,
state: 'active',
type: PlanType(fit: false, slim: false, behavior: false, wellness: false),
details: 'Test description',
packetsCount: 3,
author: Author(authorSlug: 'test-author', authorName: 'Test Author', authorProfileIcon: '/test.jpg', authorIsMe: false),
totalLikes: 10,
wasLikedByMe: false,
totalComments: 5,
totalViews: 100,
isFavorite: false,
minPriceOfOptions: 1000,
maxPriceOfOptions: 2000,
packet1Options: null,
packet2Options: null,
packet3Options: null,
);
await mockNetworkImagesFor(() async {
await tester.pumpWidget(wrap(const MyPlanWidget(plan: plan), cubit));
await tester.pump();
});
expect(find.byType(MyPlanWidget), findsOneWidget);
});
});
}