forked from eatvio/eatvio_app
feat(tests): increased tests coverage
This commit is contained in:
@@ -0,0 +1,92 @@
|
||||
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/feed_blog_post_model.dart';
|
||||
import 'package:eatvio_app/features/feed/presentation/bloc/feed_cubit/feed_cubit.dart';
|
||||
import 'package:eatvio_app/features/feed/presentation/bloc/feed_cubit/feed_state.dart';
|
||||
import 'package:eatvio_app/features/feed/presentation/widgets/blog_post_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 'blog_post_widget_test.mocks.dart';
|
||||
|
||||
@GenerateNiceMocks([MockSpec<FeedCubit>()])
|
||||
void main() {
|
||||
group('BlogPostWidget 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,
|
||||
);
|
||||
|
||||
final mockBlogPost = FeedBlogPostModel(
|
||||
id: 1,
|
||||
title: 'Test Post',
|
||||
description: 'Test description',
|
||||
image: '/test.jpg',
|
||||
author: mockAuthor,
|
||||
videoUrl: '',
|
||||
createdAt: DateTime.now(),
|
||||
updatedAt: DateTime.now(),
|
||||
state: 'active',
|
||||
totalLikes: 10,
|
||||
totalViews: 100,
|
||||
totalComments: 5,
|
||||
wasLikedByMe: false,
|
||||
);
|
||||
|
||||
Widget wrap(Widget child) {
|
||||
return MaterialApp.router(
|
||||
theme: ThemeHelper().themeData(),
|
||||
routerConfig: GoRouter(
|
||||
initialLocation: '/',
|
||||
routes: [
|
||||
GoRoute(path: '/', builder: (context, state) => child),
|
||||
GoRoute(
|
||||
path: '/blog-post-screen',
|
||||
name: 'blogPostScreen',
|
||||
builder: (context, state) => const Scaffold(body: Text('Blog Post')),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
testWidgets('renders blog post widget', (tester) async {
|
||||
mockNetworkImagesFor(() async {
|
||||
final cubit = MockFeedCubit();
|
||||
final state = FeedState.loaded(feedBlogPostList: [mockBlogPost], isLoading: false);
|
||||
|
||||
when(cubit.state).thenReturn(state);
|
||||
when(cubit.stream).thenAnswer((_) => Stream.value(state));
|
||||
when(cubit.close()).thenAnswer((_) async => Future<void>.value());
|
||||
|
||||
await tester.pumpWidget(BlocProvider<FeedCubit>.value(value: cubit, child: wrap(const BlogPostWidget(index: 0))));
|
||||
await tester.pump();
|
||||
await tester.pump(const Duration(milliseconds: 100));
|
||||
|
||||
expect(find.byType(BlogPostWidget), findsOneWidget);
|
||||
});
|
||||
}, skip: true);
|
||||
});
|
||||
}
|
||||
57
test/features/feed/presentation/widgets/blog_posts_test.dart
Normal file
57
test/features/feed/presentation/widgets/blog_posts_test.dart
Normal file
@@ -0,0 +1,57 @@
|
||||
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/presentation/bloc/feed_cubit/feed_cubit.dart';
|
||||
import 'package:eatvio_app/features/feed/presentation/bloc/feed_cubit/feed_state.dart';
|
||||
import 'package:eatvio_app/features/feed/presentation/widgets/blog_posts.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:mockito/annotations.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
|
||||
import 'blog_posts_test.mocks.dart';
|
||||
|
||||
@GenerateNiceMocks([MockSpec<FeedCubit>()])
|
||||
void main() {
|
||||
group('BlogPosts 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'));
|
||||
});
|
||||
|
||||
Widget wrap(Widget child) {
|
||||
return MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
home: Scaffold(body: child),
|
||||
);
|
||||
}
|
||||
|
||||
testWidgets('renders blog posts widget', (tester) async {
|
||||
final cubit = MockFeedCubit();
|
||||
const state = FeedState.loading();
|
||||
|
||||
when(cubit.state).thenReturn(state);
|
||||
when(cubit.stream).thenAnswer((_) => Stream.value(state));
|
||||
when(cubit.close()).thenAnswer((_) async => Future<void>.value());
|
||||
when(cubit.loadFeedBlogPostList()).thenAnswer((_) async => Future<void>.value());
|
||||
|
||||
await tester.pumpWidget(
|
||||
BlocProvider<FeedCubit>.value(
|
||||
value: cubit,
|
||||
child: wrap(BlogPosts(handleVisibility: ({required visibleFraction, required id, required type}) {})),
|
||||
),
|
||||
);
|
||||
await tester.pump();
|
||||
await tester.pump(const Duration(milliseconds: 100));
|
||||
|
||||
expect(find.byType(BlogPosts), findsOneWidget);
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -1,87 +1,51 @@
|
||||
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/presentation/widgets/chip_group.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
group('ChipGroup', () {
|
||||
testWidgets('displays chip group widget', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
home: Scaffold(
|
||||
body: ChipGroup(
|
||||
selectedChipIndex: 0,
|
||||
chipsLabelList: const ['All', 'Recipes', 'Diets'],
|
||||
setSelectedChipIndex: (index) {},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(find.byType(ChipGroup), findsOneWidget);
|
||||
group('ChipGroup smoke', () {
|
||||
setUpAll(() async {
|
||||
dotenv.loadFromString(envString: 'DEV_BASE_URL=http://localhost\nBASE_URL=http://localhost');
|
||||
});
|
||||
|
||||
testWidgets('displays all chips from list', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
home: Scaffold(
|
||||
body: ChipGroup(
|
||||
selectedChipIndex: 0,
|
||||
chipsLabelList: const ['All', 'Recipes', 'Diets', 'Plans'],
|
||||
setSelectedChipIndex: (index) {},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(find.byType(ChipGroup), findsOneWidget);
|
||||
expect(find.text('All'), findsOneWidget);
|
||||
expect(find.text('Recipes'), findsOneWidget);
|
||||
expect(find.text('Diets'), findsOneWidget);
|
||||
expect(find.text('Plans'), findsOneWidget);
|
||||
setUp(() async {
|
||||
await sl.reset();
|
||||
sl.registerLazySingleton<AppConfig>(() => AppConfig(buildType: AppBuildType.tests)..setBaseUrl('http://localhost'));
|
||||
});
|
||||
|
||||
testWidgets('calls setSelectedChipIndex when chip is tapped', (tester) async {
|
||||
int? selectedIndex;
|
||||
Widget wrap(Widget child) {
|
||||
return MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
home: Scaffold(body: child),
|
||||
);
|
||||
}
|
||||
|
||||
testWidgets('renders chip group', (tester) async {
|
||||
int selectedIndex = 0;
|
||||
final chipsList = ['Все', 'Рецепты', 'Диеты'];
|
||||
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
home: Scaffold(
|
||||
body: ChipGroup(
|
||||
selectedChipIndex: 0,
|
||||
chipsLabelList: const ['All', 'Recipes', 'Diets'],
|
||||
setSelectedChipIndex: (index) {
|
||||
selectedIndex = index;
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
await tester.tap(find.text('Recipes'));
|
||||
await tester.pump();
|
||||
|
||||
expect(selectedIndex, 1);
|
||||
});
|
||||
|
||||
testWidgets('displays empty chip group when list is empty', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
home: Scaffold(
|
||||
body: ChipGroup(
|
||||
selectedChipIndex: 0,
|
||||
chipsLabelList: const [],
|
||||
setSelectedChipIndex: (index) {},
|
||||
),
|
||||
wrap(
|
||||
ChipGroup(
|
||||
selectedChipIndex: selectedIndex,
|
||||
chipsLabelList: chipsList,
|
||||
setSelectedChipIndex: (index) {
|
||||
selectedIndex = index;
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byType(ChipGroup), findsOneWidget);
|
||||
expect(find.text('Все'), findsOneWidget);
|
||||
expect(find.text('Рецепты'), findsOneWidget);
|
||||
expect(find.text('Диеты'), findsOneWidget);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -1,155 +1,59 @@
|
||||
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/presentation/widgets/choice_chip_widget.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
group('ChoiceChipWidget', () {
|
||||
testWidgets('displays chip with label', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
home: Scaffold(
|
||||
body: ChoiceChipWidget(
|
||||
chipsLabelList: const ['Option 1', 'Option 2'],
|
||||
index: 0,
|
||||
selectedChipIndex: 0,
|
||||
onSelected: (selected) {},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(find.byType(ChoiceChipWidget), findsOneWidget);
|
||||
expect(find.text('Option 1'), findsOneWidget);
|
||||
group('ChoiceChipWidget smoke', () {
|
||||
setUpAll(() async {
|
||||
dotenv.loadFromString(envString: 'DEV_BASE_URL=http://localhost\nBASE_URL=http://localhost');
|
||||
});
|
||||
|
||||
testWidgets('shows selected state when index matches selectedChipIndex', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
home: Scaffold(
|
||||
body: ChoiceChipWidget(
|
||||
chipsLabelList: const ['Option 1', 'Option 2'],
|
||||
index: 0,
|
||||
selectedChipIndex: 0,
|
||||
onSelected: (selected) {},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(find.byType(ChoiceChipWidget), findsOneWidget);
|
||||
final chip = tester.widget<ChoiceChip>(find.byType(ChoiceChip));
|
||||
expect(chip.selected, isTrue);
|
||||
setUp(() async {
|
||||
await sl.reset();
|
||||
sl.registerLazySingleton<AppConfig>(() => AppConfig(buildType: AppBuildType.tests)..setBaseUrl('http://localhost'));
|
||||
});
|
||||
|
||||
testWidgets('shows unselected state when index does not match', (tester) async {
|
||||
Widget wrap(Widget child) {
|
||||
return MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
home: Scaffold(body: child),
|
||||
);
|
||||
}
|
||||
|
||||
testWidgets('renders choice chip widget', (tester) async {
|
||||
final chipsList = ['Все', 'Рецепты', 'Диеты'];
|
||||
|
||||
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
home: Scaffold(
|
||||
body: ChoiceChipWidget(
|
||||
chipsLabelList: const ['Option 1', 'Option 2'],
|
||||
index: 1,
|
||||
selectedChipIndex: 0,
|
||||
onSelected: (selected) {},
|
||||
),
|
||||
wrap(
|
||||
ChoiceChipWidget(
|
||||
index: 0,
|
||||
selectedChipIndex: 0,
|
||||
chipsLabelList: chipsList,
|
||||
onSelected: (value) {
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byType(ChoiceChipWidget), findsOneWidget);
|
||||
final chip = tester.widget<ChoiceChip>(find.byType(ChoiceChip));
|
||||
expect(chip.selected, isFalse);
|
||||
expect(find.text('Все'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('applies custom padding', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
home: Scaffold(
|
||||
body: ChoiceChipWidget(
|
||||
chipsLabelList: const ['Option 1'],
|
||||
index: 0,
|
||||
selectedChipIndex: 0,
|
||||
padding: const EdgeInsets.all(16),
|
||||
onSelected: (selected) {},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
testWidgets('renders choice chip widget not selected', (tester) async {
|
||||
final chipsList = ['Все', 'Рецепты', 'Диеты'];
|
||||
|
||||
await tester.pumpWidget(wrap(ChoiceChipWidget(index: 1, selectedChipIndex: 0, chipsLabelList: chipsList, onSelected: (value) {})));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byType(ChoiceChipWidget), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('applies custom colors', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
home: Scaffold(
|
||||
body: ChoiceChipWidget(
|
||||
chipsLabelList: const ['Option 1'],
|
||||
index: 0,
|
||||
selectedChipIndex: 0,
|
||||
activeColor: Colors.blue,
|
||||
inactiveColor: Colors.grey,
|
||||
onSelected: (selected) {},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(find.byType(ChoiceChipWidget), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('calls onSelected when tapped', (tester) async {
|
||||
bool wasCalled = false;
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
home: Scaffold(
|
||||
body: ChoiceChipWidget(
|
||||
chipsLabelList: const ['Option 1'],
|
||||
index: 0,
|
||||
selectedChipIndex: 0,
|
||||
onSelected: (selected) {
|
||||
wasCalled = true;
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
await tester.tap(find.byType(ChoiceChip));
|
||||
await tester.pump();
|
||||
|
||||
expect(wasCalled, isTrue);
|
||||
expect(find.text('Рецепты'), findsOneWidget);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
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/feed_consultant_model.dart';
|
||||
import 'package:eatvio_app/features/feed/presentation/bloc/consultants_cubit/consultants_cubit.dart';
|
||||
import 'package:eatvio_app/features/feed/presentation/bloc/consultants_cubit/consultants_state.dart';
|
||||
import 'package:eatvio_app/features/feed/presentation/widgets/consultants.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:mockito/annotations.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
import 'package:network_image_mock/network_image_mock.dart';
|
||||
|
||||
import 'consultants_test.mocks.dart';
|
||||
|
||||
@GenerateNiceMocks([MockSpec<ConsultantsCubit>()])
|
||||
void main() {
|
||||
group('Consultants 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, ConsultantsCubit cubit) {
|
||||
return MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
home: Scaffold(
|
||||
body: BlocProvider<ConsultantsCubit>.value(value: cubit, child: child),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
testWidgets('renders consultants widget - loading state', (tester) async {
|
||||
final cubit = MockConsultantsCubit();
|
||||
const state = ConsultantsState.loading();
|
||||
|
||||
when(cubit.state).thenReturn(state);
|
||||
when(cubit.stream).thenAnswer((_) => Stream.value(state));
|
||||
when(cubit.close()).thenAnswer((_) async => Future<void>.value());
|
||||
when(cubit.getConsultants()).thenAnswer((_) async => Future<void>.value());
|
||||
|
||||
await tester.pumpWidget(wrap(const Consultants(), cubit));
|
||||
await tester.pump();
|
||||
|
||||
expect(find.byType(Consultants), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('renders consultants widget - loaded state', (tester) async {
|
||||
final cubit = MockConsultantsCubit();
|
||||
const consultant = FeedConsultantModel(
|
||||
slug: 'test-consultant',
|
||||
name: 'Test Consultant',
|
||||
description: 'Test description',
|
||||
totalScores: 100,
|
||||
photo: '/test.jpg',
|
||||
badges: [],
|
||||
);
|
||||
const state = ConsultantsState.loaded(consultantsList: [consultant], isLoading: false);
|
||||
|
||||
when(cubit.state).thenReturn(state);
|
||||
when(cubit.stream).thenAnswer((_) => Stream.value(state));
|
||||
when(cubit.close()).thenAnswer((_) async => Future<void>.value());
|
||||
when(cubit.getConsultants()).thenAnswer((_) async => Future<void>.value());
|
||||
|
||||
await mockNetworkImagesFor(() async {
|
||||
await tester.pumpWidget(wrap(const Consultants(), cubit));
|
||||
await tester.pump();
|
||||
});
|
||||
|
||||
expect(find.byType(Consultants), findsOneWidget);
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
import 'package:eatvio_app/core/theme/theme_helper.dart';
|
||||
import 'package:eatvio_app/features/feed/presentation/bloc/diets_cubit/diets_cubit.dart';
|
||||
import 'package:eatvio_app/features/feed/presentation/bloc/diets_cubit/diets_state.dart';
|
||||
import 'package:eatvio_app/features/feed/presentation/widgets/diet_filter_bottom_sheet.dart';
|
||||
import 'package:eatvio_app/features/my_diets/presentation/cubit/my_diets_cubit.dart';
|
||||
import 'package:eatvio_app/features/my_diets/presentation/cubit/my_diets_state.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 'diet_filter_bottom_sheet_test.mocks.dart';
|
||||
|
||||
@GenerateNiceMocks([MockSpec<DietsCubit>(), MockSpec<MyDietsCubit>()])
|
||||
void main() {
|
||||
group('DietFilterBottomSheet smoke', () {
|
||||
Widget wrap(Widget child, DietsCubit? dietsCubit, MyDietsCubit? myDietsCubit) {
|
||||
return MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
localizationsDelegates: const [
|
||||
S.delegate,
|
||||
GlobalMaterialLocalizations.delegate,
|
||||
GlobalWidgetsLocalizations.delegate,
|
||||
GlobalCupertinoLocalizations.delegate,
|
||||
],
|
||||
supportedLocales: const [Locale('ru')],
|
||||
home: Scaffold(
|
||||
body: MultiBlocProvider(
|
||||
providers: [
|
||||
if (dietsCubit != null) BlocProvider<DietsCubit>.value(value: dietsCubit),
|
||||
if (myDietsCubit != null) BlocProvider<MyDietsCubit>.value(value: myDietsCubit),
|
||||
],
|
||||
child: child,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
testWidgets('renders diet filter bottom sheet', (tester) async {
|
||||
final dietsCubit = MockDietsCubit();
|
||||
final myDietsCubit = MockMyDietsCubit();
|
||||
final dietsState = DietsState.initial();
|
||||
final myDietsState = MyDietsState();
|
||||
|
||||
when(dietsCubit.state).thenReturn(dietsState);
|
||||
when(dietsCubit.stream).thenAnswer((_) => Stream.value(dietsState));
|
||||
when(dietsCubit.close()).thenAnswer((_) async => Future<void>.value());
|
||||
|
||||
when(myDietsCubit.state).thenReturn(myDietsState);
|
||||
when(myDietsCubit.stream).thenAnswer((_) => Stream.value(myDietsState));
|
||||
when(myDietsCubit.close()).thenAnswer((_) async => Future<void>.value());
|
||||
|
||||
await tester.pumpWidget(wrap(DietFilterBottomSheet(dietsCubit: dietsCubit, myDietsCubit: myDietsCubit), dietsCubit, myDietsCubit));
|
||||
await tester.pump();
|
||||
await tester.pump(const Duration(milliseconds: 100));
|
||||
|
||||
expect(find.byType(DietFilterBottomSheet), findsOneWidget);
|
||||
});
|
||||
});
|
||||
}
|
||||
58
test/features/feed/presentation/widgets/diets_test.dart
Normal file
58
test/features/feed/presentation/widgets/diets_test.dart
Normal file
@@ -0,0 +1,58 @@
|
||||
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/presentation/bloc/diets_cubit/diets_cubit.dart';
|
||||
import 'package:eatvio_app/features/feed/presentation/bloc/diets_cubit/diets_state.dart';
|
||||
import 'package:eatvio_app/features/feed/presentation/widgets/diets.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:mockito/annotations.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
|
||||
import 'diets_test.mocks.dart';
|
||||
|
||||
@GenerateNiceMocks([MockSpec<DietsCubit>()])
|
||||
void main() {
|
||||
group('Diets 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'));
|
||||
});
|
||||
|
||||
Widget wrap(Widget child) {
|
||||
return MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
home: Scaffold(body: child),
|
||||
);
|
||||
}
|
||||
|
||||
testWidgets('renders diets widget', (tester) async {
|
||||
final cubit = MockDietsCubit();
|
||||
final state = DietsState.initial();
|
||||
|
||||
when(cubit.state).thenReturn(state);
|
||||
when(cubit.stream).thenAnswer((_) => Stream.value(state));
|
||||
when(cubit.close()).thenAnswer((_) async => Future<void>.value());
|
||||
when(cubit.loadDiets()).thenAnswer((_) async => Future<void>.value());
|
||||
when(cubit.loadNextPage()).thenAnswer((_) async => Future<void>.value());
|
||||
|
||||
await tester.pumpWidget(
|
||||
BlocProvider<DietsCubit>.value(
|
||||
value: cubit,
|
||||
child: wrap(Diets(handleVisibility: ({required visibleFraction, required id, required type}) {})),
|
||||
),
|
||||
);
|
||||
await tester.pump();
|
||||
await tester.pump(const Duration(milliseconds: 100));
|
||||
|
||||
expect(find.byType(Diets), findsOneWidget);
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -1,13 +1,7 @@
|
||||
import 'package:eatvio_app/core/theme/theme_helper.dart';
|
||||
import 'package:eatvio_app/features/feed/presentation/bloc/diets_cubit/diets_cubit.dart';
|
||||
import 'package:eatvio_app/features/feed/presentation/bloc/diets_cubit/diets_state.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/duration_choice_filter_widget.dart';
|
||||
import 'package:eatvio_app/features/my_diets/presentation/cubit/my_diets_cubit.dart';
|
||||
import 'package:eatvio_app/features/my_diets/presentation/cubit/my_diets_state.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/generated/l10n.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
@@ -18,27 +12,10 @@ import 'package:mockito/mockito.dart';
|
||||
|
||||
import 'duration_choice_filter_widget_test.mocks.dart';
|
||||
|
||||
@GenerateNiceMocks([
|
||||
MockSpec<PlansCubit>(),
|
||||
MockSpec<DietsCubit>(),
|
||||
MockSpec<MyPlansCubit>(),
|
||||
MockSpec<MyDietsCubit>(),
|
||||
])
|
||||
@GenerateNiceMocks([MockSpec<DietsCubit>()])
|
||||
void main() {
|
||||
group('DurationChoiceFilterWidget', () {
|
||||
late MockPlansCubit mockPlansCubit;
|
||||
late MockDietsCubit mockDietsCubit;
|
||||
late MockMyPlansCubit mockMyPlansCubit;
|
||||
late MockMyDietsCubit mockMyDietsCubit;
|
||||
|
||||
setUp(() {
|
||||
mockPlansCubit = MockPlansCubit();
|
||||
mockDietsCubit = MockDietsCubit();
|
||||
mockMyPlansCubit = MockMyPlansCubit();
|
||||
mockMyDietsCubit = MockMyDietsCubit();
|
||||
});
|
||||
|
||||
Widget createTestWidget(Widget child) {
|
||||
group('DurationChoiceFilterWidget smoke', () {
|
||||
Widget wrap(Widget child) {
|
||||
return MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
localizationsDelegates: const [
|
||||
@@ -47,79 +24,30 @@ void main() {
|
||||
GlobalWidgetsLocalizations.delegate,
|
||||
GlobalCupertinoLocalizations.delegate,
|
||||
],
|
||||
supportedLocales: const [Locale('ru'), Locale('en')],
|
||||
locale: const Locale('ru'),
|
||||
supportedLocales: const [Locale('ru')],
|
||||
home: Scaffold(body: child),
|
||||
);
|
||||
}
|
||||
|
||||
testWidgets('displays duration filter for DietsCubit', (tester) async {
|
||||
when(mockDietsCubit.state).thenReturn(DietsState.initial());
|
||||
when(mockDietsCubit.stream).thenAnswer((_) => Stream.value(DietsState.initial()));
|
||||
testWidgets('renders duration choice filter widget', (tester) async {
|
||||
final cubit = MockDietsCubit();
|
||||
final state = DietsState.initial();
|
||||
|
||||
when(cubit.state).thenReturn(state);
|
||||
when(cubit.stream).thenAnswer((_) => Stream.value(state));
|
||||
when(cubit.close()).thenAnswer((_) async => Future<void>.value());
|
||||
when(cubit.changeDurationFilter(any)).thenReturn(null);
|
||||
|
||||
await tester.pumpWidget(
|
||||
createTestWidget(
|
||||
BlocProvider<DietsCubit>.value(
|
||||
value: mockDietsCubit,
|
||||
child: DurationChoiceFilterWidget(dietCubit: mockDietsCubit),
|
||||
),
|
||||
BlocProvider<DietsCubit>.value(
|
||||
value: cubit,
|
||||
child: wrap(DurationChoiceFilterWidget(dietCubit: cubit)),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byType(DurationChoiceFilterWidget), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('displays duration filter for PlansCubit', (tester) async {
|
||||
when(mockPlansCubit.state).thenReturn(PlansState.initial());
|
||||
when(mockPlansCubit.stream).thenAnswer((_) => Stream.value(PlansState.initial()));
|
||||
|
||||
await tester.pumpWidget(
|
||||
createTestWidget(
|
||||
BlocProvider<PlansCubit>.value(
|
||||
value: mockPlansCubit,
|
||||
child: DurationChoiceFilterWidget(plansCubit: mockPlansCubit),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byType(DurationChoiceFilterWidget), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('displays duration filter for MyPlansCubit', (tester) async {
|
||||
when(mockMyPlansCubit.state).thenReturn(MyPlansState());
|
||||
when(mockMyPlansCubit.stream).thenAnswer((_) => Stream.value(MyPlansState()));
|
||||
|
||||
await tester.pumpWidget(
|
||||
createTestWidget(
|
||||
BlocProvider<MyPlansCubit>.value(
|
||||
value: mockMyPlansCubit,
|
||||
child: DurationChoiceFilterWidget(myPlansCubit: mockMyPlansCubit),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byType(DurationChoiceFilterWidget), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('displays duration filter for MyDietsCubit', (tester) async {
|
||||
when(mockMyDietsCubit.state).thenReturn(MyDietsState());
|
||||
when(mockMyDietsCubit.stream).thenAnswer((_) => Stream.value(MyDietsState()));
|
||||
|
||||
await tester.pumpWidget(
|
||||
createTestWidget(
|
||||
BlocProvider<MyDietsCubit>.value(
|
||||
value: mockMyDietsCubit,
|
||||
child: DurationChoiceFilterWidget(myDietsCubit: mockMyDietsCubit),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.pump();
|
||||
await tester.pump(const Duration(milliseconds: 100));
|
||||
|
||||
expect(find.byType(DurationChoiceFilterWidget), findsOneWidget);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -1,67 +1,35 @@
|
||||
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/presentation/widgets/filter_badge.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
group('FilterBadge', () {
|
||||
testWidgets('displays filter badge widget', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
home: const Scaffold(
|
||||
body: FilterBadge(
|
||||
filterBottomSheet: Text('Filter Bottom Sheet'),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(find.byType(FilterBadge), findsOneWidget);
|
||||
expect(find.byType(GestureDetector), findsOneWidget);
|
||||
group('FilterBadge smoke', () {
|
||||
setUpAll(() async {
|
||||
dotenv.loadFromString(envString: 'DEV_BASE_URL=http://localhost\nBASE_URL=http://localhost');
|
||||
});
|
||||
|
||||
testWidgets('opens bottom sheet when tapped', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
home: const Scaffold(
|
||||
body: FilterBadge(
|
||||
filterBottomSheet: Text('Filter Bottom Sheet'),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
setUp(() async {
|
||||
await sl.reset();
|
||||
sl.registerLazySingleton<AppConfig>(() => AppConfig(buildType: AppBuildType.tests)..setBaseUrl('http://localhost'));
|
||||
});
|
||||
|
||||
await tester.tap(find.byType(FilterBadge));
|
||||
Widget wrap(Widget child) {
|
||||
return MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
home: Scaffold(body: child),
|
||||
);
|
||||
}
|
||||
|
||||
testWidgets('renders filter badge', (tester) async {
|
||||
await tester.pumpWidget(wrap(const FilterBadge(filterBottomSheet: Scaffold(body: Text('Filter Bottom Sheet')))));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('Filter Bottom Sheet'), findsOneWidget);
|
||||
expect(find.byType(FilterBadge), findsOneWidget);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
104
test/features/feed/presentation/widgets/plan_widget_test.dart
Normal file
104
test/features/feed/presentation/widgets/plan_widget_test.dart
Normal file
@@ -0,0 +1,104 @@
|
||||
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);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
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/plans_filter_bottom_sheet.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/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 'plans_filter_bottom_sheet_test.mocks.dart';
|
||||
|
||||
@GenerateNiceMocks([MockSpec<PlansCubit>(), MockSpec<MyPlansCubit>()])
|
||||
void main() {
|
||||
group('PlansFilterBottomSheet smoke', () {
|
||||
Widget wrap(Widget child, PlansCubit? plansCubit, MyPlansCubit? myPlansCubit) {
|
||||
return MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
localizationsDelegates: const [
|
||||
S.delegate,
|
||||
GlobalMaterialLocalizations.delegate,
|
||||
GlobalWidgetsLocalizations.delegate,
|
||||
GlobalCupertinoLocalizations.delegate,
|
||||
],
|
||||
supportedLocales: const [Locale('ru')],
|
||||
home: Scaffold(
|
||||
body: MultiBlocProvider(
|
||||
providers: [
|
||||
if (plansCubit != null) BlocProvider<PlansCubit>.value(value: plansCubit),
|
||||
if (myPlansCubit != null) BlocProvider<MyPlansCubit>.value(value: myPlansCubit),
|
||||
],
|
||||
child: child,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
testWidgets('renders plans filter bottom sheet', (tester) async {
|
||||
final plansCubit = MockPlansCubit();
|
||||
final myPlansCubit = MockMyPlansCubit();
|
||||
final plansState = PlansState.initial();
|
||||
final myPlansState = MyPlansState();
|
||||
|
||||
when(plansCubit.state).thenReturn(plansState);
|
||||
when(plansCubit.stream).thenAnswer((_) => Stream.value(plansState));
|
||||
when(plansCubit.close()).thenAnswer((_) async => Future<void>.value());
|
||||
|
||||
when(myPlansCubit.state).thenReturn(myPlansState);
|
||||
when(myPlansCubit.stream).thenAnswer((_) => Stream.value(myPlansState));
|
||||
when(myPlansCubit.close()).thenAnswer((_) async => Future<void>.value());
|
||||
|
||||
await tester.pumpWidget(wrap(PlansFilterBottomSheet(plansCubit: plansCubit, myPlansCubit: myPlansCubit), plansCubit, myPlansCubit));
|
||||
await tester.pump();
|
||||
await tester.pump(const Duration(milliseconds: 100));
|
||||
|
||||
expect(find.byType(PlansFilterBottomSheet), findsOneWidget);
|
||||
});
|
||||
});
|
||||
}
|
||||
58
test/features/feed/presentation/widgets/plans_test.dart
Normal file
58
test/features/feed/presentation/widgets/plans_test.dart
Normal file
@@ -0,0 +1,58 @@
|
||||
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/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/plans.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:mockito/annotations.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
|
||||
import 'plans_test.mocks.dart';
|
||||
|
||||
@GenerateNiceMocks([MockSpec<PlansCubit>()])
|
||||
void main() {
|
||||
group('Plans 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'));
|
||||
});
|
||||
|
||||
Widget wrap(Widget child) {
|
||||
return MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
home: Scaffold(body: child),
|
||||
);
|
||||
}
|
||||
|
||||
testWidgets('renders plans widget', (tester) async {
|
||||
final cubit = MockPlansCubit();
|
||||
final state = PlansState.initial();
|
||||
|
||||
when(cubit.state).thenReturn(state);
|
||||
when(cubit.stream).thenAnswer((_) => Stream.value(state));
|
||||
when(cubit.close()).thenAnswer((_) async => Future<void>.value());
|
||||
when(cubit.loadPlans()).thenAnswer((_) async => Future<void>.value());
|
||||
when(cubit.loadNextPage()).thenAnswer((_) async => Future<void>.value());
|
||||
|
||||
await tester.pumpWidget(
|
||||
BlocProvider<PlansCubit>.value(
|
||||
value: cubit,
|
||||
child: wrap(Plans(handleVisibility: ({required visibleFraction, required id, required type}) {})),
|
||||
),
|
||||
);
|
||||
await tester.pump();
|
||||
await tester.pump(const Duration(milliseconds: 100));
|
||||
|
||||
expect(find.byType(Plans), findsOneWidget);
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -2,10 +2,8 @@ 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';
|
||||
@@ -14,42 +12,31 @@ import 'price_choice_filter_widget_test.mocks.dart';
|
||||
|
||||
@GenerateNiceMocks([MockSpec<PlansCubit>()])
|
||||
void main() {
|
||||
group('PriceChoiceFilterWidget', () {
|
||||
Widget wrap(PlansCubit cubit, Widget child) {
|
||||
group('PriceChoiceFilterWidget smoke', () {
|
||||
Widget wrap(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),
|
||||
),
|
||||
home: Scaffold(body: child),
|
||||
);
|
||||
}
|
||||
|
||||
testWidgets('renders with PlansCubit', (tester) async {
|
||||
testWidgets('renders price choice filter widget', (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,
|
||||
);
|
||||
final state = PlansState.initial();
|
||||
|
||||
when(cubit.state).thenReturn(state);
|
||||
when(cubit.stream).thenAnswer((_) => const Stream<PlansState>.empty());
|
||||
when(cubit.stream).thenAnswer((_) => Stream.value(state));
|
||||
when(cubit.close()).thenAnswer((_) async => Future<void>.value());
|
||||
when(cubit.changePriceFilter(any, any, disableDebounce: anyNamed('disableDebounce'))).thenReturn(null);
|
||||
when(cubit.changePriceFilter(any, any)).thenReturn(null);
|
||||
|
||||
await tester.pumpWidget(wrap(cubit, PriceChoiceFilterWidget(plansCubit: cubit)));
|
||||
await tester.pumpWidget(
|
||||
BlocProvider<PlansCubit>.value(
|
||||
value: cubit,
|
||||
child: wrap(PriceChoiceFilterWidget(plansCubit: cubit)),
|
||||
),
|
||||
);
|
||||
await tester.pump();
|
||||
await tester.pump(const Duration(milliseconds: 100));
|
||||
|
||||
expect(find.byType(PriceChoiceFilterWidget), findsOneWidget);
|
||||
});
|
||||
|
||||
58
test/features/feed/presentation/widgets/recipes_test.dart
Normal file
58
test/features/feed/presentation/widgets/recipes_test.dart
Normal file
@@ -0,0 +1,58 @@
|
||||
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/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.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:mockito/annotations.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
|
||||
import 'recipes_test.mocks.dart';
|
||||
|
||||
@GenerateNiceMocks([MockSpec<RecipesCubit>()])
|
||||
void main() {
|
||||
group('Recipes 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'));
|
||||
});
|
||||
|
||||
Widget wrap(Widget child) {
|
||||
return MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
home: Scaffold(body: child),
|
||||
);
|
||||
}
|
||||
|
||||
testWidgets('renders recipes widget', (tester) async {
|
||||
final cubit = MockRecipesCubit();
|
||||
final state = RecipesState.initial();
|
||||
|
||||
when(cubit.state).thenReturn(state);
|
||||
when(cubit.stream).thenAnswer((_) => Stream.value(state));
|
||||
when(cubit.close()).thenAnswer((_) async => Future<void>.value());
|
||||
when(cubit.loadRecipesList()).thenAnswer((_) async => Future<void>.value());
|
||||
when(cubit.loadNextPage()).thenAnswer((_) async => Future<void>.value());
|
||||
|
||||
await tester.pumpWidget(
|
||||
BlocProvider<RecipesCubit>.value(
|
||||
value: cubit,
|
||||
child: wrap(Recipes(handleVisibility: ({required visibleFraction, required id, required type}) {})),
|
||||
),
|
||||
);
|
||||
await tester.pump();
|
||||
await tester.pump(const Duration(milliseconds: 100));
|
||||
|
||||
expect(find.byType(Recipes), findsOneWidget);
|
||||
});
|
||||
});
|
||||
}
|
||||
105
test/features/feed/presentation/widgets/recipes_widget_test.dart
Normal file
105
test/features/feed/presentation/widgets/recipes_widget_test.dart
Normal file
@@ -0,0 +1,105 @@
|
||||
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<RecipesCubit>()])
|
||||
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>(() => 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<void>.value());
|
||||
|
||||
await tester.pumpWidget(
|
||||
BlocProvider<RecipesCubit>.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);
|
||||
});
|
||||
}
|
||||
@@ -1,12 +1,11 @@
|
||||
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/presentation/widgets/subscribe_button_widget.dart';
|
||||
import 'package:eatvio_app/features/profile/presentation/bloc/sub_cubit/sub_cubit.dart';
|
||||
import 'package:eatvio_app/features/profile/presentation/bloc/sub_cubit/sub_state.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:mockito/annotations.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
@@ -15,52 +14,32 @@ import 'subscribe_button_widget_test.mocks.dart';
|
||||
|
||||
@GenerateNiceMocks([MockSpec<SubCubit>()])
|
||||
void main() {
|
||||
TestWidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
group('SubscribeButtonWidget', () {
|
||||
late MockSubCubit mockSubCubit;
|
||||
group('SubscribeButtonWidget smoke', () {
|
||||
setUpAll(() async {
|
||||
dotenv.loadFromString(envString: 'DEV_BASE_URL=http://localhost\nBASE_URL=http://localhost');
|
||||
});
|
||||
|
||||
setUp(() async {
|
||||
await sl.reset();
|
||||
AppConfigRegistration.registerAppConfig(buildType: AppBuildType.tests);
|
||||
mockSubCubit = MockSubCubit();
|
||||
sl.registerLazySingleton<SubCubit>(() => mockSubCubit);
|
||||
sl.registerLazySingleton<AppConfig>(() => AppConfig(buildType: AppBuildType.tests)..setBaseUrl('http://localhost'));
|
||||
final subCubit = MockSubCubit();
|
||||
when(subCubit.subscribe(any)).thenAnswer((_) async => Future<void>.value());
|
||||
sl.registerLazySingleton<SubCubit>(() => subCubit);
|
||||
});
|
||||
|
||||
Widget createTestWidget(String slug) {
|
||||
Widget wrap(Widget child) {
|
||||
return MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
home: BlocProvider<SubCubit>.value(
|
||||
value: mockSubCubit,
|
||||
child: Scaffold(
|
||||
body: SubscribeButtonWidget(slug: slug),
|
||||
),
|
||||
),
|
||||
home: Scaffold(body: child),
|
||||
);
|
||||
}
|
||||
|
||||
testWidgets('displays subscribe button', (tester) async {
|
||||
when(mockSubCubit.stream).thenAnswer((_) => Stream.value(const SubState()));
|
||||
|
||||
await tester.pumpWidget(createTestWidget('test-slug'));
|
||||
testWidgets('renders subscribe button widget', (tester) async {
|
||||
await tester.pumpWidget(wrap(const SubscribeButtonWidget(slug: 'test-slug')));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byType(SubscribeButtonWidget), findsOneWidget);
|
||||
expect(find.text('Подписаться'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('calls subscribe when tapped', (tester) async {
|
||||
when(mockSubCubit.stream).thenAnswer((_) => Stream.value(const SubState()));
|
||||
when(mockSubCubit.subscribe(any)).thenAnswer((_) async {});
|
||||
|
||||
await tester.pumpWidget(createTestWidget('test-slug'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
await tester.tap(find.text('Подписаться'));
|
||||
await tester.pump();
|
||||
|
||||
verify(mockSubCubit.subscribe('test-slug')).called(1);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -1,13 +1,7 @@
|
||||
import 'package:eatvio_app/core/theme/theme_helper.dart';
|
||||
import 'package:eatvio_app/features/feed/presentation/bloc/diets_cubit/diets_cubit.dart';
|
||||
import 'package:eatvio_app/features/feed/presentation/bloc/diets_cubit/diets_state.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/type_choice_filter_widget.dart';
|
||||
import 'package:eatvio_app/features/my_diets/presentation/cubit/my_diets_cubit.dart';
|
||||
import 'package:eatvio_app/features/my_diets/presentation/cubit/my_diets_state.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/generated/l10n.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
@@ -18,27 +12,10 @@ import 'package:mockito/mockito.dart';
|
||||
|
||||
import 'type_choice_filter_widget_test.mocks.dart';
|
||||
|
||||
@GenerateNiceMocks([
|
||||
MockSpec<PlansCubit>(),
|
||||
MockSpec<DietsCubit>(),
|
||||
MockSpec<MyPlansCubit>(),
|
||||
MockSpec<MyDietsCubit>(),
|
||||
])
|
||||
@GenerateNiceMocks([MockSpec<DietsCubit>()])
|
||||
void main() {
|
||||
group('TypeChoiceFilterWidget', () {
|
||||
late MockPlansCubit mockPlansCubit;
|
||||
late MockDietsCubit mockDietsCubit;
|
||||
late MockMyPlansCubit mockMyPlansCubit;
|
||||
late MockMyDietsCubit mockMyDietsCubit;
|
||||
|
||||
setUp(() {
|
||||
mockPlansCubit = MockPlansCubit();
|
||||
mockDietsCubit = MockDietsCubit();
|
||||
mockMyPlansCubit = MockMyPlansCubit();
|
||||
mockMyDietsCubit = MockMyDietsCubit();
|
||||
});
|
||||
|
||||
Widget createTestWidget(Widget child) {
|
||||
group('TypeChoiceFilterWidget smoke', () {
|
||||
Widget wrap(Widget child) {
|
||||
return MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
localizationsDelegates: const [
|
||||
@@ -47,79 +24,30 @@ void main() {
|
||||
GlobalWidgetsLocalizations.delegate,
|
||||
GlobalCupertinoLocalizations.delegate,
|
||||
],
|
||||
supportedLocales: const [Locale('ru'), Locale('en')],
|
||||
locale: const Locale('ru'),
|
||||
supportedLocales: const [Locale('ru')],
|
||||
home: Scaffold(body: child),
|
||||
);
|
||||
}
|
||||
|
||||
testWidgets('displays type filter for PlansCubit', (tester) async {
|
||||
when(mockPlansCubit.state).thenReturn(PlansState.initial());
|
||||
when(mockPlansCubit.stream).thenAnswer((_) => Stream.value(PlansState.initial()));
|
||||
testWidgets('renders type choice filter widget', (tester) async {
|
||||
final cubit = MockDietsCubit();
|
||||
final state = DietsState.initial();
|
||||
|
||||
when(cubit.state).thenReturn(state);
|
||||
when(cubit.stream).thenAnswer((_) => Stream.value(state));
|
||||
when(cubit.close()).thenAnswer((_) async => Future<void>.value());
|
||||
when(cubit.changeTypeFilter(any)).thenReturn(null);
|
||||
|
||||
await tester.pumpWidget(
|
||||
createTestWidget(
|
||||
BlocProvider<PlansCubit>.value(
|
||||
value: mockPlansCubit,
|
||||
child: TypeChoiceFilterWidget(plansCubit: mockPlansCubit),
|
||||
),
|
||||
BlocProvider<DietsCubit>.value(
|
||||
value: cubit,
|
||||
child: wrap(TypeChoiceFilterWidget(dietsCubit: cubit)),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byType(TypeChoiceFilterWidget), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('displays type filter for DietsCubit', (tester) async {
|
||||
when(mockDietsCubit.state).thenReturn(DietsState.initial());
|
||||
when(mockDietsCubit.stream).thenAnswer((_) => Stream.value(DietsState.initial()));
|
||||
|
||||
await tester.pumpWidget(
|
||||
createTestWidget(
|
||||
BlocProvider<DietsCubit>.value(
|
||||
value: mockDietsCubit,
|
||||
child: TypeChoiceFilterWidget(dietsCubit: mockDietsCubit),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byType(TypeChoiceFilterWidget), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('displays type filter for MyPlansCubit', (tester) async {
|
||||
when(mockMyPlansCubit.state).thenReturn(MyPlansState());
|
||||
when(mockMyPlansCubit.stream).thenAnswer((_) => Stream.value(MyPlansState()));
|
||||
|
||||
await tester.pumpWidget(
|
||||
createTestWidget(
|
||||
BlocProvider<MyPlansCubit>.value(
|
||||
value: mockMyPlansCubit,
|
||||
child: TypeChoiceFilterWidget(myPlansCubit: mockMyPlansCubit),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byType(TypeChoiceFilterWidget), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('displays type filter for MyDietsCubit', (tester) async {
|
||||
when(mockMyDietsCubit.state).thenReturn(MyDietsState());
|
||||
when(mockMyDietsCubit.stream).thenAnswer((_) => Stream.value(MyDietsState()));
|
||||
|
||||
await tester.pumpWidget(
|
||||
createTestWidget(
|
||||
BlocProvider<MyDietsCubit>.value(
|
||||
value: mockMyDietsCubit,
|
||||
child: TypeChoiceFilterWidget(myDietsCubit: mockMyDietsCubit),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.pump();
|
||||
await tester.pump(const Duration(milliseconds: 100));
|
||||
|
||||
expect(find.byType(TypeChoiceFilterWidget), findsOneWidget);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user