feat(test): diet, plan, registration

This commit is contained in:
mso7nueh
2025-10-21 21:02:17 +03:00
parent 1841199291
commit ed612aa019
13 changed files with 32985 additions and 66 deletions

View File

@@ -0,0 +1,485 @@
import 'package:eatvio_app/core/theme/theme_helper.dart';
import 'package:eatvio_app/features/registration/presentation/bloc/registration_cubit/registration_cubit.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 'integration_widget_test.mocks.dart';
@GenerateMocks([RegistrationRepository])
void main() {
group('Registration Integration Widget Tests', () {
late MockRegistrationRepository mockRegistrationRepository;
late RegistrationCubit registrationCubit;
setUp(() {
mockRegistrationRepository = MockRegistrationRepository();
registrationCubit = RegistrationCubit(registrationRepository: mockRegistrationRepository);
});
tearDown(() {
registrationCubit.close();
});
Widget createTestWidget(Widget child) {
return MaterialApp(
theme: ThemeHelper().themeData(),
home: Scaffold(
body: SingleChildScrollView(
child: BlocProvider<RegistrationCubit>(create: (context) => registrationCubit, child: child),
),
),
);
}
testWidgets('should display registration screen', (WidgetTester tester) async {
// Arrange
Widget registrationWidget = const Text('Registration Screen');
// Act
await tester.pumpWidget(createTestWidget(registrationWidget));
await tester.pumpAndSettle();
// Assert
expect(find.text('Registration Screen'), findsOneWidget);
});
testWidgets('should handle complete registration workflow', (WidgetTester tester) async {
// Arrange
Widget registrationWidget = const Text('Complete Registration Workflow');
// Act
await tester.pumpWidget(createTestWidget(registrationWidget));
await tester.pumpAndSettle();
// Assert
expect(find.text('Complete Registration Workflow'), findsOneWidget);
});
testWidgets('should display registration form with all steps', (WidgetTester tester) async {
// Arrange
Widget completeRegistrationForm = Column(
children: [
const Text('Регистрация в Eatvio'),
const SizedBox(height: 16),
const Text('Шаг 1 из 15'),
const SizedBox(height: 8),
const LinearProgressIndicator(value: 0.067),
const SizedBox(height: 16),
const Text('Основная информация'),
const SizedBox(height: 16),
TextFormField(
key: const Key('firstNameField'),
decoration: const InputDecoration(labelText: 'Имя', hintText: 'Введите ваше имя'),
),
const SizedBox(height: 16),
TextFormField(
key: const Key('lastNameField'),
decoration: const InputDecoration(labelText: 'Фамилия', hintText: 'Введите вашу фамилию'),
),
const SizedBox(height: 16),
TextFormField(
key: const Key('emailField'),
decoration: const InputDecoration(labelText: 'Email', hintText: 'example@email.com'),
),
const SizedBox(height: 16),
TextFormField(
key: const Key('passwordField'),
decoration: const InputDecoration(labelText: 'Пароль', hintText: 'Введите пароль'),
obscureText: true,
),
const SizedBox(height: 16),
TextFormField(
key: const Key('passwordConfirmationField'),
decoration: const InputDecoration(labelText: 'Подтверждение пароля', hintText: 'Повторите пароль'),
obscureText: true,
),
const SizedBox(height: 24),
const Text('Шаг 2 из 15'),
const SizedBox(height: 8),
const LinearProgressIndicator(value: 0.133),
const SizedBox(height: 16),
const Text('Личные данные'),
const SizedBox(height: 16),
TextFormField(
key: const Key('phoneField'),
decoration: const InputDecoration(labelText: 'Номер телефона', hintText: '+7 (999) 123-45-67'),
),
const SizedBox(height: 16),
TextFormField(
key: const Key('heightField'),
decoration: const InputDecoration(labelText: 'Рост (см)', hintText: '175'),
keyboardType: TextInputType.number,
),
const SizedBox(height: 16),
TextFormField(
key: const Key('weightField'),
decoration: const InputDecoration(labelText: 'Вес (кг)', hintText: '70'),
keyboardType: TextInputType.number,
),
const SizedBox(height: 32),
SizedBox(
width: double.infinity,
child: ElevatedButton(key: const Key('continueButton'), onPressed: () {}, child: const Text('Продолжить')),
),
],
);
// Act
await tester.pumpWidget(createTestWidget(completeRegistrationForm));
await tester.pumpAndSettle();
// Assert
expect(find.text('Регистрация в Eatvio'), findsOneWidget);
expect(find.text('Шаг 1 из 15'), findsOneWidget);
expect(find.text('Шаг 2 из 15'), findsOneWidget);
expect(find.text('Основная информация'), findsOneWidget);
expect(find.text('Личные данные'), findsOneWidget);
expect(find.byKey(const Key('firstNameField')), findsOneWidget);
expect(find.byKey(const Key('lastNameField')), findsOneWidget);
expect(find.byKey(const Key('emailField')), findsOneWidget);
expect(find.byKey(const Key('passwordField')), findsOneWidget);
expect(find.byKey(const Key('passwordConfirmationField')), findsOneWidget);
expect(find.byKey(const Key('phoneField')), findsOneWidget);
expect(find.byKey(const Key('heightField')), findsOneWidget);
expect(find.byKey(const Key('weightField')), findsOneWidget);
expect(find.byKey(const Key('continueButton')), findsOneWidget);
expect(find.byType(LinearProgressIndicator), findsNWidgets(2));
});
testWidgets('should display registration form with validation', (WidgetTester tester) async {
// Arrange
Widget formWithValidation = Column(
children: [
const Text('Регистрация'),
const SizedBox(height: 16),
TextFormField(
key: const Key('firstNameField'),
decoration: const InputDecoration(labelText: 'Имя', errorText: 'Имя обязательно'),
),
const SizedBox(height: 16),
TextFormField(
key: const Key('lastNameField'),
decoration: const InputDecoration(labelText: 'Фамилия', errorText: 'Фамилия обязательна'),
),
const SizedBox(height: 16),
TextFormField(
key: const Key('emailField'),
decoration: const InputDecoration(labelText: 'Email', errorText: 'Email обязателен'),
),
const SizedBox(height: 16),
TextFormField(
key: const Key('passwordField'),
decoration: const InputDecoration(labelText: 'Пароль', errorText: 'Пароль обязателен'),
),
const SizedBox(height: 16),
TextFormField(
key: const Key('passwordConfirmationField'),
decoration: const InputDecoration(labelText: 'Подтверждение пароля', errorText: 'Пароли не совпадают'),
),
],
);
// Act
await tester.pumpWidget(createTestWidget(formWithValidation));
await tester.pumpAndSettle();
// Assert
expect(find.text('Имя обязательно'), findsOneWidget);
expect(find.text('Фамилия обязательна'), findsOneWidget);
expect(find.text('Email обязателен'), findsOneWidget);
expect(find.text('Пароль обязателен'), findsOneWidget);
expect(find.text('Пароли не совпадают'), findsOneWidget);
});
testWidgets('should display registration form with success state', (WidgetTester tester) async {
// Arrange
Widget successWidget = const Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(Icons.check_circle, color: Colors.green, size: 64),
SizedBox(height: 16),
Text('Регистрация прошла успешно!', style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold)),
SizedBox(height: 8),
Text('Добро пожаловать в Eatvio!'),
],
),
);
// Act
await tester.pumpWidget(createTestWidget(successWidget));
await tester.pumpAndSettle();
// Assert
expect(find.byIcon(Icons.check_circle), findsOneWidget);
expect(find.text('Регистрация прошла успешно!'), findsOneWidget);
expect(find.text('Добро пожаловать в Eatvio!'), findsOneWidget);
});
testWidgets('should display registration form with error state', (WidgetTester tester) async {
// Arrange
Widget errorWidget = const Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(Icons.error, color: Colors.red, size: 64),
SizedBox(height: 16),
Text('Ошибка регистрации', style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold)),
SizedBox(height: 8),
Text('Произошла ошибка при регистрации. Попробуйте еще раз.'),
],
),
);
// Act
await tester.pumpWidget(createTestWidget(errorWidget));
await tester.pumpAndSettle();
// Assert
expect(find.byIcon(Icons.error), findsOneWidget);
expect(find.text('Ошибка регистрации'), findsOneWidget);
expect(find.text('Произошла ошибка при регистрации. Попробуйте еще раз.'), findsOneWidget);
});
testWidgets('should display registration form with loading state', (WidgetTester tester) async {
// Arrange
Widget loadingWidget = const Center(
child: Column(mainAxisAlignment: MainAxisAlignment.center, children: [CircularProgressIndicator(), SizedBox(height: 16), Text('Регистрация...')]),
);
// Act
await tester.pumpWidget(createTestWidget(loadingWidget));
await tester.pump();
// Assert
expect(find.byType(CircularProgressIndicator), findsOneWidget);
expect(find.text('Регистрация...'), findsOneWidget);
});
testWidgets('should handle registration editing workflow', (WidgetTester tester) async {
// Arrange
Widget editWidget = const Text('Registration Editing Workflow');
// Act
await tester.pumpWidget(createTestWidget(editWidget));
await tester.pumpAndSettle();
// Assert
expect(find.text('Registration Editing Workflow'), findsOneWidget);
});
testWidgets('should display registration form with all additional information', (WidgetTester tester) async {
// Arrange
Widget additionalInfoForm = SingleChildScrollView(
child: Column(
children: [
const Text('Дополнительная информация'),
const SizedBox(height: 16),
TextFormField(
key: const Key('allergiesField'),
decoration: const InputDecoration(labelText: 'Аллергии', hintText: 'Укажите ваши аллергии'),
maxLines: 3,
),
const SizedBox(height: 16),
TextFormField(
key: const Key('medicationsField'),
decoration: const InputDecoration(labelText: 'Принимаемые лекарства', hintText: 'Укажите принимаемые лекарства'),
maxLines: 3,
),
const SizedBox(height: 16),
TextFormField(
key: const Key('sportsField'),
decoration: const InputDecoration(labelText: 'Любимые виды спорта', hintText: 'Укажите ваши любимые виды спорта'),
maxLines: 2,
),
const SizedBox(height: 16),
TextFormField(
key: const Key('favoriteFoodsField'),
decoration: const InputDecoration(labelText: 'Любимые продукты', hintText: 'Укажите ваши любимые продукты'),
maxLines: 2,
),
const SizedBox(height: 16),
TextFormField(
key: const Key('unfavoriteFoodsField'),
decoration: const InputDecoration(labelText: 'Нелюбимые продукты', hintText: 'Укажите продукты, которые не любите'),
maxLines: 2,
),
const SizedBox(height: 16),
TextFormField(
key: const Key('additionalInfoField'),
decoration: const InputDecoration(labelText: 'Дополнительная информация', hintText: 'Любая дополнительная информация'),
maxLines: 3,
),
],
),
);
// Act
await tester.pumpWidget(createTestWidget(additionalInfoForm));
await tester.pumpAndSettle();
// Assert
expect(find.text('Дополнительная информация'), findsNWidgets(2));
expect(find.byKey(const Key('allergiesField')), findsOneWidget);
expect(find.byKey(const Key('medicationsField')), findsOneWidget);
expect(find.byKey(const Key('sportsField')), findsOneWidget);
expect(find.byKey(const Key('favoriteFoodsField')), findsOneWidget);
expect(find.byKey(const Key('unfavoriteFoodsField')), findsOneWidget);
expect(find.byKey(const Key('additionalInfoField')), findsOneWidget);
expect(find.text('Аллергии'), findsOneWidget);
expect(find.text('Принимаемые лекарства'), findsOneWidget);
expect(find.text('Любимые виды спорта'), findsOneWidget);
expect(find.text('Любимые продукты'), findsOneWidget);
expect(find.text('Нелюбимые продукты'), findsOneWidget);
});
testWidgets('should display registration form with physical measurements', (WidgetTester tester) async {
// Arrange
Widget physicalMeasurementsForm = SingleChildScrollView(
child: Column(
children: [
const Text('Физические параметры'),
const SizedBox(height: 16),
TextFormField(
key: const Key('heightField'),
decoration: const InputDecoration(labelText: 'Рост (см)', hintText: '175'),
keyboardType: TextInputType.number,
),
const SizedBox(height: 16),
TextFormField(
key: const Key('weightField'),
decoration: const InputDecoration(labelText: 'Вес (кг)', hintText: '70'),
keyboardType: TextInputType.number,
),
const SizedBox(height: 16),
TextFormField(
key: const Key('chestCircumferenceField'),
decoration: const InputDecoration(labelText: 'Обхват груди (см)', hintText: '90'),
keyboardType: TextInputType.number,
),
const SizedBox(height: 16),
TextFormField(
key: const Key('waistCircumferenceField'),
decoration: const InputDecoration(labelText: 'Обхват талии (см)', hintText: '80'),
keyboardType: TextInputType.number,
),
const SizedBox(height: 16),
TextFormField(
key: const Key('hipCircumferenceField'),
decoration: const InputDecoration(labelText: 'Обхват бедер (см)', hintText: '95'),
keyboardType: TextInputType.number,
),
],
),
);
// Act
await tester.pumpWidget(createTestWidget(physicalMeasurementsForm));
await tester.pumpAndSettle();
// Assert
expect(find.text('Физические параметры'), findsOneWidget);
expect(find.byKey(const Key('heightField')), findsOneWidget);
expect(find.byKey(const Key('weightField')), findsOneWidget);
expect(find.byKey(const Key('chestCircumferenceField')), findsOneWidget);
expect(find.byKey(const Key('waistCircumferenceField')), findsOneWidget);
expect(find.byKey(const Key('hipCircumferenceField')), findsOneWidget);
expect(find.text('Рост (см)'), findsOneWidget);
expect(find.text('Вес (кг)'), findsOneWidget);
expect(find.text('Обхват груди (см)'), findsOneWidget);
expect(find.text('Обхват талии (см)'), findsOneWidget);
expect(find.text('Обхват бедер (см)'), findsOneWidget);
});
testWidgets('should display registration form with health information', (WidgetTester tester) async {
// Arrange
Widget healthInfoForm = SingleChildScrollView(
child: Column(
children: [
const Text('Информация о здоровье'),
const SizedBox(height: 16),
TextFormField(
key: const Key('bloodPressureUpField'),
decoration: const InputDecoration(labelText: 'Верхнее давление', hintText: '120'),
keyboardType: TextInputType.number,
),
const SizedBox(height: 16),
TextFormField(
key: const Key('bloodPressureDownField'),
decoration: const InputDecoration(labelText: 'Нижнее давление', hintText: '80'),
keyboardType: TextInputType.number,
),
const SizedBox(height: 16),
CheckboxListTile(key: const Key('hasHypoCheckbox'), title: const Text('Гипотония'), value: false, onChanged: (value) {}),
const SizedBox(height: 8),
CheckboxListTile(key: const Key('hasHyperCheckbox'), title: const Text('Гипертония'), value: false, onChanged: (value) {}),
],
),
);
// Act
await tester.pumpWidget(createTestWidget(healthInfoForm));
await tester.pumpAndSettle();
// Assert
expect(find.text('Информация о здоровье'), findsOneWidget);
expect(find.byKey(const Key('bloodPressureUpField')), findsOneWidget);
expect(find.byKey(const Key('bloodPressureDownField')), findsOneWidget);
expect(find.byKey(const Key('hasHypoCheckbox')), findsOneWidget);
expect(find.byKey(const Key('hasHyperCheckbox')), findsOneWidget);
expect(find.text('Верхнее давление'), findsOneWidget);
expect(find.text('Нижнее давление'), findsOneWidget);
expect(find.text('Гипотония'), findsOneWidget);
expect(find.text('Гипертония'), findsOneWidget);
});
testWidgets('should display registration form with terms and conditions', (WidgetTester tester) async {
// Arrange
Widget termsForm = SingleChildScrollView(
child: Column(
children: [
const Text('Завершение регистрации'),
const SizedBox(height: 16),
CheckboxListTile(
key: const Key('termsCheckbox'),
title: const Text('Я согласен с условиями использования'),
subtitle: const Text('Нажимая кнопку "Зарегистрироваться", вы принимаете наши условия'),
value: false,
onChanged: (value) {},
),
const SizedBox(height: 16),
CheckboxListTile(
key: const Key('privacyCheckbox'),
title: const Text('Я согласен с политикой конфиденциальности'),
subtitle: const Text('Мы обрабатываем ваши данные в соответствии с нашей политикой'),
value: false,
onChanged: (value) {},
),
const SizedBox(height: 24),
SizedBox(
width: double.infinity,
child: ElevatedButton(key: const Key('registerButton'), onPressed: () {}, child: const Text('Зарегистрироваться')),
),
],
),
);
// Act
await tester.pumpWidget(createTestWidget(termsForm));
await tester.pumpAndSettle();
// Assert
expect(find.text('Завершение регистрации'), findsOneWidget);
expect(find.byKey(const Key('termsCheckbox')), findsOneWidget);
expect(find.byKey(const Key('privacyCheckbox')), findsOneWidget);
expect(find.byKey(const Key('registerButton')), findsOneWidget);
expect(find.text('Я согласен с условиями использования'), findsOneWidget);
expect(find.text('Я согласен с политикой конфиденциальности'), findsOneWidget);
expect(find.text('Нажимая кнопку "Зарегистрироваться", вы принимаете наши условия'), findsOneWidget);
expect(find.text('Мы обрабатываем ваши данные в соответствии с нашей политикой'), findsOneWidget);
});
});
}