From 4b4e0dd81460803b8de23dfdb8ba88ba3e4a27cc Mon Sep 17 00:00:00 2001 From: maxxkim Date: Wed, 13 Mar 2024 12:51:50 +0300 Subject: [PATCH] test(registration): All tests passed! SMOKE TESTING FINISHED --- .../registration/name_screen/name_screen.dart | 82 +++++++++---------- .../weight_screen/weight_screen.dart | 26 +++--- test/language_select_test.dart | 1 - test/medicine_intake_test.dart | 55 +++++++++++++ test/name_test.dart | 55 +++++++++++++ test/weight_test.dart | 55 +++++++++++++ 6 files changed, 216 insertions(+), 58 deletions(-) create mode 100644 test/medicine_intake_test.dart create mode 100644 test/name_test.dart create mode 100644 test/weight_test.dart diff --git a/lib/presentation/registration/name_screen/name_screen.dart b/lib/presentation/registration/name_screen/name_screen.dart index 05759a4..83dafef 100644 --- a/lib/presentation/registration/name_screen/name_screen.dart +++ b/lib/presentation/registration/name_screen/name_screen.dart @@ -34,7 +34,7 @@ class NameScreen extends StatelessWidget { body: Container( width: double.maxFinite, padding: EdgeInsets.symmetric(horizontal: 16.h, vertical: 9.v), - child: Column(children: [ + child: ListView(children: [ SizedBox(height: 7.v), Container( height: 16.v, @@ -75,7 +75,6 @@ class NameScreen extends StatelessWidget { ); }), SizedBox(height: 21.v), - Spacer(), BlocBuilder(builder: (context, state) { return NextStepButton( text: "continue".tr.toUpperCase(), @@ -104,65 +103,66 @@ class NameScreen extends StatelessWidget { NavigatorService.goBack(); } - _onTapNext(BuildContext context, state) { - List errors = validateFields( - state.firstNameController!.text, state.lastNameController!.text); - if (errors.isEmpty) { - UserRegistrationSheet sheet = state.nameModelObj!.userRegistrationSheet; - sheet.firstName = state.firstNameController!.text; - sheet.lastName = state.lastNameController!.text; - Navigator.pushNamed( - context, - AppRoutes.genderScreen, - arguments: sheet, - ); - } else { - String errorMessage = ''; + _onTapNext(BuildContext context, NameState state) { + if (state.firstNameController != null && state.lastNameController != null) { + List errors = validateFields( + state.firstNameController!.text, state.lastNameController!.text); - for (var error in errors) { - errorMessage += error + '\n\n'; + if (errors.isEmpty) { + UserRegistrationSheet sheet = state.nameModelObj!.userRegistrationSheet; + sheet.firstName = state.firstNameController!.text; + sheet.lastName = state.lastNameController!.text; + + Navigator.pushNamed( + context, + AppRoutes.genderScreen, + arguments: sheet, + ); + } else { + String errorMessage = ''; + + for (var error in errors) { + errorMessage += error + '\n\n'; + } + + showDialog( + context: context, + builder: (context) => AlertDialog( + title: Text('Error'), + content: Text(errorMessage), + actions: [ + TextButton( + onPressed: () => onTapOk(context), + child: Text('OK'), + ), + ], + ), + ); } - - showDialog( - context: context, - builder: (context) => AlertDialog( - title: Text('Ошибка'), - content: Text(errorMessage), - actions: [ - TextButton( - onPressed: onTapOk(context), - child: Text('OK'), - ), - ], - ), - ); } } - onTapOk(BuildContext context) { + void onTapOk(BuildContext context) { Navigator.pop(context); } - List validateFields( - String firstName, - String lastName, - ) { + List validateFields(String firstName, String lastName) { List errors = []; if (firstName.isEmpty) { - errors.add('first_name_empty'.tr); + errors.add('First name cannot be empty'); } if (firstName.length < 1) { - errors.add('first_name_short'.tr); + errors.add('First name is too short'); } if (lastName.isEmpty) { - errors.add('last_name_empty'.tr); + errors.add('Last name cannot be empty'); } if (lastName.length < 1) { - errors.add('last_name_short'.tr); + errors.add('Last name is too short'); } return errors; diff --git a/lib/presentation/registration/weight_screen/weight_screen.dart b/lib/presentation/registration/weight_screen/weight_screen.dart index 64cec0a..3a14fd0 100644 --- a/lib/presentation/registration/weight_screen/weight_screen.dart +++ b/lib/presentation/registration/weight_screen/weight_screen.dart @@ -36,7 +36,7 @@ class _WeightScreenState extends State { body: Container( width: double.maxFinite, padding: EdgeInsets.symmetric(horizontal: 16.h, vertical: 9.v), - child: Column(children: [ + child: ListView(children: [ SizedBox(height: 7.v), Container( height: 16.v, @@ -81,7 +81,6 @@ class _WeightScreenState extends State { }) ]) ]), - Spacer(), BlocBuilder( builder: (context, state) { return NextStepButton( @@ -111,20 +110,15 @@ class _WeightScreenState extends State { NavigatorService.goBack(); } - onTapNext(BuildContext context, state) { - UserRegistrationSheet sheet = state.weightModelObj!.userRegistrationSheet; - Navigator.pushNamed( - context, - AppRoutes.heightScreen, - arguments: sheet, - ); - } - - /// Navigates to the allergiesScreen when the action is triggered. - navigateToHeight(BuildContext context) { - NavigatorService.pushNamed( - AppRoutes.heightScreen, - ); + onTapNext(BuildContext context, WeightState state) { + return () { + UserRegistrationSheet sheet = state.weightModelObj!.userRegistrationSheet; + Navigator.pushNamed( + context, + AppRoutes.heightScreen, + arguments: sheet, + ); + }; } void _onDropDownChanged(value) { diff --git a/test/language_select_test.dart b/test/language_select_test.dart index ecba1de..447592f 100644 --- a/test/language_select_test.dart +++ b/test/language_select_test.dart @@ -1,4 +1,3 @@ -import 'package:eatvio_app/data/models/userRegistrationModel/user_registration_model.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_test/flutter_test.dart'; diff --git a/test/medicine_intake_test.dart b/test/medicine_intake_test.dart new file mode 100644 index 0000000..fd92e71 --- /dev/null +++ b/test/medicine_intake_test.dart @@ -0,0 +1,55 @@ +import 'package:eatvio_app/data/models/userRegistrationModel/user_registration_model.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:eatvio_app/presentation/registration/medicine_intake_screen/medicine_intake_screen.dart'; +import 'package:eatvio_app/presentation/registration/medicine_intake_screen/bloc/medicine_intake_bloc.dart'; +import 'package:eatvio_app/presentation/registration/medicine_intake_screen/models/medicine_intake_model.dart'; + +void main() { + group('AdditionalInfoScreen', () { + testWidgets('renders screen in initial state', (WidgetTester tester) async { + final myProfileBloc = MedicineIntakeBloc(MedicineIntakeState( + medicineIntakeModelObj: MedicineIntakeModel( + userRegistrationSheet: UserRegistrationSheet( + name: "name", + firstName: "firstName", + lastName: "lastName", + email: "email", + password: "password", + passwordConfirmation: "passwordConfirmation", + termsAccepted: "termsAccepted", + birthdate: "birthdate", + gender: "gender", + country: "country", + city: "city", + lang: "lang", + weight: "weight", + height: "height", + chestCircumference: 'asdasd', + waistCircumference: "waistCircumference", + hipCircumference: "hipCircumference", + bloodPressureUp: "bloodPressureUp", + bloodPressureDown: "bloodPressureDown", + hasHypo: "hasHypo", + hasHyper: "hasHyper", + aboutAllergy: "aboutAllergy", + aboutTakingPils: "aboutTakingPils", + aboutSportHobbies: "aboutSportHobbies", + favoriteFoods: "favoriteFoods", + unfavoriteFoods: "unfavoriteFoods", + additionalInfo: + "additionalInfo")))); // Ensure that MyProfileModel is non-nullable + + await tester.pumpWidget( + MaterialApp( + home: BlocProvider.value( + value: myProfileBloc, + child: MedicineIntakeScreen(), + ), + ), + ); + }); + }); +} +//sports \ No newline at end of file diff --git a/test/name_test.dart b/test/name_test.dart new file mode 100644 index 0000000..408a01c --- /dev/null +++ b/test/name_test.dart @@ -0,0 +1,55 @@ +import 'package:eatvio_app/data/models/userRegistrationModel/user_registration_model.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:eatvio_app/presentation/registration/name_screen/name_screen.dart'; +import 'package:eatvio_app/presentation/registration/name_screen/bloc/name_bloc.dart'; +import 'package:eatvio_app/presentation/registration/name_screen/models/name_model.dart'; + +void main() { + group('AdditionalInfoScreen', () { + testWidgets('renders screen in initial state', (WidgetTester tester) async { + final myProfileBloc = NameBloc(NameState( + nameModelObj: NameModel( + userRegistrationSheet: UserRegistrationSheet( + name: "name", + firstName: "firstName", + lastName: "lastName", + email: "email", + password: "password", + passwordConfirmation: "passwordConfirmation", + termsAccepted: "termsAccepted", + birthdate: "birthdate", + gender: "gender", + country: "country", + city: "city", + lang: "lang", + weight: "weight", + height: "height", + chestCircumference: 'asdasd', + waistCircumference: "waistCircumference", + hipCircumference: "hipCircumference", + bloodPressureUp: "bloodPressureUp", + bloodPressureDown: "bloodPressureDown", + hasHypo: "hasHypo", + hasHyper: "hasHyper", + aboutAllergy: "aboutAllergy", + aboutTakingPils: "aboutTakingPils", + aboutSportHobbies: "aboutSportHobbies", + favoriteFoods: "favoriteFoods", + unfavoriteFoods: "unfavoriteFoods", + additionalInfo: + "additionalInfo")))); // Ensure that MyProfileModel is non-nullable + + await tester.pumpWidget( + MaterialApp( + home: BlocProvider.value( + value: myProfileBloc, + child: NameScreen(), + ), + ), + ); + }); + }); +} +//sports \ No newline at end of file diff --git a/test/weight_test.dart b/test/weight_test.dart new file mode 100644 index 0000000..adf8f8f --- /dev/null +++ b/test/weight_test.dart @@ -0,0 +1,55 @@ +import 'package:eatvio_app/data/models/userRegistrationModel/user_registration_model.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:eatvio_app/presentation/registration/weight_screen/weight_screen.dart'; +import 'package:eatvio_app/presentation/registration/weight_screen/bloc/weight_bloc.dart'; +import 'package:eatvio_app/presentation/registration/weight_screen/models/weight_model.dart'; + +void main() { + group('AdditionalInfoScreen', () { + testWidgets('renders screen in initial state', (WidgetTester tester) async { + final myProfileBloc = WeightBloc(WeightState( + weightModelObj: WeightModel( + userRegistrationSheet: UserRegistrationSheet( + name: "name", + firstName: "firstName", + lastName: "lastName", + email: "email", + password: "password", + passwordConfirmation: "passwordConfirmation", + termsAccepted: "termsAccepted", + birthdate: "birthdate", + gender: "gender", + country: "country", + city: "city", + lang: "lang", + weight: "weight", + height: "height", + chestCircumference: 'asdasd', + waistCircumference: "waistCircumference", + hipCircumference: "hipCircumference", + bloodPressureUp: "bloodPressureUp", + bloodPressureDown: "bloodPressureDown", + hasHypo: "hasHypo", + hasHyper: "hasHyper", + aboutAllergy: "aboutAllergy", + aboutTakingPils: "aboutTakingPils", + aboutSportHobbies: "aboutSportHobbies", + favoriteFoods: "favoriteFoods", + unfavoriteFoods: "unfavoriteFoods", + additionalInfo: + "additionalInfo")))); // Ensure that MyProfileModel is non-nullable + + await tester.pumpWidget( + MaterialApp( + home: BlocProvider.value( + value: myProfileBloc, + child: WeightScreen(), + ), + ), + ); + }); + }); +} +//sports \ No newline at end of file