forked from eatvio/eatvio_app
252 lines
7.7 KiB
Dart
252 lines
7.7 KiB
Dart
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));
|
|
});
|
|
});
|
|
}
|
|
|
|
|