forked from eatvio/eatvio_app
feat(coverage): enhance coverage analysis script to filter generated files and generate detailed markdown report for files with less than 100% coverage
This commit is contained in:
@@ -136,3 +136,4 @@ void main() {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -71,3 +71,4 @@ void main() {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -85,3 +85,4 @@ void main() {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -34,3 +34,4 @@ void main() {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -60,3 +60,4 @@ void main() {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -30,3 +30,4 @@ void main() {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -27,3 +27,4 @@ void main() {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -31,3 +31,4 @@ void main() {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -110,3 +110,4 @@ void main() {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -34,3 +34,4 @@ void main() {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -28,3 +28,4 @@ void main() {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -64,3 +64,4 @@ void main() {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -116,3 +116,4 @@ void main() {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -53,3 +53,4 @@ void main() {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -135,3 +135,4 @@ void main() {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -96,3 +96,4 @@ void main() {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -164,3 +164,4 @@ void main() {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -57,3 +57,4 @@ void main() {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -42,3 +42,4 @@ void main() {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -96,3 +96,4 @@ void main() {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -76,3 +76,4 @@ void main() {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -65,3 +65,4 @@ void main() {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
import 'package:eatvio_app/core/locator_service.dart';
|
||||
import 'package:eatvio_app/core/theme/theme_helper.dart';
|
||||
import 'package:eatvio_app/features/auth/presentation/bloc/reset_password_cubit/reset_password_cubit.dart';
|
||||
import 'package:eatvio_app/features/auth/presentation/pages/forget_password_screen.dart';
|
||||
import 'package:eatvio_app/features/auth/repositories/reset_password_repository.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:mockito/annotations.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
|
||||
import 'forget_password_screen_test.mocks.dart';
|
||||
|
||||
@GenerateMocks([ResetPasswordRepository])
|
||||
void main() {
|
||||
group('ForgetPasswordScreen', () {
|
||||
late MockResetPasswordRepository mockResetPasswordRepository;
|
||||
late ResetPasswordCubit resetPasswordCubit;
|
||||
|
||||
setUp(() async {
|
||||
await sl.reset();
|
||||
mockResetPasswordRepository = MockResetPasswordRepository();
|
||||
resetPasswordCubit = ResetPasswordCubit(
|
||||
resetPasswordRepository: mockResetPasswordRepository,
|
||||
);
|
||||
sl.registerLazySingleton<ResetPasswordCubit>(() => resetPasswordCubit);
|
||||
});
|
||||
|
||||
tearDown(() {
|
||||
resetPasswordCubit.close();
|
||||
});
|
||||
|
||||
Widget createTestWidget({required bool isAuth}) {
|
||||
return MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
home: ForgetPasswordScreen(isAuth: isAuth),
|
||||
);
|
||||
}
|
||||
|
||||
testWidgets('displays screen with correct title when isAuth is false', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(createTestWidget(isAuth: false));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('Восстановление пароля'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('displays screen with correct title when isAuth is true', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(createTestWidget(isAuth: true));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('Смена пароля'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('displays email field in initial state', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(createTestWidget(isAuth: false));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('E-mail'), findsOneWidget);
|
||||
expect(find.text('Введите e-mail'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('displays email field in initial state', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(createTestWidget(isAuth: false));
|
||||
await tester.pump(); // Use pump instead of pumpAndSettle
|
||||
|
||||
// Check that email field exists
|
||||
final textFields = find.byType(TextFormField);
|
||||
expect(textFields, findsWidgets);
|
||||
});
|
||||
|
||||
testWidgets('displays button in initial state', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(createTestWidget(isAuth: false));
|
||||
await tester.pump(); // Use pump instead of pumpAndSettle
|
||||
|
||||
// Check that button exists (either "Сбросить пароль" or "Сменить пароль")
|
||||
expect(find.text('Сбросить пароль'), findsOneWidget);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
112
test/features/chat/presentation/pages/chats_screen_test.dart
Normal file
112
test/features/chat/presentation/pages/chats_screen_test.dart
Normal file
@@ -0,0 +1,112 @@
|
||||
import 'package:eatvio_app/core/enums/base_state.dart';
|
||||
import 'package:eatvio_app/core/theme/theme_helper.dart';
|
||||
import 'package:eatvio_app/features/chat/presentation/bloc/chats_cubit/chats_cubit.dart';
|
||||
import 'package:eatvio_app/features/chat/presentation/bloc/chats_cubit/chats_state.dart';
|
||||
import 'package:eatvio_app/features/chat/presentation/pages/chats_screen.dart';
|
||||
import 'package:eatvio_app/generated/l10n.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.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 'chats_screen_test.mocks.dart';
|
||||
|
||||
@GenerateNiceMocks([MockSpec<ChatsCubit>()])
|
||||
void main() {
|
||||
group('ChatsScreen', () {
|
||||
late MockChatsCubit mockChatsCubit;
|
||||
|
||||
setUp(() {
|
||||
mockChatsCubit = MockChatsCubit();
|
||||
when(mockChatsCubit.state).thenReturn(
|
||||
ChatsState(
|
||||
chatRooms: [],
|
||||
state: BaseState.loading,
|
||||
isLoadingMoreChats: false,
|
||||
),
|
||||
);
|
||||
when(mockChatsCubit.stream).thenAnswer((_) => Stream.value(
|
||||
ChatsState(
|
||||
chatRooms: [],
|
||||
state: BaseState.loading,
|
||||
isLoadingMoreChats: false,
|
||||
),
|
||||
));
|
||||
});
|
||||
|
||||
Widget createTestWidget() {
|
||||
return MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
localizationsDelegates: const [
|
||||
S.delegate,
|
||||
GlobalMaterialLocalizations.delegate,
|
||||
GlobalWidgetsLocalizations.delegate,
|
||||
GlobalCupertinoLocalizations.delegate,
|
||||
],
|
||||
supportedLocales: const [Locale('ru')],
|
||||
home: BlocProvider<ChatsCubit>(
|
||||
create: (context) => mockChatsCubit,
|
||||
child: const ChatsScreen(),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
testWidgets('displays screen', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(createTestWidget());
|
||||
await tester.pump();
|
||||
|
||||
expect(find.byType(ChatsScreen), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('displays search field', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(createTestWidget());
|
||||
await tester.pump();
|
||||
|
||||
expect(find.text('Поиск'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('displays loading state', (WidgetTester tester) async {
|
||||
when(mockChatsCubit.state).thenReturn(
|
||||
ChatsState(
|
||||
chatRooms: [],
|
||||
state: BaseState.loading,
|
||||
isLoadingMoreChats: false,
|
||||
),
|
||||
);
|
||||
|
||||
await tester.pumpWidget(createTestWidget());
|
||||
await tester.pump();
|
||||
|
||||
// Screen should be displayed
|
||||
expect(find.byType(ChatsScreen), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('displays error state', (WidgetTester tester) async {
|
||||
when(mockChatsCubit.state).thenReturn(
|
||||
ChatsState(
|
||||
chatRooms: [],
|
||||
state: BaseState.error,
|
||||
isLoadingMoreChats: false,
|
||||
),
|
||||
);
|
||||
|
||||
await tester.pumpWidget(createTestWidget());
|
||||
await tester.pump();
|
||||
|
||||
// Screen should be displayed
|
||||
expect(find.byType(ChatsScreen), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('displays screen correctly', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(createTestWidget());
|
||||
await tester.pump();
|
||||
|
||||
// Screen should be displayed
|
||||
expect(find.byType(ChatsScreen), findsOneWidget);
|
||||
// Note: getChatRooms is called in initState, which is hard to test without proper setup
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -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/locator_service.dart';
|
||||
import 'package:eatvio_app/core/theme/theme_helper.dart';
|
||||
import 'package:eatvio_app/features/chat/presentation/pages/photo_view_screen.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
group('PhotoViewScreen', () {
|
||||
setUp(() async {
|
||||
await sl.reset();
|
||||
dotenv.loadFromString(envString: 'DEV_BASE_URL=http://localhost\nBASE_URL=http://localhost');
|
||||
sl.registerLazySingleton<AppConfig>(() => AppConfig(buildType: AppBuildType.tests)..setBaseUrl('http://localhost'));
|
||||
});
|
||||
|
||||
Widget createTestWidget({
|
||||
required List<dynamic> imageUrls,
|
||||
required int index,
|
||||
bool isLocal = false,
|
||||
}) {
|
||||
return MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
home: PhotoViewScreen(
|
||||
imageUrls: imageUrls,
|
||||
index: index,
|
||||
isLocal: isLocal,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
testWidgets('creates PhotoViewScreen with image URLs', (WidgetTester tester) async {
|
||||
const imageUrls = [
|
||||
'https://example.com/image1.jpg',
|
||||
'https://example.com/image2.jpg',
|
||||
];
|
||||
|
||||
await tester.pumpWidget(createTestWidget(imageUrls: imageUrls, index: 0));
|
||||
await tester.pump();
|
||||
|
||||
// Screen should be created
|
||||
expect(find.byType(PhotoViewScreen), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('initializes with correct index', (WidgetTester tester) async {
|
||||
const imageUrls = [
|
||||
'https://example.com/image1.jpg',
|
||||
'https://example.com/image2.jpg',
|
||||
'https://example.com/image3.jpg',
|
||||
];
|
||||
|
||||
await tester.pumpWidget(createTestWidget(imageUrls: imageUrls, index: 1));
|
||||
await tester.pump();
|
||||
|
||||
// Screen should be created with index 1
|
||||
expect(find.byType(PhotoViewScreen), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('handles single image', (WidgetTester tester) async {
|
||||
const imageUrls = ['https://example.com/image1.jpg'];
|
||||
|
||||
await tester.pumpWidget(createTestWidget(imageUrls: imageUrls, index: 0));
|
||||
await tester.pump();
|
||||
|
||||
expect(find.byType(PhotoViewScreen), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('handles multiple images', (WidgetTester tester) async {
|
||||
const imageUrls = [
|
||||
'https://example.com/image1.jpg',
|
||||
'https://example.com/image2.jpg',
|
||||
'https://example.com/image3.jpg',
|
||||
];
|
||||
|
||||
await tester.pumpWidget(createTestWidget(imageUrls: imageUrls, index: 0));
|
||||
await tester.pump();
|
||||
|
||||
expect(find.byType(PhotoViewScreen), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('creates screen with isLocal flag', (WidgetTester tester) async {
|
||||
// For local files, we need File objects, but in tests we'll skip this test
|
||||
// as it requires actual file system access
|
||||
// This test is skipped to avoid File type errors
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -71,3 +71,4 @@ void main() {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -80,3 +80,4 @@ void main() {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -58,3 +58,4 @@ void main() {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -53,3 +53,4 @@ void main() {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -90,3 +90,4 @@ void main() {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -42,3 +42,4 @@ void main() {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -108,3 +108,4 @@ void main() {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -138,3 +138,4 @@ void main() {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -50,3 +50,4 @@ void main() {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -58,3 +58,4 @@ void main() {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -51,3 +51,4 @@ void main() {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1028,3 +1028,4 @@ void main() {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -60,3 +60,4 @@ void main() {
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,100 @@
|
||||
import 'package:eatvio_app/core/locator_service.dart';
|
||||
import 'package:eatvio_app/core/theme/theme_helper.dart';
|
||||
import 'package:eatvio_app/features/chat/repositories/chat_repository.dart';
|
||||
import 'package:eatvio_app/features/order_info/cubit/order_info_cubit.dart';
|
||||
import 'package:eatvio_app/features/order_info/presentation/info_by_order_screen.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_localizations/flutter_localizations.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:mockito/annotations.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
|
||||
import 'info_by_order_screen_test.mocks.dart';
|
||||
|
||||
@GenerateMocks([ChatRepository, ProfileRepository])
|
||||
void main() {
|
||||
group('InfoByOrderScreen', () {
|
||||
late MockChatRepository mockChatRepository;
|
||||
late MockProfileRepository mockProfileRepository;
|
||||
late OrderInfoCubit orderInfoCubit;
|
||||
|
||||
setUp(() async {
|
||||
await sl.reset();
|
||||
mockChatRepository = MockChatRepository();
|
||||
mockProfileRepository = MockProfileRepository();
|
||||
orderInfoCubit = OrderInfoCubit(
|
||||
chatRepository: mockChatRepository,
|
||||
profileRepository: mockProfileRepository,
|
||||
);
|
||||
sl.registerLazySingleton<OrderInfoCubit>(() => orderInfoCubit);
|
||||
});
|
||||
|
||||
tearDown(() {
|
||||
orderInfoCubit.close();
|
||||
});
|
||||
|
||||
Widget createTestWidget({required int planId, bool? successfulPayment, String? customerSlug}) {
|
||||
return MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
localizationsDelegates: const [
|
||||
S.delegate,
|
||||
GlobalMaterialLocalizations.delegate,
|
||||
GlobalWidgetsLocalizations.delegate,
|
||||
GlobalCupertinoLocalizations.delegate,
|
||||
],
|
||||
supportedLocales: const [Locale('ru')],
|
||||
home: InfoByOrderScreen(
|
||||
planId: planId,
|
||||
successfulPayment: successfulPayment,
|
||||
customerSlug: customerSlug,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
testWidgets('displays screen with loading state initially', (WidgetTester tester) async {
|
||||
when(mockChatRepository.getChosenPlan(id: anyNamed('id')))
|
||||
.thenThrow(Exception('Not implemented'));
|
||||
|
||||
await tester.pumpWidget(createTestWidget(planId: 1));
|
||||
await tester.pump();
|
||||
|
||||
// Screen should be displayed (Loader widget is used, not CircularProgressIndicator directly)
|
||||
expect(find.byType(Scaffold), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('calls getChosenPlan when screen is created', (WidgetTester tester) async {
|
||||
when(mockChatRepository.getChosenPlan(id: anyNamed('id')))
|
||||
.thenThrow(Exception('Not implemented'));
|
||||
|
||||
await tester.pumpWidget(createTestWidget(planId: 123));
|
||||
await tester.pump();
|
||||
|
||||
verify(mockChatRepository.getChosenPlan(id: 123)).called(1);
|
||||
});
|
||||
|
||||
testWidgets('calls getChosenPlan when customerSlug is provided', (WidgetTester tester) async {
|
||||
when(mockChatRepository.getChosenPlan(id: anyNamed('id')))
|
||||
.thenThrow(Exception('Not implemented'));
|
||||
|
||||
await tester.pumpWidget(createTestWidget(planId: 123, customerSlug: 'test-user'));
|
||||
await tester.pump();
|
||||
|
||||
verify(mockChatRepository.getChosenPlan(id: 123)).called(1);
|
||||
// Note: getProfileBySlug is only called if getChosenPlan succeeds
|
||||
});
|
||||
|
||||
testWidgets('displays screen with back button', (WidgetTester tester) async {
|
||||
when(mockChatRepository.getChosenPlan(id: anyNamed('id')))
|
||||
.thenThrow(Exception('Not implemented'));
|
||||
|
||||
await tester.pumpWidget(createTestWidget(planId: 1));
|
||||
await tester.pump();
|
||||
|
||||
// Check for back button
|
||||
expect(find.byIcon(Icons.arrow_back), findsOneWidget);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
119
test/features/profile/presentation/pages/subs_screen_test.dart
Normal file
119
test/features/profile/presentation/pages/subs_screen_test.dart
Normal file
@@ -0,0 +1,119 @@
|
||||
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/profile/models/sub_model.dart';
|
||||
import 'package:eatvio_app/features/profile/presentation/bloc/sub_cubit/sub_cubit.dart';
|
||||
import 'package:eatvio_app/features/profile/presentation/pages/subs_screen.dart';
|
||||
import 'package:eatvio_app/features/profile/repositories/profile_repository.dart';
|
||||
import 'package:flutter/material.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 'subs_screen_test.mocks.dart';
|
||||
|
||||
@GenerateMocks([ProfileRepository])
|
||||
void main() {
|
||||
group('SubsScreen', () {
|
||||
late MockProfileRepository mockProfileRepository;
|
||||
late SubCubit subCubit;
|
||||
|
||||
setUp(() async {
|
||||
await sl.reset();
|
||||
dotenv.loadFromString(envString: 'DEV_BASE_URL=http://localhost\nBASE_URL=http://localhost');
|
||||
sl.registerLazySingleton<AppConfig>(() => AppConfig(buildType: AppBuildType.tests)..setBaseUrl('http://localhost'));
|
||||
mockProfileRepository = MockProfileRepository();
|
||||
subCubit = SubCubit(profileRepository: mockProfileRepository);
|
||||
sl.registerLazySingleton<SubCubit>(() => subCubit);
|
||||
});
|
||||
|
||||
tearDown(() {
|
||||
subCubit.close();
|
||||
});
|
||||
|
||||
Widget createTestWidget({required SubType subType, required String slug}) {
|
||||
return MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
home: SubsScreen(subType: subType, slug: slug),
|
||||
);
|
||||
}
|
||||
|
||||
testWidgets('displays screen with correct title for subscriptions', (WidgetTester tester) async {
|
||||
when(mockProfileRepository.getSubscriptionsBySlug(any, any))
|
||||
.thenAnswer((_) async => []);
|
||||
|
||||
await tester.pumpWidget(createTestWidget(subType: SubType.subscriptions, slug: 'test-user'));
|
||||
await tester.pump(); // Use pump instead of pumpAndSettle
|
||||
|
||||
expect(find.text('Подписки'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('displays screen with correct title for subscribers', (WidgetTester tester) async {
|
||||
when(mockProfileRepository.getSubscribersBySlug(any, any))
|
||||
.thenAnswer((_) async => []);
|
||||
|
||||
await tester.pumpWidget(createTestWidget(subType: SubType.subscribers, slug: 'test-user'));
|
||||
await tester.pump(); // Use pump instead of pumpAndSettle
|
||||
|
||||
expect(find.text('Подписчики'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('displays search field', (WidgetTester tester) async {
|
||||
when(mockProfileRepository.getSubscriptionsBySlug(any, any))
|
||||
.thenAnswer((_) async => []);
|
||||
|
||||
await tester.pumpWidget(createTestWidget(subType: SubType.subscriptions, slug: 'test-user'));
|
||||
await tester.pump();
|
||||
|
||||
expect(find.text('Поиск'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('displays loading state', (WidgetTester tester) async {
|
||||
when(mockProfileRepository.getSubscriptionsBySlug(any, any))
|
||||
.thenAnswer((_) async => []);
|
||||
|
||||
await tester.pumpWidget(createTestWidget(subType: SubType.subscriptions, slug: 'test-user'));
|
||||
await tester.pump();
|
||||
|
||||
// Check for loader widget (Loader widget is used, not CircularProgressIndicator directly)
|
||||
// The screen should be displayed even in loading state
|
||||
expect(find.text('Подписки'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('displays error state', (WidgetTester tester) async {
|
||||
when(mockProfileRepository.getSubscriptionsBySlug(any, any))
|
||||
.thenThrow(Exception('Error loading subscriptions'));
|
||||
|
||||
await tester.pumpWidget(createTestWidget(subType: SubType.subscriptions, slug: 'test-user'));
|
||||
await tester.pump();
|
||||
await tester.pump(); // Wait for error state
|
||||
|
||||
// Error message should be displayed
|
||||
expect(find.textContaining('Error'), findsWidgets);
|
||||
});
|
||||
|
||||
|
||||
testWidgets('calls getSubscriptions when subType is subscriptions', (WidgetTester tester) async {
|
||||
when(mockProfileRepository.getSubscriptionsBySlug(any, any))
|
||||
.thenAnswer((_) async => []);
|
||||
|
||||
await tester.pumpWidget(createTestWidget(subType: SubType.subscriptions, slug: 'test-user'));
|
||||
await tester.pump();
|
||||
|
||||
verify(mockProfileRepository.getSubscriptionsBySlug('test-user', null)).called(1);
|
||||
});
|
||||
|
||||
testWidgets('calls getSubscribers when subType is subscribers', (WidgetTester tester) async {
|
||||
when(mockProfileRepository.getSubscribersBySlug(any, any))
|
||||
.thenAnswer((_) async => []);
|
||||
|
||||
await tester.pumpWidget(createTestWidget(subType: SubType.subscribers, slug: 'test-user'));
|
||||
await tester.pump();
|
||||
|
||||
verify(mockProfileRepository.getSubscribersBySlug('test-user', null)).called(1);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -0,0 +1,393 @@
|
||||
import 'package:eatvio_app/core/prefs.dart';
|
||||
import 'package:eatvio_app/core/theme/theme_helper.dart';
|
||||
import 'package:eatvio_app/features/registration/models/user_registration_model.dart';
|
||||
import 'package:eatvio_app/features/registration/presentation/bloc/registration_cubit/registration_cubit.dart';
|
||||
import 'package:eatvio_app/features/registration/presentation/pages/body_circumferences_screen.dart';
|
||||
import 'package:eatvio_app/features/registration/repositories/registration_repository.dart';
|
||||
import 'package:eatvio_app/generated/l10n.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:flutter_localizations/flutter_localizations.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:mockito/annotations.dart';
|
||||
|
||||
import 'body_circumferences_screen_test.mocks.dart';
|
||||
|
||||
@GenerateMocks([RegistrationRepository, Prefs])
|
||||
void main() {
|
||||
group('BodyCircumferencesScreen', () {
|
||||
late MockRegistrationRepository mockRegistrationRepository;
|
||||
late RegistrationCubit registrationCubit;
|
||||
|
||||
setUp(() {
|
||||
mockRegistrationRepository = MockRegistrationRepository();
|
||||
registrationCubit = RegistrationCubit(
|
||||
registrationRepository: mockRegistrationRepository,
|
||||
prefs: MockPrefs(),
|
||||
);
|
||||
});
|
||||
|
||||
tearDown(() {
|
||||
registrationCubit.close();
|
||||
});
|
||||
|
||||
Widget createTestWidget(UserRegistrationSheet sheet) {
|
||||
return MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
localizationsDelegates: const [
|
||||
S.delegate,
|
||||
GlobalMaterialLocalizations.delegate,
|
||||
GlobalWidgetsLocalizations.delegate,
|
||||
GlobalCupertinoLocalizations.delegate,
|
||||
],
|
||||
supportedLocales: const [Locale('ru')],
|
||||
home: Scaffold(
|
||||
body: BlocProvider<RegistrationCubit>(
|
||||
create: (context) => registrationCubit,
|
||||
child: BodyCircumferencesScreen(sheet: sheet),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
testWidgets('displays screen with initial circumferences from sheet', (WidgetTester tester) async {
|
||||
const sheet = UserRegistrationSheet(
|
||||
firstName: 'John',
|
||||
lastName: 'Doe',
|
||||
email: 'john@example.com',
|
||||
password: 'password123',
|
||||
passwordConfirmation: 'password123',
|
||||
birthdate: '1990-01-01',
|
||||
gender: 'male',
|
||||
location: 'Moscow',
|
||||
responseBody: '{}',
|
||||
lang: 'ru',
|
||||
weight: 75,
|
||||
height: 180,
|
||||
phone: '+1234567890',
|
||||
chestCircumference: 100,
|
||||
waistCircumference: 80,
|
||||
hipCircumference: 90,
|
||||
bloodPressureUp: 120,
|
||||
bloodPressureDown: 80,
|
||||
hasHypo: 0,
|
||||
hasHyper: 0,
|
||||
aboutAllergy: 'None',
|
||||
aboutTakingPils: 'None',
|
||||
aboutSportHobbies: 'Running',
|
||||
favoriteFoods: 'Pizza',
|
||||
unfavoriteFoods: 'Broccoli',
|
||||
additionalInfo: 'No additional info',
|
||||
);
|
||||
|
||||
await tester.pumpWidget(createTestWidget(sheet));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// Check that text fields contain the values
|
||||
final textFields = find.byType(TextFormField);
|
||||
expect(textFields, findsNWidgets(3));
|
||||
|
||||
// Verify values in text fields
|
||||
final firstField = tester.widget<TextFormField>(textFields.first);
|
||||
expect(firstField.controller?.text, '100');
|
||||
|
||||
final secondField = tester.widget<TextFormField>(textFields.at(1));
|
||||
expect(secondField.controller?.text, '80');
|
||||
|
||||
final thirdField = tester.widget<TextFormField>(textFields.at(2));
|
||||
expect(thirdField.controller?.text, '90');
|
||||
});
|
||||
|
||||
testWidgets('displays empty fields when circumferences are 0', (WidgetTester tester) async {
|
||||
const sheet = UserRegistrationSheet(
|
||||
firstName: 'John',
|
||||
lastName: 'Doe',
|
||||
email: 'john@example.com',
|
||||
password: 'password123',
|
||||
passwordConfirmation: 'password123',
|
||||
birthdate: '1990-01-01',
|
||||
gender: 'male',
|
||||
location: 'Moscow',
|
||||
responseBody: '{}',
|
||||
lang: 'ru',
|
||||
weight: 75,
|
||||
height: 180,
|
||||
phone: '+1234567890',
|
||||
chestCircumference: 0,
|
||||
waistCircumference: 0,
|
||||
hipCircumference: 0,
|
||||
bloodPressureUp: 120,
|
||||
bloodPressureDown: 80,
|
||||
hasHypo: 0,
|
||||
hasHyper: 0,
|
||||
aboutAllergy: 'None',
|
||||
aboutTakingPils: 'None',
|
||||
aboutSportHobbies: 'Running',
|
||||
favoriteFoods: 'Pizza',
|
||||
unfavoriteFoods: 'Broccoli',
|
||||
additionalInfo: 'No additional info',
|
||||
);
|
||||
|
||||
await tester.pumpWidget(createTestWidget(sheet));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
final textFields = find.byType(TextFormField);
|
||||
expect(textFields, findsNWidgets(3));
|
||||
});
|
||||
|
||||
testWidgets('displays hint texts', (WidgetTester tester) async {
|
||||
const sheet = UserRegistrationSheet(
|
||||
firstName: 'John',
|
||||
lastName: 'Doe',
|
||||
email: 'john@example.com',
|
||||
password: 'password123',
|
||||
passwordConfirmation: 'password123',
|
||||
birthdate: '1990-01-01',
|
||||
gender: 'male',
|
||||
location: 'Moscow',
|
||||
responseBody: '{}',
|
||||
lang: 'ru',
|
||||
weight: 75,
|
||||
height: 180,
|
||||
phone: '+1234567890',
|
||||
chestCircumference: 0,
|
||||
waistCircumference: 0,
|
||||
hipCircumference: 0,
|
||||
bloodPressureUp: 120,
|
||||
bloodPressureDown: 80,
|
||||
hasHypo: 0,
|
||||
hasHyper: 0,
|
||||
aboutAllergy: 'None',
|
||||
aboutTakingPils: 'None',
|
||||
aboutSportHobbies: 'Running',
|
||||
favoriteFoods: 'Pizza',
|
||||
unfavoriteFoods: 'Broccoli',
|
||||
additionalInfo: 'No additional info',
|
||||
);
|
||||
|
||||
await tester.pumpWidget(createTestWidget(sheet));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// Check hint texts are displayed
|
||||
final textFields = find.byType(TextFormField);
|
||||
expect(textFields, findsNWidgets(3));
|
||||
|
||||
// Hint texts should be visible when fields are empty
|
||||
expect(find.text('90'), findsWidgets); // Appears as hint for chest and hip
|
||||
expect(find.text('60'), findsOneWidget); // Appears as hint for waist
|
||||
});
|
||||
|
||||
testWidgets('updates registration cubit when chest circumference changes', (WidgetTester tester) async {
|
||||
const sheet = UserRegistrationSheet(
|
||||
firstName: 'John',
|
||||
lastName: 'Doe',
|
||||
email: 'john@example.com',
|
||||
password: 'password123',
|
||||
passwordConfirmation: 'password123',
|
||||
birthdate: '1990-01-01',
|
||||
gender: 'male',
|
||||
location: 'Moscow',
|
||||
responseBody: '{}',
|
||||
lang: 'ru',
|
||||
weight: 75,
|
||||
height: 180,
|
||||
phone: '+1234567890',
|
||||
chestCircumference: 100,
|
||||
waistCircumference: 80,
|
||||
hipCircumference: 90,
|
||||
bloodPressureUp: 120,
|
||||
bloodPressureDown: 80,
|
||||
hasHypo: 0,
|
||||
hasHyper: 0,
|
||||
aboutAllergy: 'None',
|
||||
aboutTakingPils: 'None',
|
||||
aboutSportHobbies: 'Running',
|
||||
favoriteFoods: 'Pizza',
|
||||
unfavoriteFoods: 'Broccoli',
|
||||
additionalInfo: 'No additional info',
|
||||
);
|
||||
|
||||
await tester.pumpWidget(createTestWidget(sheet));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
final textFields = find.byType(TextFormField);
|
||||
expect(textFields, findsNWidgets(3));
|
||||
|
||||
await tester.enterText(textFields.first, '105');
|
||||
await tester.pump();
|
||||
|
||||
// Verify that the cubit state was updated
|
||||
expect(registrationCubit.state.sheet.chestCircumference, 105);
|
||||
});
|
||||
|
||||
testWidgets('updates registration cubit when waist circumference changes', (WidgetTester tester) async {
|
||||
const sheet = UserRegistrationSheet(
|
||||
firstName: 'John',
|
||||
lastName: 'Doe',
|
||||
email: 'john@example.com',
|
||||
password: 'password123',
|
||||
passwordConfirmation: 'password123',
|
||||
birthdate: '1990-01-01',
|
||||
gender: 'male',
|
||||
location: 'Moscow',
|
||||
responseBody: '{}',
|
||||
lang: 'ru',
|
||||
weight: 75,
|
||||
height: 180,
|
||||
phone: '+1234567890',
|
||||
chestCircumference: 100,
|
||||
waistCircumference: 80,
|
||||
hipCircumference: 90,
|
||||
bloodPressureUp: 120,
|
||||
bloodPressureDown: 80,
|
||||
hasHypo: 0,
|
||||
hasHyper: 0,
|
||||
aboutAllergy: 'None',
|
||||
aboutTakingPils: 'None',
|
||||
aboutSportHobbies: 'Running',
|
||||
favoriteFoods: 'Pizza',
|
||||
unfavoriteFoods: 'Broccoli',
|
||||
additionalInfo: 'No additional info',
|
||||
);
|
||||
|
||||
await tester.pumpWidget(createTestWidget(sheet));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
final textFields = find.byType(TextFormField);
|
||||
expect(textFields, findsNWidgets(3));
|
||||
|
||||
await tester.enterText(textFields.at(1), '85');
|
||||
await tester.pump();
|
||||
|
||||
// Verify that the cubit state was updated
|
||||
expect(registrationCubit.state.sheet.waistCircumference, 85);
|
||||
});
|
||||
|
||||
testWidgets('updates registration cubit when hip circumference changes', (WidgetTester tester) async {
|
||||
const sheet = UserRegistrationSheet(
|
||||
firstName: 'John',
|
||||
lastName: 'Doe',
|
||||
email: 'john@example.com',
|
||||
password: 'password123',
|
||||
passwordConfirmation: 'password123',
|
||||
birthdate: '1990-01-01',
|
||||
gender: 'male',
|
||||
location: 'Moscow',
|
||||
responseBody: '{}',
|
||||
lang: 'ru',
|
||||
weight: 75,
|
||||
height: 180,
|
||||
phone: '+1234567890',
|
||||
chestCircumference: 100,
|
||||
waistCircumference: 80,
|
||||
hipCircumference: 90,
|
||||
bloodPressureUp: 120,
|
||||
bloodPressureDown: 80,
|
||||
hasHypo: 0,
|
||||
hasHyper: 0,
|
||||
aboutAllergy: 'None',
|
||||
aboutTakingPils: 'None',
|
||||
aboutSportHobbies: 'Running',
|
||||
favoriteFoods: 'Pizza',
|
||||
unfavoriteFoods: 'Broccoli',
|
||||
additionalInfo: 'No additional info',
|
||||
);
|
||||
|
||||
await tester.pumpWidget(createTestWidget(sheet));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
final textFields = find.byType(TextFormField);
|
||||
expect(textFields, findsNWidgets(3));
|
||||
|
||||
await tester.enterText(textFields.at(2), '95');
|
||||
await tester.pump();
|
||||
|
||||
// Verify that the cubit state was updated
|
||||
expect(registrationCubit.state.sheet.hipCircumference, 95);
|
||||
});
|
||||
|
||||
testWidgets('only accepts digits input', (WidgetTester tester) async {
|
||||
const sheet = UserRegistrationSheet(
|
||||
firstName: 'John',
|
||||
lastName: 'Doe',
|
||||
email: 'john@example.com',
|
||||
password: 'password123',
|
||||
passwordConfirmation: 'password123',
|
||||
birthdate: '1990-01-01',
|
||||
gender: 'male',
|
||||
location: 'Moscow',
|
||||
responseBody: '{}',
|
||||
lang: 'ru',
|
||||
weight: 75,
|
||||
height: 180,
|
||||
phone: '+1234567890',
|
||||
chestCircumference: 0,
|
||||
waistCircumference: 0,
|
||||
hipCircumference: 0,
|
||||
bloodPressureUp: 120,
|
||||
bloodPressureDown: 80,
|
||||
hasHypo: 0,
|
||||
hasHyper: 0,
|
||||
aboutAllergy: 'None',
|
||||
aboutTakingPils: 'None',
|
||||
aboutSportHobbies: 'Running',
|
||||
favoriteFoods: 'Pizza',
|
||||
unfavoriteFoods: 'Broccoli',
|
||||
additionalInfo: 'No additional info',
|
||||
);
|
||||
|
||||
await tester.pumpWidget(createTestWidget(sheet));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
final textFields = find.byType(TextFormField);
|
||||
expect(textFields, findsNWidgets(3));
|
||||
|
||||
// Try to enter non-digit characters
|
||||
await tester.enterText(textFields.first, 'abc');
|
||||
await tester.pump();
|
||||
|
||||
// The text field should only accept digits (filtered by inputFormatters)
|
||||
final textFieldWidget = tester.widget<TextFormField>(textFields.first);
|
||||
// Since digitsOnly formatter filters non-digits, the text should be empty
|
||||
expect(textFieldWidget.controller?.text, isEmpty);
|
||||
});
|
||||
|
||||
testWidgets('displays labels for all circumference fields', (WidgetTester tester) async {
|
||||
const sheet = UserRegistrationSheet(
|
||||
firstName: 'John',
|
||||
lastName: 'Doe',
|
||||
email: 'john@example.com',
|
||||
password: 'password123',
|
||||
passwordConfirmation: 'password123',
|
||||
birthdate: '1990-01-01',
|
||||
gender: 'male',
|
||||
location: 'Moscow',
|
||||
responseBody: '{}',
|
||||
lang: 'ru',
|
||||
weight: 75,
|
||||
height: 180,
|
||||
phone: '+1234567890',
|
||||
chestCircumference: 0,
|
||||
waistCircumference: 0,
|
||||
hipCircumference: 0,
|
||||
bloodPressureUp: 120,
|
||||
bloodPressureDown: 80,
|
||||
hasHypo: 0,
|
||||
hasHyper: 0,
|
||||
aboutAllergy: 'None',
|
||||
aboutTakingPils: 'None',
|
||||
aboutSportHobbies: 'Running',
|
||||
favoriteFoods: 'Pizza',
|
||||
unfavoriteFoods: 'Broccoli',
|
||||
additionalInfo: 'No additional info',
|
||||
);
|
||||
|
||||
await tester.pumpWidget(createTestWidget(sheet));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// Check that labels are displayed (they contain "(не обязательно)")
|
||||
expect(find.textContaining('не обязательно'), findsNWidgets(3));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -0,0 +1,275 @@
|
||||
import 'package:eatvio_app/core/prefs.dart';
|
||||
import 'package:eatvio_app/core/theme/theme_helper.dart';
|
||||
import 'package:eatvio_app/features/registration/models/location_model.dart';
|
||||
import 'package:eatvio_app/features/registration/models/user_registration_model.dart';
|
||||
import 'package:eatvio_app/features/registration/presentation/bloc/registration_cubit/registration_cubit.dart';
|
||||
import 'package:eatvio_app/features/registration/presentation/pages/city_of_living_screen.dart';
|
||||
import 'package:eatvio_app/features/registration/repositories/registration_repository.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:mockito/annotations.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
|
||||
import 'city_of_living_screen_test.mocks.dart';
|
||||
|
||||
@GenerateMocks([RegistrationRepository, Prefs])
|
||||
void main() {
|
||||
group('CityOfLivingScreen', () {
|
||||
late MockRegistrationRepository mockRegistrationRepository;
|
||||
late RegistrationCubit registrationCubit;
|
||||
|
||||
setUp(() {
|
||||
mockRegistrationRepository = MockRegistrationRepository();
|
||||
registrationCubit = RegistrationCubit(
|
||||
registrationRepository: mockRegistrationRepository,
|
||||
prefs: MockPrefs(),
|
||||
);
|
||||
// Mock getLocationsListByQuery to return empty list by default
|
||||
when(mockRegistrationRepository.getLocationsListByQuery(any))
|
||||
.thenAnswer((_) async => LocationModel(locations: [], responseBody: '{}'));
|
||||
});
|
||||
|
||||
tearDown(() {
|
||||
registrationCubit.close();
|
||||
});
|
||||
|
||||
Widget createTestWidget(UserRegistrationSheet sheet) {
|
||||
return MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
home: Scaffold(
|
||||
body: BlocProvider<RegistrationCubit>(
|
||||
create: (context) => registrationCubit,
|
||||
child: CityOfLivingScreen(sheet: sheet),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
testWidgets('displays screen with initial location from sheet', (WidgetTester tester) async {
|
||||
const sheet = UserRegistrationSheet(
|
||||
firstName: 'John',
|
||||
lastName: 'Doe',
|
||||
email: 'john@example.com',
|
||||
password: 'password123',
|
||||
passwordConfirmation: 'password123',
|
||||
birthdate: '1990-01-01',
|
||||
gender: 'male',
|
||||
location: 'Moscow',
|
||||
responseBody: '{}',
|
||||
lang: 'ru',
|
||||
weight: 75,
|
||||
height: 180,
|
||||
phone: '+1234567890',
|
||||
chestCircumference: 100,
|
||||
waistCircumference: 80,
|
||||
hipCircumference: 90,
|
||||
bloodPressureUp: 120,
|
||||
bloodPressureDown: 80,
|
||||
hasHypo: 0,
|
||||
hasHyper: 0,
|
||||
aboutAllergy: 'None',
|
||||
aboutTakingPils: 'None',
|
||||
aboutSportHobbies: 'Running',
|
||||
favoriteFoods: 'Pizza',
|
||||
unfavoriteFoods: 'Broccoli',
|
||||
additionalInfo: 'No additional info',
|
||||
);
|
||||
|
||||
await tester.pumpWidget(createTestWidget(sheet));
|
||||
await tester.pump(); // Use pump instead of pumpAndSettle to avoid timeout
|
||||
|
||||
expect(find.text('Moscow'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('displays empty field when location is empty', (WidgetTester tester) async {
|
||||
const sheet = UserRegistrationSheet(
|
||||
firstName: 'John',
|
||||
lastName: 'Doe',
|
||||
email: 'john@example.com',
|
||||
password: 'password123',
|
||||
passwordConfirmation: 'password123',
|
||||
birthdate: '1990-01-01',
|
||||
gender: 'male',
|
||||
location: '',
|
||||
responseBody: '{}',
|
||||
lang: 'ru',
|
||||
weight: 75,
|
||||
height: 180,
|
||||
phone: '+1234567890',
|
||||
chestCircumference: 100,
|
||||
waistCircumference: 80,
|
||||
hipCircumference: 90,
|
||||
bloodPressureUp: 120,
|
||||
bloodPressureDown: 80,
|
||||
hasHypo: 0,
|
||||
hasHyper: 0,
|
||||
aboutAllergy: 'None',
|
||||
aboutTakingPils: 'None',
|
||||
aboutSportHobbies: 'Running',
|
||||
favoriteFoods: 'Pizza',
|
||||
unfavoriteFoods: 'Broccoli',
|
||||
additionalInfo: 'No additional info',
|
||||
);
|
||||
|
||||
await tester.pumpWidget(createTestWidget(sheet));
|
||||
await tester.pump(); // Use pump instead of pumpAndSettle to avoid timeout
|
||||
|
||||
final textField = find.byType(TextFormField);
|
||||
expect(textField, findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('displays hint text', (WidgetTester tester) async {
|
||||
const sheet = UserRegistrationSheet(
|
||||
firstName: 'John',
|
||||
lastName: 'Doe',
|
||||
email: 'john@example.com',
|
||||
password: 'password123',
|
||||
passwordConfirmation: 'password123',
|
||||
birthdate: '1990-01-01',
|
||||
gender: 'male',
|
||||
location: '',
|
||||
responseBody: '{}',
|
||||
lang: 'ru',
|
||||
weight: 75,
|
||||
height: 180,
|
||||
phone: '+1234567890',
|
||||
chestCircumference: 100,
|
||||
waistCircumference: 80,
|
||||
hipCircumference: 90,
|
||||
bloodPressureUp: 120,
|
||||
bloodPressureDown: 80,
|
||||
hasHypo: 0,
|
||||
hasHyper: 0,
|
||||
aboutAllergy: 'None',
|
||||
aboutTakingPils: 'None',
|
||||
aboutSportHobbies: 'Running',
|
||||
favoriteFoods: 'Pizza',
|
||||
unfavoriteFoods: 'Broccoli',
|
||||
additionalInfo: 'No additional info',
|
||||
);
|
||||
|
||||
await tester.pumpWidget(createTestWidget(sheet));
|
||||
await tester.pump(); // Use pump instead of pumpAndSettle to avoid timeout
|
||||
|
||||
expect(find.text('Москва'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('displays location label', (WidgetTester tester) async {
|
||||
const sheet = UserRegistrationSheet(
|
||||
firstName: 'John',
|
||||
lastName: 'Doe',
|
||||
email: 'john@example.com',
|
||||
password: 'password123',
|
||||
passwordConfirmation: 'password123',
|
||||
birthdate: '1990-01-01',
|
||||
gender: 'male',
|
||||
location: '',
|
||||
responseBody: '{}',
|
||||
lang: 'ru',
|
||||
weight: 75,
|
||||
height: 180,
|
||||
phone: '+1234567890',
|
||||
chestCircumference: 100,
|
||||
waistCircumference: 80,
|
||||
hipCircumference: 90,
|
||||
bloodPressureUp: 120,
|
||||
bloodPressureDown: 80,
|
||||
hasHypo: 0,
|
||||
hasHyper: 0,
|
||||
aboutAllergy: 'None',
|
||||
aboutTakingPils: 'None',
|
||||
aboutSportHobbies: 'Running',
|
||||
favoriteFoods: 'Pizza',
|
||||
unfavoriteFoods: 'Broccoli',
|
||||
additionalInfo: 'No additional info',
|
||||
);
|
||||
|
||||
await tester.pumpWidget(createTestWidget(sheet));
|
||||
await tester.pump(); // Use pump instead of pumpAndSettle to avoid timeout
|
||||
|
||||
expect(find.text('Местоположение'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('updates registration cubit when location changes', (WidgetTester tester) async {
|
||||
const sheet = UserRegistrationSheet(
|
||||
firstName: 'John',
|
||||
lastName: 'Doe',
|
||||
email: 'john@example.com',
|
||||
password: 'password123',
|
||||
passwordConfirmation: 'password123',
|
||||
birthdate: '1990-01-01',
|
||||
gender: 'male',
|
||||
location: 'Moscow',
|
||||
responseBody: '{}',
|
||||
lang: 'ru',
|
||||
weight: 75,
|
||||
height: 180,
|
||||
phone: '+1234567890',
|
||||
chestCircumference: 100,
|
||||
waistCircumference: 80,
|
||||
hipCircumference: 90,
|
||||
bloodPressureUp: 120,
|
||||
bloodPressureDown: 80,
|
||||
hasHypo: 0,
|
||||
hasHyper: 0,
|
||||
aboutAllergy: 'None',
|
||||
aboutTakingPils: 'None',
|
||||
aboutSportHobbies: 'Running',
|
||||
favoriteFoods: 'Pizza',
|
||||
unfavoriteFoods: 'Broccoli',
|
||||
additionalInfo: 'No additional info',
|
||||
);
|
||||
|
||||
await tester.pumpWidget(createTestWidget(sheet));
|
||||
await tester.pump(); // Use pump instead of pumpAndSettle to avoid timeout
|
||||
|
||||
final textField = find.byType(TextFormField);
|
||||
expect(textField, findsOneWidget);
|
||||
|
||||
await tester.enterText(textField, 'Saint Petersburg');
|
||||
await tester.pump();
|
||||
|
||||
// Verify that the cubit state was updated
|
||||
expect(registrationCubit.state.sheet.location, 'Saint Petersburg');
|
||||
});
|
||||
|
||||
testWidgets('displays TypeAheadField widget', (WidgetTester tester) async {
|
||||
const sheet = UserRegistrationSheet(
|
||||
firstName: 'John',
|
||||
lastName: 'Doe',
|
||||
email: 'john@example.com',
|
||||
password: 'password123',
|
||||
passwordConfirmation: 'password123',
|
||||
birthdate: '1990-01-01',
|
||||
gender: 'male',
|
||||
location: '',
|
||||
responseBody: '{}',
|
||||
lang: 'ru',
|
||||
weight: 75,
|
||||
height: 180,
|
||||
phone: '+1234567890',
|
||||
chestCircumference: 100,
|
||||
waistCircumference: 80,
|
||||
hipCircumference: 90,
|
||||
bloodPressureUp: 120,
|
||||
bloodPressureDown: 80,
|
||||
hasHypo: 0,
|
||||
hasHyper: 0,
|
||||
aboutAllergy: 'None',
|
||||
aboutTakingPils: 'None',
|
||||
aboutSportHobbies: 'Running',
|
||||
favoriteFoods: 'Pizza',
|
||||
unfavoriteFoods: 'Broccoli',
|
||||
additionalInfo: 'No additional info',
|
||||
);
|
||||
|
||||
await tester.pumpWidget(createTestWidget(sheet));
|
||||
await tester.pump(); // Use pump instead of pumpAndSettle to avoid timeout
|
||||
|
||||
final textField = find.byType(TextFormField);
|
||||
expect(textField, findsOneWidget);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -0,0 +1,100 @@
|
||||
import 'package:eatvio_app/core/theme/theme_helper.dart';
|
||||
import 'package:eatvio_app/features/settings/entities/settings_entity.dart';
|
||||
import 'package:eatvio_app/features/settings/presentation/bloc/settings_cubit/settings_cubit.dart';
|
||||
import 'package:eatvio_app/features/settings/presentation/bloc/settings_cubit/settings_state.dart';
|
||||
import 'package:eatvio_app/features/settings/presentation/pages/other_info_screen.dart';
|
||||
import 'package:eatvio_app/generated/l10n.dart';
|
||||
import 'package:flutter/material.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 '../../../../fixtures/settings_fixtures.dart';
|
||||
import 'other_info_screen_test.mocks.dart';
|
||||
|
||||
@GenerateMocks([SettingsCubit])
|
||||
void main() {
|
||||
group('OtherInfoScreen', () {
|
||||
late MockSettingsCubit mockSettingsCubit;
|
||||
late SettingsEntity settingsEntity;
|
||||
|
||||
setUp(() {
|
||||
mockSettingsCubit = MockSettingsCubit();
|
||||
final profileDetails = SettingsFixtures.profileDetailsModel();
|
||||
final profileSettings = SettingsFixtures.profileSettingsModel();
|
||||
|
||||
when(mockSettingsCubit.state).thenReturn(
|
||||
SettingsStateLoaded(
|
||||
profile: SettingsFixtures.profileModel(),
|
||||
profileSettings: profileSettings,
|
||||
profileDetails: profileDetails,
|
||||
hasActiveConsultation: false,
|
||||
),
|
||||
);
|
||||
|
||||
settingsEntity = SettingsEntity(
|
||||
profileSettingsModel: profileSettings,
|
||||
profileDetailsModel: profileDetails,
|
||||
settingsCubit: mockSettingsCubit,
|
||||
);
|
||||
});
|
||||
|
||||
Widget createTestWidget() {
|
||||
final router = GoRouter(
|
||||
initialLocation: '/',
|
||||
routes: [
|
||||
GoRoute(
|
||||
path: '/',
|
||||
builder: (context, state) => OtherInfoScreen(settingsEntity: settingsEntity),
|
||||
),
|
||||
],
|
||||
);
|
||||
|
||||
return MaterialApp.router(
|
||||
theme: ThemeHelper().themeData(),
|
||||
routerConfig: router,
|
||||
localizationsDelegates: const [
|
||||
S.delegate,
|
||||
GlobalMaterialLocalizations.delegate,
|
||||
GlobalWidgetsLocalizations.delegate,
|
||||
GlobalCupertinoLocalizations.delegate,
|
||||
],
|
||||
supportedLocales: const [Locale('ru')],
|
||||
);
|
||||
}
|
||||
|
||||
testWidgets('displays screen with correct title', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(createTestWidget());
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('Прочая информаиця'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('displays all input fields', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(createTestWidget());
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// Check for input fields
|
||||
expect(find.byType(TextFormField), findsWidgets);
|
||||
});
|
||||
|
||||
testWidgets('displays save button', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(createTestWidget());
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('Сохранить'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('initializes with existing values', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(createTestWidget());
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// The controllers should be initialized with existing values
|
||||
final textFields = find.byType(TextFormField);
|
||||
expect(textFields, findsWidgets);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -0,0 +1,111 @@
|
||||
import 'package:eatvio_app/core/theme/theme_helper.dart';
|
||||
import 'package:eatvio_app/features/settings/entities/settings_entity.dart';
|
||||
import 'package:eatvio_app/features/settings/presentation/bloc/settings_cubit/settings_cubit.dart';
|
||||
import 'package:eatvio_app/features/settings/presentation/bloc/settings_cubit/settings_state.dart';
|
||||
import 'package:eatvio_app/features/settings/presentation/pages/physical_form_screen.dart';
|
||||
import 'package:eatvio_app/generated/l10n.dart';
|
||||
import 'package:flutter/material.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 '../../../../fixtures/settings_fixtures.dart';
|
||||
import 'physical_form_screen_test.mocks.dart';
|
||||
|
||||
@GenerateMocks([SettingsCubit])
|
||||
void main() {
|
||||
group('PhysicalFormScreen', () {
|
||||
late MockSettingsCubit mockSettingsCubit;
|
||||
late SettingsEntity settingsEntity;
|
||||
|
||||
setUp(() {
|
||||
mockSettingsCubit = MockSettingsCubit();
|
||||
final profileDetails = SettingsFixtures.profileDetailsModel();
|
||||
final profileSettings = SettingsFixtures.profileSettingsModel();
|
||||
|
||||
when(mockSettingsCubit.state).thenReturn(
|
||||
SettingsStateLoaded(
|
||||
profile: SettingsFixtures.profileModel(),
|
||||
profileSettings: profileSettings,
|
||||
profileDetails: profileDetails,
|
||||
hasActiveConsultation: false,
|
||||
),
|
||||
);
|
||||
|
||||
settingsEntity = SettingsEntity(
|
||||
profileSettingsModel: profileSettings,
|
||||
profileDetailsModel: profileDetails,
|
||||
settingsCubit: mockSettingsCubit,
|
||||
);
|
||||
});
|
||||
|
||||
Widget createTestWidget() {
|
||||
final router = GoRouter(
|
||||
initialLocation: '/',
|
||||
routes: [
|
||||
GoRoute(
|
||||
path: '/',
|
||||
builder: (context, state) => PhysicalFormScreen(settingsEntity: settingsEntity),
|
||||
),
|
||||
],
|
||||
);
|
||||
|
||||
return MaterialApp.router(
|
||||
theme: ThemeHelper().themeData(),
|
||||
routerConfig: router,
|
||||
localizationsDelegates: const [
|
||||
S.delegate,
|
||||
GlobalMaterialLocalizations.delegate,
|
||||
GlobalWidgetsLocalizations.delegate,
|
||||
GlobalCupertinoLocalizations.delegate,
|
||||
],
|
||||
supportedLocales: const [Locale('ru')],
|
||||
);
|
||||
}
|
||||
|
||||
testWidgets('displays screen with correct title', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(createTestWidget());
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('Физическая форма'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('displays all input fields', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(createTestWidget());
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// Check for input fields by hint text
|
||||
expect(find.text('см'), findsWidgets);
|
||||
expect(find.text('кг'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('displays save button', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(createTestWidget());
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('Сохранить'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('initializes with existing values', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(createTestWidget());
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// The controllers should be initialized with existing values
|
||||
// We can verify this by checking that the fields are not empty
|
||||
final chestField = find.byType(TextFormField).first;
|
||||
expect(chestField, findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('displays save button', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(createTestWidget());
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// Verify save button is displayed
|
||||
expect(find.text('Сохранить'), findsOneWidget);
|
||||
// Note: Testing button tap requires proper navigation setup
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -0,0 +1,108 @@
|
||||
import 'package:eatvio_app/core/theme/theme_helper.dart';
|
||||
import 'package:eatvio_app/features/settings/entities/settings_entity.dart';
|
||||
import 'package:eatvio_app/features/settings/presentation/bloc/settings_cubit/settings_cubit.dart';
|
||||
import 'package:eatvio_app/features/settings/presentation/bloc/settings_cubit/settings_state.dart';
|
||||
import 'package:eatvio_app/features/settings/presentation/pages/pressure_screen.dart';
|
||||
import 'package:eatvio_app/generated/l10n.dart';
|
||||
import 'package:flutter/material.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 '../../../../fixtures/settings_fixtures.dart';
|
||||
import 'pressure_screen_test.mocks.dart';
|
||||
|
||||
@GenerateMocks([SettingsCubit])
|
||||
void main() {
|
||||
group('PressureScreen', () {
|
||||
late MockSettingsCubit mockSettingsCubit;
|
||||
late SettingsEntity settingsEntity;
|
||||
|
||||
setUp(() {
|
||||
mockSettingsCubit = MockSettingsCubit();
|
||||
final profileDetails = SettingsFixtures.profileDetailsModel();
|
||||
final profileSettings = SettingsFixtures.profileSettingsModel();
|
||||
|
||||
when(mockSettingsCubit.state).thenReturn(
|
||||
SettingsStateLoaded(
|
||||
profile: SettingsFixtures.profileModel(),
|
||||
profileSettings: profileSettings,
|
||||
profileDetails: profileDetails,
|
||||
hasActiveConsultation: false,
|
||||
),
|
||||
);
|
||||
|
||||
settingsEntity = SettingsEntity(
|
||||
profileSettingsModel: profileSettings,
|
||||
profileDetailsModel: profileDetails,
|
||||
settingsCubit: mockSettingsCubit,
|
||||
);
|
||||
});
|
||||
|
||||
Widget createTestWidget() {
|
||||
final router = GoRouter(
|
||||
initialLocation: '/',
|
||||
routes: [
|
||||
GoRoute(
|
||||
path: '/',
|
||||
builder: (context, state) => PressureScreen(settingsEntity: settingsEntity),
|
||||
),
|
||||
],
|
||||
);
|
||||
|
||||
return MaterialApp.router(
|
||||
theme: ThemeHelper().themeData(),
|
||||
routerConfig: router,
|
||||
localizationsDelegates: const [
|
||||
S.delegate,
|
||||
GlobalMaterialLocalizations.delegate,
|
||||
GlobalWidgetsLocalizations.delegate,
|
||||
GlobalCupertinoLocalizations.delegate,
|
||||
],
|
||||
supportedLocales: const [Locale('ru')],
|
||||
);
|
||||
}
|
||||
|
||||
testWidgets('displays screen with correct title', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(createTestWidget());
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('Давление'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('displays input fields for pressure', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(createTestWidget());
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// Check for input fields by hint text
|
||||
expect(find.text('90'), findsWidgets);
|
||||
});
|
||||
|
||||
testWidgets('displays form fields', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(createTestWidget());
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// Check that screen displays correctly with input fields
|
||||
expect(find.byType(TextFormField), findsWidgets);
|
||||
});
|
||||
|
||||
testWidgets('displays save button', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(createTestWidget());
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('Сохранить'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('displays save button', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(createTestWidget());
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// Verify save button is displayed
|
||||
expect(find.text('Сохранить'), findsOneWidget);
|
||||
// Note: Testing button tap requires proper navigation setup
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
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/support/presentation/pages/support_screen.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';
|
||||
|
||||
void main() {
|
||||
group('SupportScreen', () {
|
||||
setUp(() async {
|
||||
await sl.reset();
|
||||
dotenv.loadFromString(envString: 'DEV_BASE_URL=http://localhost\nBASE_URL=http://localhost');
|
||||
sl.registerLazySingleton<AppConfig>(() => AppConfig(buildType: AppBuildType.tests)..setBaseUrl('http://localhost'));
|
||||
});
|
||||
|
||||
Widget createTestWidget() {
|
||||
return MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
localizationsDelegates: const [
|
||||
S.delegate,
|
||||
GlobalMaterialLocalizations.delegate,
|
||||
GlobalWidgetsLocalizations.delegate,
|
||||
GlobalCupertinoLocalizations.delegate,
|
||||
],
|
||||
supportedLocales: const [Locale('ru')],
|
||||
home: const SupportScreen(),
|
||||
);
|
||||
}
|
||||
|
||||
testWidgets('displays screen with correct title', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(createTestWidget());
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('Поддержка'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('displays support information', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(createTestWidget());
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// Check for support text
|
||||
expect(find.textContaining('Если у вас есть вопросы'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('displays legal documents section', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(createTestWidget());
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('Правовые документы'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('displays privacy policy link', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(createTestWidget());
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('Политика конфиденциальности'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('displays company details link', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(createTestWidget());
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('О компании'), findsOneWidget);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user