forked from eatvio/eatvio_app
59 lines
2.2 KiB
Dart
59 lines
2.2 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/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);
|
|
});
|
|
});
|
|
}
|