forked from eatvio/eatvio_app
feat(tests): test coverage is 70.4
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
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/recipe/presentation/cubit/my_recipes_cubit/my_recieps_cubit.dart';
|
||||
import 'package:eatvio_app/features/recipe/presentation/cubit/my_recipes_cubit/my_recipes_state.dart';
|
||||
import 'package:eatvio_app/features/recipe/presentation/pages/my_recipes_screen.dart';
|
||||
import 'package:flutter/material.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 'my_recipes_screen_smoke_test.mocks.dart';
|
||||
|
||||
@GenerateNiceMocks([MockSpec<MyRecipesCubit>()])
|
||||
void main() {
|
||||
group('MyRecipesScreen 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: child);
|
||||
}
|
||||
|
||||
testWidgets('renders my recipes screen', (tester) async {
|
||||
final cubit = MockMyRecipesCubit();
|
||||
const state = MyRecipesStateLoading();
|
||||
|
||||
when(cubit.state).thenReturn(state);
|
||||
when(cubit.stream).thenAnswer((_) => Stream.value(state));
|
||||
when(cubit.close()).thenAnswer((_) async => Future<void>.value());
|
||||
when(cubit.getMyRecipes()).thenAnswer((_) async => Future<void>.value());
|
||||
|
||||
// Регистрируем cubit в sl, так как MyRecipesScreen использует sl<MyRecipesCubit>()
|
||||
sl.registerFactory<MyRecipesCubit>(() => cubit);
|
||||
|
||||
await tester.pumpWidget(wrap(const MyRecipesScreen()));
|
||||
await tester.pump();
|
||||
|
||||
expect(find.byType(MyRecipesScreen), findsOneWidget);
|
||||
expect(find.text('Мои рецепты'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('renders my recipes screen with loaded state', (tester) async {
|
||||
final cubit = MockMyRecipesCubit();
|
||||
const state = MyRecipesStateLoaded(recipes: [], selectedState: 'all');
|
||||
|
||||
when(cubit.state).thenReturn(state);
|
||||
when(cubit.stream).thenAnswer((_) => Stream.value(state));
|
||||
when(cubit.close()).thenAnswer((_) async => Future<void>.value());
|
||||
when(cubit.getMyRecipes()).thenAnswer((_) async => Future<void>.value());
|
||||
|
||||
// Регистрируем cubit в sl, так как MyRecipesScreen использует sl<MyRecipesCubit>()
|
||||
sl.registerFactory<MyRecipesCubit>(() => cubit);
|
||||
|
||||
await tester.pumpWidget(wrap(const MyRecipesScreen()));
|
||||
await tester.pump();
|
||||
|
||||
expect(find.byType(MyRecipesScreen), findsOneWidget);
|
||||
expect(find.text('Мои рецепты'), findsOneWidget);
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user