forked from eatvio/eatvio_app
feat(tests): test coverage 60%
This commit is contained in:
@@ -0,0 +1,173 @@
|
||||
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/menu/presentation/bloc/menu_cubit/menu_cubit.dart';
|
||||
import 'package:eatvio_app/features/menu/presentation/pages/menu_screen.dart';
|
||||
import 'package:eatvio_app/features/profile/models/profile_model.dart';
|
||||
import 'package:eatvio_app/features/profile/repositories/profile_repository.dart';
|
||||
import 'package:eatvio_app/generated/l10n.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
||||
import 'package:flutter_localizations/flutter_localizations.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 'menu_screen_smoke_test.mocks.dart';
|
||||
|
||||
@GenerateNiceMocks([MockSpec<ProfileRepository>()])
|
||||
void main() {
|
||||
group('MenuScreen 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'));
|
||||
});
|
||||
|
||||
const mockUserProfile = ProfileModel(
|
||||
id: 1,
|
||||
name: 'Test User',
|
||||
email: 'test@example.com',
|
||||
phoneConfirmationState: 'confirmed',
|
||||
isPublicProfile: true,
|
||||
isBlockedByMe: false,
|
||||
isBlockedByAuthor: false,
|
||||
isBlockedByUser: false,
|
||||
isEntitySubscribedByMe: false,
|
||||
slug: 'test-user',
|
||||
profilePhotoUrl: 'https://example.com/avatar.jpg',
|
||||
roles: ['user'],
|
||||
badges: [],
|
||||
subscriptions: [],
|
||||
subscribers: [],
|
||||
);
|
||||
|
||||
const mockConsultantProfile = ProfileModel(
|
||||
id: 1,
|
||||
name: 'Test Consultant',
|
||||
email: 'consultant@example.com',
|
||||
phoneConfirmationState: 'confirmed',
|
||||
isPublicProfile: true,
|
||||
isBlockedByMe: false,
|
||||
isBlockedByAuthor: false,
|
||||
isBlockedByUser: false,
|
||||
isEntitySubscribedByMe: false,
|
||||
slug: 'test-consultant',
|
||||
profilePhotoUrl: 'https://example.com/avatar.jpg',
|
||||
roles: ['consultant'],
|
||||
badges: [],
|
||||
subscriptions: [],
|
||||
subscribers: [],
|
||||
);
|
||||
|
||||
Widget wrap(Widget child) {
|
||||
return MaterialApp.router(
|
||||
theme: ThemeHelper().themeData(),
|
||||
localizationsDelegates: const [
|
||||
S.delegate,
|
||||
GlobalMaterialLocalizations.delegate,
|
||||
GlobalWidgetsLocalizations.delegate,
|
||||
GlobalCupertinoLocalizations.delegate,
|
||||
],
|
||||
supportedLocales: const [Locale('ru')],
|
||||
routerConfig: GoRouter(
|
||||
initialLocation: '/',
|
||||
routes: [
|
||||
GoRoute(path: '/', builder: (context, state) => child),
|
||||
GoRoute(
|
||||
path: '/settings-screen',
|
||||
builder: (context, state) => const Scaffold(body: Text('Settings')),
|
||||
),
|
||||
GoRoute(
|
||||
path: '/glossary-screen',
|
||||
builder: (context, state) => const Scaffold(body: Text('Glossary')),
|
||||
),
|
||||
GoRoute(
|
||||
path: '/support-screen',
|
||||
builder: (context, state) => const Scaffold(body: Text('Support')),
|
||||
),
|
||||
GoRoute(
|
||||
path: '/my-recipes-screen',
|
||||
name: 'myRecipesScreen',
|
||||
builder: (context, state) => const Scaffold(body: Text('My Recipes')),
|
||||
),
|
||||
GoRoute(
|
||||
path: '/my-diets-screen',
|
||||
name: 'myDietsScreen',
|
||||
builder: (context, state) => const Scaffold(body: Text('My Diets')),
|
||||
),
|
||||
GoRoute(
|
||||
path: '/my-plans-screen',
|
||||
name: 'myPlansScreen',
|
||||
builder: (context, state) => const Scaffold(body: Text('My Plans')),
|
||||
),
|
||||
GoRoute(
|
||||
path: '/consultant-finances-screen',
|
||||
name: 'consultantFinancesScreen',
|
||||
builder: (context, state) => const Scaffold(body: Text('Consultant Finances')),
|
||||
),
|
||||
GoRoute(
|
||||
path: '/user-purchases-screen',
|
||||
name: 'userPurchasesScreen',
|
||||
builder: (context, state) => const Scaffold(body: Text('User Purchases')),
|
||||
),
|
||||
GoRoute(
|
||||
path: '/consultant-rating-screen',
|
||||
name: 'consultantRatingScreen',
|
||||
builder: (context, state) => const Scaffold(body: Text('Consultant Rating')),
|
||||
),
|
||||
GoRoute(
|
||||
path: '/notifications-settings-screen',
|
||||
name: 'notificationsSettingsScreen',
|
||||
builder: (context, state) => const Scaffold(body: Text('Notifications Settings')),
|
||||
),
|
||||
GoRoute(
|
||||
path: '/blocked-users-screen',
|
||||
name: 'blockedUsersScreen',
|
||||
builder: (context, state) => const Scaffold(body: Text('Blocked Users')),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
testWidgets('renders menu screen for user', (tester) async {
|
||||
final repository = MockProfileRepository();
|
||||
final cubit = MenuCubit(repository);
|
||||
|
||||
when(repository.getPassKey(routeName: anyNamed('routeName'), routeParams: anyNamed('routeParams'))).thenAnswer((_) async => 'test-passkey');
|
||||
|
||||
sl.registerLazySingleton<ProfileRepository>(() => repository);
|
||||
sl.registerLazySingleton<MenuCubit>(() => cubit);
|
||||
|
||||
await tester.pumpWidget(wrap(const MenuScreen(profileModel: mockUserProfile)));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('Меню'), findsOneWidget);
|
||||
expect(find.text('Настройки профиля'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('renders menu screen for consultant', (tester) async {
|
||||
final repository = MockProfileRepository();
|
||||
final cubit = MenuCubit(repository);
|
||||
|
||||
when(repository.getPassKey(routeName: anyNamed('routeName'), routeParams: anyNamed('routeParams'))).thenAnswer((_) async => 'test-passkey');
|
||||
|
||||
sl.registerLazySingleton<ProfileRepository>(() => repository);
|
||||
sl.registerLazySingleton<MenuCubit>(() => cubit);
|
||||
|
||||
await tester.pumpWidget(wrap(const MenuScreen(profileModel: mockConsultantProfile)));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('Меню'), findsOneWidget);
|
||||
expect(find.text('Мои рецепты'), findsOneWidget);
|
||||
expect(find.text('Мои диеты'), findsOneWidget);
|
||||
expect(find.text('Мои планы'), findsOneWidget);
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
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/menu/models/notification_settings_model.dart';
|
||||
import 'package:eatvio_app/features/menu/presentation/bloc/notification_settings_cubit/notification_settings_cubit.dart';
|
||||
import 'package:eatvio_app/features/menu/presentation/pages/notifications_settings_screen.dart';
|
||||
import 'package:eatvio_app/features/menu/repositories/notification_settings_repository.dart';
|
||||
import 'package:eatvio_app/generated/l10n.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
||||
import 'package:flutter_localizations/flutter_localizations.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:mockito/annotations.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
|
||||
import 'notifications_settings_screen_smoke_test.mocks.dart';
|
||||
|
||||
@GenerateNiceMocks([MockSpec<NotificationSettingsRepository>()])
|
||||
void main() {
|
||||
group('NotificationsSettingsScreen 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'));
|
||||
});
|
||||
|
||||
const mockNotificationSettings = NotificationSettingsModel(
|
||||
newUpdatesNotification: true,
|
||||
weightMeasurementsNotification: true,
|
||||
isEmailNotificationsEnabled: true,
|
||||
isPushNotificationsEnabled: true,
|
||||
diaryReminderNotifications: DiaryReminderNotifications(
|
||||
firstReminder: ReminderSettings(enabled: true, localTimeHours: 9, localTimeMins: 0),
|
||||
secondReminder: ReminderSettings(enabled: true, localTimeHours: 13, localTimeMins: 0),
|
||||
thirdReminder: ReminderSettings(enabled: false, localTimeHours: 18, localTimeMins: 0),
|
||||
),
|
||||
);
|
||||
|
||||
Widget wrap(Widget child) {
|
||||
return MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
localizationsDelegates: const [
|
||||
S.delegate,
|
||||
GlobalMaterialLocalizations.delegate,
|
||||
GlobalWidgetsLocalizations.delegate,
|
||||
GlobalCupertinoLocalizations.delegate,
|
||||
],
|
||||
supportedLocales: const [Locale('ru')],
|
||||
home: child,
|
||||
);
|
||||
}
|
||||
|
||||
testWidgets('renders loading state', (tester) async {
|
||||
tester.view.physicalSize = const Size(800, 1200);
|
||||
tester.view.devicePixelRatio = 1.0;
|
||||
addTearDown(() => tester.view.resetPhysicalSize());
|
||||
|
||||
final repository = MockNotificationSettingsRepository();
|
||||
final cubit = NotificationSettingsCubit(notificationSettingsRepository: repository);
|
||||
|
||||
when(repository.getNotificationSettings()).thenAnswer((_) async => mockNotificationSettings);
|
||||
|
||||
sl.registerLazySingleton<NotificationSettingsRepository>(() => repository);
|
||||
sl.registerLazySingleton<NotificationSettingsCubit>(() => cubit);
|
||||
|
||||
await tester.pumpWidget(wrap(const NotificationsSettingsScreen()));
|
||||
await tester.pump();
|
||||
|
||||
|
||||
expect(find.byType(NotificationsSettingsScreen), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('renders loaded state with settings', (tester) async {
|
||||
tester.view.physicalSize = const Size(800, 1200);
|
||||
tester.view.devicePixelRatio = 1.0;
|
||||
addTearDown(() => tester.view.resetPhysicalSize());
|
||||
|
||||
final repository = MockNotificationSettingsRepository();
|
||||
final cubit = NotificationSettingsCubit(notificationSettingsRepository: repository);
|
||||
|
||||
when(repository.getNotificationSettings()).thenAnswer((_) async => mockNotificationSettings);
|
||||
|
||||
sl.registerLazySingleton<NotificationSettingsRepository>(() => repository);
|
||||
sl.registerLazySingleton<NotificationSettingsCubit>(() => cubit);
|
||||
|
||||
await tester.pumpWidget(wrap(const NotificationsSettingsScreen()));
|
||||
await tester.pump();
|
||||
await tester.pump(const Duration(milliseconds: 100));
|
||||
|
||||
|
||||
expect(find.byType(NotificationsSettingsScreen), findsOneWidget);
|
||||
expect(find.text('Новые обновления'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('renders error state', (tester) async {
|
||||
final repository = MockNotificationSettingsRepository();
|
||||
final cubit = NotificationSettingsCubit(notificationSettingsRepository: repository);
|
||||
|
||||
when(repository.getNotificationSettings()).thenThrow(Exception('Error loading settings'));
|
||||
|
||||
sl.registerLazySingleton<NotificationSettingsRepository>(() => repository);
|
||||
sl.registerLazySingleton<NotificationSettingsCubit>(() => cubit);
|
||||
|
||||
await tester.pumpWidget(wrap(const NotificationsSettingsScreen()));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.textContaining('Ошибка'), findsOneWidget);
|
||||
expect(find.text('Повторить'), findsOneWidget);
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user