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/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);
|
|
});
|
|
});
|
|
}
|
|
|