feat(tests): test coverage 60%

This commit is contained in:
misha
2025-12-23 10:59:56 +03:00
parent 38118055a5
commit 5b705dfb72
67 changed files with 8391 additions and 42 deletions

View File

@@ -0,0 +1,85 @@
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/calendar/models/calendar_model.dart';
import 'package:eatvio_app/features/calendar/presentation/bloc/calendar_cubit.dart';
import 'package:eatvio_app/features/calendar/presentation/pages/calendar_screen.dart';
import 'package:eatvio_app/features/calendar/repositories/calendar_repository.dart';
import 'package:flutter/material.dart';
import 'package:flutter_dotenv/flutter_dotenv.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:intl/date_symbol_data_local.dart';
import 'package:mockito/annotations.dart';
import 'package:mockito/mockito.dart';
import 'calendar_screen_smoke_test.mocks.dart';
@GenerateNiceMocks([MockSpec<CalendarRepository>()])
void main() {
group('CalendarScreen smoke', () {
setUpAll(() async {
dotenv.loadFromString(envString: 'DEV_BASE_URL=http://localhost\nBASE_URL=http://localhost');
await initializeDateFormatting('ru', null);
});
setUp(() async {
await sl.reset();
sl.registerLazySingleton<AppConfig>(() => AppConfig(buildType: AppBuildType.tests)..setBaseUrl('http://localhost'));
});
final mockCalendarList = [
const CalendarModel(date: '2025-01-01', isCurrentDayIncludedInTheChosenDietProgression: true, diary: <String, dynamic>{'id': 1, 'state': 'finished'}),
];
Widget wrap(Widget child) {
return MaterialApp(theme: ThemeHelper().themeData(), home: child);
}
testWidgets('renders loading state', (tester) async {
final calendarRepository = MockCalendarRepository();
final cubit = CalendarCubit(calendarRepository: calendarRepository);
when(calendarRepository.getCalendar()).thenAnswer((_) async => mockCalendarList);
sl.registerLazySingleton<CalendarRepository>(() => calendarRepository);
sl.registerLazySingleton<CalendarCubit>(() => cubit);
await tester.pumpWidget(wrap(const CalendarScreen()));
await tester.pump();
await tester.pump(const Duration(milliseconds: 100));
expect(find.byType(CalendarScreen), findsOneWidget);
});
testWidgets('renders loaded state with calendar list', (tester) async {
final calendarRepository = MockCalendarRepository();
final cubit = CalendarCubit(calendarRepository: calendarRepository);
when(calendarRepository.getCalendar()).thenAnswer((_) async => mockCalendarList);
sl.registerLazySingleton<CalendarRepository>(() => calendarRepository);
sl.registerLazySingleton<CalendarCubit>(() => cubit);
await tester.pumpWidget(wrap(const CalendarScreen()));
await tester.pumpAndSettle();
expect(find.text('Календарь'), findsOneWidget);
});
testWidgets('renders error state', (tester) async {
final calendarRepository = MockCalendarRepository();
final cubit = CalendarCubit(calendarRepository: calendarRepository);
when(calendarRepository.getCalendar()).thenThrow(Exception('Error loading calendar'));
sl.registerLazySingleton<CalendarRepository>(() => calendarRepository);
sl.registerLazySingleton<CalendarCubit>(() => cubit);
await tester.pumpWidget(wrap(const CalendarScreen()));
await tester.pumpAndSettle();
expect(find.textContaining('Error loading calendar'), findsOneWidget);
});
});
}