forked from eatvio/eatvio_app
feat(tests): test coverage 60%
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
import 'package:eatvio_app/core/theme/theme_helper.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/price_choice_filter_widget.dart';
|
||||
import 'package:eatvio_app/generated/l10n.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:flutter_localizations/flutter_localizations.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:mockito/annotations.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
|
||||
import 'price_choice_filter_widget_test.mocks.dart';
|
||||
|
||||
@GenerateNiceMocks([MockSpec<PlansCubit>()])
|
||||
void main() {
|
||||
group('PriceChoiceFilterWidget', () {
|
||||
Widget wrap(PlansCubit cubit, Widget child) {
|
||||
return MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
localizationsDelegates: const [
|
||||
S.delegate,
|
||||
GlobalMaterialLocalizations.delegate,
|
||||
GlobalWidgetsLocalizations.delegate,
|
||||
GlobalCupertinoLocalizations.delegate,
|
||||
],
|
||||
supportedLocales: const [Locale('ru')],
|
||||
home: BlocProvider<PlansCubit>.value(
|
||||
value: cubit,
|
||||
child: Scaffold(body: child),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
testWidgets('renders with PlansCubit', (tester) async {
|
||||
final cubit = MockPlansCubit();
|
||||
const state = PlansState(
|
||||
isLoading: false,
|
||||
plans: [],
|
||||
errorMessage: null,
|
||||
filterState: PlansFilterState(priceFilter: (null, null), durationIndex: 0, typeIndex: 0),
|
||||
minPlanPrice: 100,
|
||||
maxPlanPrice: 1000,
|
||||
);
|
||||
|
||||
when(cubit.state).thenReturn(state);
|
||||
when(cubit.stream).thenAnswer((_) => const Stream<PlansState>.empty());
|
||||
when(cubit.close()).thenAnswer((_) async => Future<void>.value());
|
||||
when(cubit.changePriceFilter(any, any, disableDebounce: anyNamed('disableDebounce'))).thenReturn(null);
|
||||
|
||||
await tester.pumpWidget(wrap(cubit, PriceChoiceFilterWidget(plansCubit: cubit)));
|
||||
await tester.pump();
|
||||
|
||||
expect(find.byType(PriceChoiceFilterWidget), findsOneWidget);
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user