forked from eatvio/eatvio_app
chore(dependencies): add webview_flutter_platform_interface package to pubspec.yaml and clean up test files by removing unnecessary whitespace
This commit is contained in:
@@ -0,0 +1,245 @@
|
||||
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/additional_information_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 'additional_information_screen_test.mocks.dart';
|
||||
|
||||
@GenerateMocks([RegistrationRepository, Prefs])
|
||||
void main() {
|
||||
group('AdditionalInformationScreen', () {
|
||||
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(),
|
||||
home: Scaffold(
|
||||
body: BlocProvider<RegistrationCubit>(
|
||||
create: (context) => registrationCubit,
|
||||
child: AdditionalInformationScreen(sheet: sheet),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
testWidgets('displays screen with initial text 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: 'I am a vegetarian',
|
||||
);
|
||||
|
||||
await tester.pumpWidget(createTestWidget(sheet));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('I am a vegetarian'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('displays label 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: '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: '',
|
||||
);
|
||||
|
||||
await tester.pumpWidget(createTestWidget(sheet));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// Check that the label contains "Дополнительная информация"
|
||||
expect(find.textContaining('Дополнительная информация'), findsOneWidget);
|
||||
expect(find.textContaining('не обязательно'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('updates registration cubit when text 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: 'Initial info',
|
||||
);
|
||||
|
||||
await tester.pumpWidget(createTestWidget(sheet));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
final textField = find.byType(TextField);
|
||||
expect(textField, findsOneWidget);
|
||||
|
||||
await tester.enterText(textField, 'Updated information');
|
||||
await tester.pump();
|
||||
|
||||
// Verify that the cubit state was updated
|
||||
expect(registrationCubit.state.sheet.additionalInfo, 'Updated information');
|
||||
});
|
||||
|
||||
testWidgets('limits text input to 250 characters', (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: '',
|
||||
);
|
||||
|
||||
await tester.pumpWidget(createTestWidget(sheet));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
final textField = find.byType(TextField);
|
||||
expect(textField, findsOneWidget);
|
||||
|
||||
// Try to enter more than 250 characters
|
||||
final longText = 'a' * 300;
|
||||
await tester.enterText(textField, longText);
|
||||
await tester.pump();
|
||||
|
||||
// The text should be limited to 250 characters
|
||||
final textFieldWidget = tester.widget<TextField>(textField);
|
||||
expect(textFieldWidget.controller?.text.length, lessThanOrEqualTo(250));
|
||||
});
|
||||
|
||||
testWidgets('displays empty text field when sheet has empty additionalInfo', (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: '',
|
||||
);
|
||||
|
||||
await tester.pumpWidget(createTestWidget(sheet));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
final textField = find.byType(TextField);
|
||||
expect(textField, findsOneWidget);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -0,0 +1,207 @@
|
||||
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/allergies_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 'allergies_screen_test.mocks.dart';
|
||||
|
||||
@GenerateMocks([RegistrationRepository, Prefs])
|
||||
void main() {
|
||||
group('AllergiesScreen', () {
|
||||
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: AllergiesScreen(sheet: sheet),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
testWidgets('displays screen with initial allergy information 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: 'Nuts, honey',
|
||||
aboutTakingPils: 'None',
|
||||
aboutSportHobbies: 'Running',
|
||||
favoriteFoods: 'Pizza',
|
||||
unfavoriteFoods: 'Broccoli',
|
||||
additionalInfo: 'No additional info',
|
||||
);
|
||||
|
||||
await tester.pumpWidget(createTestWidget(sheet));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('Nuts, honey'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('displays empty field when allergy information 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: '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: '',
|
||||
aboutTakingPils: 'None',
|
||||
aboutSportHobbies: 'Running',
|
||||
favoriteFoods: 'Pizza',
|
||||
unfavoriteFoods: 'Broccoli',
|
||||
additionalInfo: 'No additional info',
|
||||
);
|
||||
|
||||
await tester.pumpWidget(createTestWidget(sheet));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
final textFields = find.byType(TextField);
|
||||
expect(textFields, 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: '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: '',
|
||||
aboutTakingPils: 'None',
|
||||
aboutSportHobbies: 'Running',
|
||||
favoriteFoods: 'Pizza',
|
||||
unfavoriteFoods: 'Broccoli',
|
||||
additionalInfo: 'No additional info',
|
||||
);
|
||||
|
||||
await tester.pumpWidget(createTestWidget(sheet));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('Например: орехи, мёд и т.д.'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('updates registration cubit when allergy information 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: '',
|
||||
aboutTakingPils: 'None',
|
||||
aboutSportHobbies: 'Running',
|
||||
favoriteFoods: 'Pizza',
|
||||
unfavoriteFoods: 'Broccoli',
|
||||
additionalInfo: 'No additional info',
|
||||
);
|
||||
|
||||
await tester.pumpWidget(createTestWidget(sheet));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
final textFields = find.byType(TextField);
|
||||
expect(textFields, findsOneWidget);
|
||||
|
||||
// Enter allergy information
|
||||
await tester.enterText(textFields.first, 'Peanuts, shellfish');
|
||||
await tester.pump();
|
||||
|
||||
// Verify that the cubit state was updated
|
||||
expect(registrationCubit.state.sheet.aboutAllergy, 'Peanuts, shellfish');
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -0,0 +1,216 @@
|
||||
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/favorite_foods_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 'favorite_foods_screen_test.mocks.dart';
|
||||
|
||||
@GenerateMocks([RegistrationRepository, Prefs])
|
||||
void main() {
|
||||
group('FavoriteFoodsScreen', () {
|
||||
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: FavoriteFoodsScreen(sheet: sheet),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
testWidgets('displays screen with initial favorite and unfavorite foods 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, pasta',
|
||||
unfavoriteFoods: 'Broccoli, spinach',
|
||||
additionalInfo: 'No additional info',
|
||||
);
|
||||
|
||||
await tester.pumpWidget(createTestWidget(sheet));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('Pizza, pasta'), findsOneWidget);
|
||||
expect(find.text('Broccoli, spinach'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('displays empty fields when foods are 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: '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: '',
|
||||
unfavoriteFoods: '',
|
||||
additionalInfo: 'No additional info',
|
||||
);
|
||||
|
||||
await tester.pumpWidget(createTestWidget(sheet));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
final textFields = find.byType(TextField);
|
||||
expect(textFields, findsNWidgets(2));
|
||||
});
|
||||
|
||||
testWidgets('updates registration cubit when favorite foods change', (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: '',
|
||||
unfavoriteFoods: '',
|
||||
additionalInfo: 'No additional info',
|
||||
);
|
||||
|
||||
await tester.pumpWidget(createTestWidget(sheet));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
final textFields = find.byType(TextField);
|
||||
expect(textFields, findsNWidgets(2));
|
||||
|
||||
// Enter favorite foods
|
||||
await tester.enterText(textFields.first, 'Sushi, ramen');
|
||||
await tester.pump();
|
||||
|
||||
// Verify that the cubit state was updated
|
||||
expect(registrationCubit.state.sheet.favoriteFoods, 'Sushi, ramen');
|
||||
});
|
||||
|
||||
testWidgets('updates registration cubit when unfavorite foods change', (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: '',
|
||||
unfavoriteFoods: '',
|
||||
additionalInfo: 'No additional info',
|
||||
);
|
||||
|
||||
await tester.pumpWidget(createTestWidget(sheet));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
final textFields = find.byType(TextField);
|
||||
expect(textFields, findsNWidgets(2));
|
||||
|
||||
// Enter unfavorite foods
|
||||
await tester.enterText(textFields.last, 'Mushrooms, olives');
|
||||
await tester.pump();
|
||||
|
||||
// Verify that the cubit state was updated
|
||||
expect(registrationCubit.state.sheet.unfavoriteFoods, 'Mushrooms, olives');
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -0,0 +1,207 @@
|
||||
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/favorite_sports_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 'favorite_sports_screen_test.mocks.dart';
|
||||
|
||||
@GenerateMocks([RegistrationRepository, Prefs])
|
||||
void main() {
|
||||
group('FavoriteSportsScreen', () {
|
||||
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: FavoriteSportsScreen(sheet: sheet),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
testWidgets('displays screen with initial text 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, Swimming',
|
||||
favoriteFoods: 'Pizza',
|
||||
unfavoriteFoods: 'Broccoli',
|
||||
additionalInfo: 'No additional info',
|
||||
);
|
||||
|
||||
await tester.pumpWidget(createTestWidget(sheet));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('Running, Swimming'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('displays label 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: '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: '',
|
||||
favoriteFoods: 'Pizza',
|
||||
unfavoriteFoods: 'Broccoli',
|
||||
additionalInfo: 'No additional info',
|
||||
);
|
||||
|
||||
await tester.pumpWidget(createTestWidget(sheet));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// Check that the label contains "не обязательно"
|
||||
expect(find.textContaining('не обязательно'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('updates registration cubit when text 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: 'Initial',
|
||||
favoriteFoods: 'Pizza',
|
||||
unfavoriteFoods: 'Broccoli',
|
||||
additionalInfo: 'No additional info',
|
||||
);
|
||||
|
||||
await tester.pumpWidget(createTestWidget(sheet));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
final textField = find.byType(TextField);
|
||||
expect(textField, findsOneWidget);
|
||||
|
||||
await tester.enterText(textField, 'Running, Cycling');
|
||||
await tester.pump();
|
||||
|
||||
// Verify that the cubit state was updated
|
||||
expect(registrationCubit.state.sheet.aboutSportHobbies, 'Running, Cycling');
|
||||
});
|
||||
|
||||
testWidgets('displays empty text field when sheet has empty aboutSportHobbies', (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: '',
|
||||
favoriteFoods: 'Pizza',
|
||||
unfavoriteFoods: 'Broccoli',
|
||||
additionalInfo: 'No additional info',
|
||||
);
|
||||
|
||||
await tester.pumpWidget(createTestWidget(sheet));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
final textField = find.byType(TextField);
|
||||
expect(textField, findsOneWidget);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -0,0 +1,251 @@
|
||||
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/gender_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 'gender_screen_test.mocks.dart';
|
||||
|
||||
@GenerateMocks([RegistrationRepository, Prefs])
|
||||
void main() {
|
||||
group('GenderScreen', () {
|
||||
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(),
|
||||
home: Scaffold(
|
||||
body: BlocProvider<RegistrationCubit>(
|
||||
create: (context) => registrationCubit,
|
||||
child: GenderScreen(sheet: sheet),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
testWidgets('displays screen with initial gender 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();
|
||||
|
||||
expect(find.text('Мужской'), findsOneWidget);
|
||||
expect(find.text('Женский'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('displays female option when gender is female', (WidgetTester tester) async {
|
||||
const sheet = UserRegistrationSheet(
|
||||
firstName: 'Jane',
|
||||
lastName: 'Smith',
|
||||
email: 'jane@example.com',
|
||||
password: 'password123',
|
||||
passwordConfirmation: 'password123',
|
||||
birthdate: '1995-05-15',
|
||||
gender: 'female',
|
||||
location: 'London',
|
||||
responseBody: '{}',
|
||||
lang: 'ru',
|
||||
weight: 60,
|
||||
height: 165,
|
||||
phone: '+9876543210',
|
||||
chestCircumference: 90,
|
||||
waistCircumference: 70,
|
||||
hipCircumference: 85,
|
||||
bloodPressureUp: 110,
|
||||
bloodPressureDown: 70,
|
||||
hasHypo: 0,
|
||||
hasHyper: 0,
|
||||
aboutAllergy: 'None',
|
||||
aboutTakingPils: 'None',
|
||||
aboutSportHobbies: 'Yoga',
|
||||
favoriteFoods: 'Salad',
|
||||
unfavoriteFoods: 'Fast food',
|
||||
additionalInfo: 'No additional info',
|
||||
);
|
||||
|
||||
await tester.pumpWidget(createTestWidget(sheet));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('Женский'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('updates registration cubit when male is selected', (WidgetTester tester) async {
|
||||
const sheet = UserRegistrationSheet(
|
||||
firstName: 'John',
|
||||
lastName: 'Doe',
|
||||
email: 'john@example.com',
|
||||
password: 'password123',
|
||||
passwordConfirmation: 'password123',
|
||||
birthdate: '1990-01-01',
|
||||
gender: '',
|
||||
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();
|
||||
|
||||
// Find the male radio button by its value
|
||||
final maleRadio = find.byWidgetPredicate(
|
||||
(widget) => widget is Radio<String> && widget.value == 'male',
|
||||
);
|
||||
expect(maleRadio, findsOneWidget);
|
||||
|
||||
// Tap on the radio button
|
||||
await tester.tap(maleRadio);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// Verify that the cubit state was updated
|
||||
expect(registrationCubit.state.sheet.gender, 'male');
|
||||
});
|
||||
|
||||
testWidgets('updates registration cubit when female is selected', (WidgetTester tester) async {
|
||||
const sheet = UserRegistrationSheet(
|
||||
firstName: 'Jane',
|
||||
lastName: 'Smith',
|
||||
email: 'jane@example.com',
|
||||
password: 'password123',
|
||||
passwordConfirmation: 'password123',
|
||||
birthdate: '1995-05-15',
|
||||
gender: '',
|
||||
location: 'London',
|
||||
responseBody: '{}',
|
||||
lang: 'ru',
|
||||
weight: 60,
|
||||
height: 165,
|
||||
phone: '+9876543210',
|
||||
chestCircumference: 90,
|
||||
waistCircumference: 70,
|
||||
hipCircumference: 85,
|
||||
bloodPressureUp: 110,
|
||||
bloodPressureDown: 70,
|
||||
hasHypo: 0,
|
||||
hasHyper: 0,
|
||||
aboutAllergy: 'None',
|
||||
aboutTakingPils: 'None',
|
||||
aboutSportHobbies: 'Yoga',
|
||||
favoriteFoods: 'Salad',
|
||||
unfavoriteFoods: 'Fast food',
|
||||
additionalInfo: 'No additional info',
|
||||
);
|
||||
|
||||
await tester.pumpWidget(createTestWidget(sheet));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// Find the female radio button by its value
|
||||
final femaleRadio = find.byWidgetPredicate(
|
||||
(widget) => widget is Radio<String> && widget.value == 'female',
|
||||
);
|
||||
expect(femaleRadio, findsOneWidget);
|
||||
|
||||
// Tap on the radio button
|
||||
await tester.tap(femaleRadio);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// Verify that the cubit state was updated
|
||||
expect(registrationCubit.state.sheet.gender, 'female');
|
||||
});
|
||||
|
||||
testWidgets('displays both gender options', (WidgetTester tester) async {
|
||||
const sheet = UserRegistrationSheet(
|
||||
firstName: 'Test',
|
||||
lastName: 'User',
|
||||
email: 'test@example.com',
|
||||
password: 'password123',
|
||||
passwordConfirmation: 'password123',
|
||||
birthdate: '2000-01-01',
|
||||
gender: '',
|
||||
location: 'Paris',
|
||||
responseBody: '{}',
|
||||
lang: 'ru',
|
||||
weight: 70,
|
||||
height: 170,
|
||||
phone: '+1111111111',
|
||||
chestCircumference: 95,
|
||||
waistCircumference: 75,
|
||||
hipCircumference: 88,
|
||||
bloodPressureUp: 115,
|
||||
bloodPressureDown: 75,
|
||||
hasHypo: 0,
|
||||
hasHyper: 0,
|
||||
aboutAllergy: 'None',
|
||||
aboutTakingPils: 'None',
|
||||
aboutSportHobbies: 'Swimming',
|
||||
favoriteFoods: 'Fish',
|
||||
unfavoriteFoods: 'Meat',
|
||||
additionalInfo: 'No additional info',
|
||||
);
|
||||
|
||||
await tester.pumpWidget(createTestWidget(sheet));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('Мужской'), findsOneWidget);
|
||||
expect(find.text('Женский'), findsOneWidget);
|
||||
expect(find.byType(Radio<String>), findsNWidgets(2));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,251 @@
|
||||
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/height_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 'height_screen_test.mocks.dart';
|
||||
|
||||
@GenerateMocks([RegistrationRepository, Prefs])
|
||||
void main() {
|
||||
group('HeightScreen', () {
|
||||
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: HeightScreen(sheet: sheet),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
testWidgets('displays screen with initial height 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();
|
||||
|
||||
expect(find.text('180'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('displays empty field when height is 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: 0,
|
||||
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 textField = find.byType(TextField);
|
||||
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: 'Moscow',
|
||||
responseBody: '{}',
|
||||
lang: 'ru',
|
||||
weight: 75,
|
||||
height: 0,
|
||||
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();
|
||||
|
||||
expect(find.text('см'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('updates registration cubit when height 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: 170,
|
||||
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 textField = find.byType(TextField);
|
||||
expect(textField, findsOneWidget);
|
||||
|
||||
await tester.enterText(textField, '185');
|
||||
await tester.pump();
|
||||
|
||||
// Verify that the cubit state was updated
|
||||
expect(registrationCubit.state.sheet.height, 185);
|
||||
});
|
||||
|
||||
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: 0,
|
||||
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 textField = find.byType(TextField);
|
||||
expect(textField, findsOneWidget);
|
||||
|
||||
// Try to enter non-digit characters
|
||||
await tester.enterText(textField, 'abc');
|
||||
await tester.pump();
|
||||
|
||||
// The text field should only accept digits
|
||||
final textFieldWidget = tester.widget<TextField>(textField);
|
||||
expect(textFieldWidget.controller?.text, isEmpty);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -0,0 +1,171 @@
|
||||
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/medicine_intake_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 'medicine_intake_screen_test.mocks.dart';
|
||||
|
||||
@GenerateMocks([RegistrationRepository, Prefs])
|
||||
void main() {
|
||||
group('MedicineIntakeScreen', () {
|
||||
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: MedicineIntakeScreen(sheet: sheet),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
testWidgets('displays screen with initial medicine intake information 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: 'Aspirin daily',
|
||||
aboutSportHobbies: 'Running',
|
||||
favoriteFoods: 'Pizza',
|
||||
unfavoriteFoods: 'Broccoli',
|
||||
additionalInfo: 'No additional info',
|
||||
);
|
||||
|
||||
await tester.pumpWidget(createTestWidget(sheet));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('Aspirin daily'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('displays empty field when medicine intake information 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: '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: '',
|
||||
aboutSportHobbies: 'Running',
|
||||
favoriteFoods: 'Pizza',
|
||||
unfavoriteFoods: 'Broccoli',
|
||||
additionalInfo: 'No additional info',
|
||||
);
|
||||
|
||||
await tester.pumpWidget(createTestWidget(sheet));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
final textFields = find.byType(TextField);
|
||||
expect(textFields, findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('updates registration cubit when medicine intake information 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: '',
|
||||
aboutSportHobbies: 'Running',
|
||||
favoriteFoods: 'Pizza',
|
||||
unfavoriteFoods: 'Broccoli',
|
||||
additionalInfo: 'No additional info',
|
||||
);
|
||||
|
||||
await tester.pumpWidget(createTestWidget(sheet));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
final textFields = find.byType(TextField);
|
||||
expect(textFields, findsOneWidget);
|
||||
|
||||
// Enter medicine intake information
|
||||
await tester.enterText(textFields.first, 'Vitamin D, Omega-3');
|
||||
await tester.pump();
|
||||
|
||||
// Verify that the cubit state was updated
|
||||
expect(registrationCubit.state.sheet.aboutTakingPils, 'Vitamin D, Omega-3');
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -0,0 +1,254 @@
|
||||
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/name_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 'name_screen_test.mocks.dart';
|
||||
|
||||
@GenerateMocks([RegistrationRepository, Prefs])
|
||||
void main() {
|
||||
group('NameScreen', () {
|
||||
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: NameScreen(sheet: sheet),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
testWidgets('displays screen with initial first and last name 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();
|
||||
|
||||
expect(find.text('John'), findsOneWidget);
|
||||
expect(find.text('Doe'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('displays empty fields when names are empty', (WidgetTester tester) async {
|
||||
const sheet = UserRegistrationSheet(
|
||||
firstName: '',
|
||||
lastName: '',
|
||||
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(TextField);
|
||||
expect(textFields, findsNWidgets(2));
|
||||
});
|
||||
|
||||
testWidgets('displays hint texts', (WidgetTester tester) async {
|
||||
const sheet = UserRegistrationSheet(
|
||||
firstName: '',
|
||||
lastName: '',
|
||||
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();
|
||||
|
||||
expect(find.text('Введите имя'), findsOneWidget);
|
||||
expect(find.text('Введите фамилию'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('updates registration cubit when first name 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(TextField);
|
||||
expect(textFields, findsNWidgets(2));
|
||||
|
||||
// Enter new first name
|
||||
await tester.enterText(textFields.first, 'Jane');
|
||||
await tester.pump();
|
||||
|
||||
// Verify that the cubit state was updated
|
||||
expect(registrationCubit.state.sheet.firstName, 'Jane');
|
||||
});
|
||||
|
||||
testWidgets('updates registration cubit when last name 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(TextField);
|
||||
expect(textFields, findsNWidgets(2));
|
||||
|
||||
// Enter new last name
|
||||
await tester.enterText(textFields.last, 'Smith');
|
||||
await tester.pump();
|
||||
|
||||
// Verify that the cubit state was updated
|
||||
expect(registrationCubit.state.sheet.lastName, 'Smith');
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
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/features/registration/presentation/pages/verify_screen.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
||||
import '../../../../helpers/webview_test_helper.dart';
|
||||
|
||||
void main() {
|
||||
group('VerifyScreen', () {
|
||||
setUp(() async {
|
||||
WebViewTestHelper.setUpWebViewPlatform();
|
||||
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'));
|
||||
});
|
||||
|
||||
tearDown(() {
|
||||
WebViewTestHelper.tearDownWebViewPlatform();
|
||||
});
|
||||
|
||||
testWidgets('отображает VerifyScreen с WebView', (WidgetTester tester) async {
|
||||
const passKey = 'test-pass-key';
|
||||
|
||||
final router = GoRouter(
|
||||
initialLocation: '/',
|
||||
routes: [
|
||||
GoRoute(
|
||||
path: '/',
|
||||
builder: (context, state) => const VerifyScreen(passKey: passKey),
|
||||
),
|
||||
],
|
||||
);
|
||||
|
||||
await tester.pumpWidget(
|
||||
MaterialApp.router(
|
||||
routerConfig: router,
|
||||
),
|
||||
);
|
||||
|
||||
await tester.pump();
|
||||
|
||||
// Проверяем, что экран отображается
|
||||
expect(find.byType(VerifyScreen), findsOneWidget);
|
||||
expect(find.byType(Scaffold), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('VerifyScreen создается с правильным passKey', (WidgetTester tester) async {
|
||||
const passKey = 'test-pass-key-123';
|
||||
|
||||
final router = GoRouter(
|
||||
initialLocation: '/',
|
||||
routes: [
|
||||
GoRoute(
|
||||
path: '/',
|
||||
builder: (context, state) => const VerifyScreen(passKey: passKey),
|
||||
),
|
||||
],
|
||||
);
|
||||
|
||||
await tester.pumpWidget(
|
||||
MaterialApp.router(
|
||||
routerConfig: router,
|
||||
),
|
||||
);
|
||||
|
||||
await tester.pump();
|
||||
|
||||
expect(find.byType(VerifyScreen), findsOneWidget);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,251 @@
|
||||
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/weight_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 'weight_screen_test.mocks.dart';
|
||||
|
||||
@GenerateMocks([RegistrationRepository, Prefs])
|
||||
void main() {
|
||||
group('WeightScreen', () {
|
||||
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: WeightScreen(sheet: sheet),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
testWidgets('displays screen with initial weight 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();
|
||||
|
||||
expect(find.text('75'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('displays empty field when weight is 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: 0,
|
||||
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 textField = find.byType(TextField);
|
||||
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: 'Moscow',
|
||||
responseBody: '{}',
|
||||
lang: 'ru',
|
||||
weight: 0,
|
||||
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();
|
||||
|
||||
expect(find.text('кг'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('updates registration cubit when weight 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: 70,
|
||||
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 textField = find.byType(TextField);
|
||||
expect(textField, findsOneWidget);
|
||||
|
||||
await tester.enterText(textField, '80');
|
||||
await tester.pump();
|
||||
|
||||
// Verify that the cubit state was updated
|
||||
expect(registrationCubit.state.sheet.weight, 80);
|
||||
});
|
||||
|
||||
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: 0,
|
||||
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 textField = find.byType(TextField);
|
||||
expect(textField, findsOneWidget);
|
||||
|
||||
// Try to enter non-digit characters
|
||||
await tester.enterText(textField, 'abc');
|
||||
await tester.pump();
|
||||
|
||||
// The text field should only accept digits
|
||||
final textFieldWidget = tester.widget<TextField>(textField);
|
||||
expect(textFieldWidget.controller?.text, isEmpty);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user