forked from eatvio/eatvio_app
feat(tests): increased tests coverage
This commit is contained in:
@@ -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);
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user