feat(tests): test coverage is 70.4

This commit is contained in:
misha
2026-01-23 12:40:17 +03:00
parent f6809a06b3
commit 92205c09d6
38 changed files with 1829 additions and 133 deletions

View File

@@ -0,0 +1,89 @@
import 'package:eatvio_app/core/app_config.dart';
import 'package:eatvio_app/core/app_initializer.dart';
import 'package:eatvio_app/core/enums/base_state.dart';
import 'package:eatvio_app/core/locator_service.dart';
import 'package:eatvio_app/core/theme/theme_helper.dart';
import 'package:eatvio_app/features/consultations/presentation/cubit/consultations_cubit.dart';
import 'package:eatvio_app/features/consultations/presentation/cubit/consultations_state.dart';
import 'package:eatvio_app/features/consultations/presentation/pages/consultations_screen.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 'consultations_screen_smoke_test.mocks.dart';
@GenerateNiceMocks([MockSpec<ConsultationsCubit>()])
void main() {
group('ConsultationsScreen 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, ConsultationsCubit cubit) {
return MaterialApp.router(
theme: ThemeHelper().themeData(),
routerConfig: GoRouter(
routes: [
GoRoute(
path: '/',
builder: (context, state) => Scaffold(
body: BlocProvider<ConsultationsCubit>.value(value: cubit, child: child),
),
),
],
),
);
}
testWidgets('renders consultations screen', (tester) async {
final cubit = MockConsultationsCubit();
final state = ConsultationsState(state: BaseState.initial, consultations: []);
when(cubit.state).thenReturn(state);
when(cubit.stream).thenAnswer((_) => Stream.value(state));
when(cubit.close()).thenAnswer((_) async => Future<void>.value());
await tester.pumpWidget(wrap(const ConsultationsContent(), cubit));
await tester.pump();
expect(find.byType(ConsultationsContent), findsOneWidget);
});
testWidgets('displays consultations title', (tester) async {
final cubit = MockConsultationsCubit();
final state = ConsultationsState(state: BaseState.success, consultations: []);
when(cubit.state).thenReturn(state);
when(cubit.stream).thenAnswer((_) => Stream.value(state));
when(cubit.close()).thenAnswer((_) async => Future<void>.value());
await tester.pumpWidget(wrap(const ConsultationsContent(), cubit));
await tester.pump();
expect(find.text('Консультации'), findsOneWidget);
});
testWidgets('displays archive button when loaded', (tester) async {
final cubit = MockConsultationsCubit();
final state = ConsultationsState(state: BaseState.success, consultations: []);
when(cubit.state).thenReturn(state);
when(cubit.stream).thenAnswer((_) => Stream.value(state));
when(cubit.close()).thenAnswer((_) async => Future<void>.value());
await tester.pumpWidget(wrap(const ConsultationsContent(), cubit));
await tester.pump();
expect(find.text('Архив консультаций'), findsOneWidget);
});
});
}