forked from eatvio/eatvio_app
166 lines
4.8 KiB
Dart
166 lines
4.8 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/credentials_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 'credentials_screen_test.mocks.dart';
|
|
|
|
@GenerateMocks([RegistrationRepository, Prefs])
|
|
void main() {
|
|
group('CredentialsScreen', () {
|
|
late MockRegistrationRepository mockRegistrationRepository;
|
|
late MockPrefs mockPrefs;
|
|
late RegistrationCubit registrationCubit;
|
|
|
|
setUp(() {
|
|
mockRegistrationRepository = MockRegistrationRepository();
|
|
mockPrefs = MockPrefs();
|
|
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'), Locale('en')],
|
|
locale: const Locale('ru'),
|
|
home: BlocProvider<RegistrationCubit>.value(
|
|
value: registrationCubit,
|
|
child: Scaffold(
|
|
body: CredentialsScreen(sheet: sheet),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
testWidgets('displays email field', (tester) async {
|
|
const sheet = UserRegistrationSheet(
|
|
firstName: 'Test',
|
|
lastName: 'User',
|
|
email: '',
|
|
password: '',
|
|
passwordConfirmation: '',
|
|
birthdate: '',
|
|
gender: 'male',
|
|
location: '',
|
|
responseBody: '{}',
|
|
lang: 'ru',
|
|
weight: 70,
|
|
height: 175,
|
|
phone: '',
|
|
chestCircumference: 90,
|
|
waistCircumference: 80,
|
|
hipCircumference: 95,
|
|
bloodPressureUp: 0,
|
|
bloodPressureDown: 0,
|
|
hasHypo: 0,
|
|
hasHyper: 0,
|
|
aboutAllergy: '',
|
|
aboutTakingPils: '',
|
|
aboutSportHobbies: '',
|
|
favoriteFoods: '',
|
|
unfavoriteFoods: '',
|
|
additionalInfo: '',
|
|
);
|
|
|
|
await tester.pumpWidget(createTestWidget(sheet));
|
|
await tester.pumpAndSettle();
|
|
|
|
expect(find.byType(CredentialsScreen), findsOneWidget);
|
|
});
|
|
|
|
testWidgets('displays password fields', (tester) async {
|
|
const sheet = UserRegistrationSheet(
|
|
firstName: 'Test',
|
|
lastName: 'User',
|
|
email: 'test@example.com',
|
|
password: '',
|
|
passwordConfirmation: '',
|
|
birthdate: '',
|
|
gender: 'male',
|
|
location: '',
|
|
responseBody: '{}',
|
|
lang: 'ru',
|
|
weight: 70,
|
|
height: 175,
|
|
phone: '',
|
|
chestCircumference: 90,
|
|
waistCircumference: 80,
|
|
hipCircumference: 95,
|
|
bloodPressureUp: 0,
|
|
bloodPressureDown: 0,
|
|
hasHypo: 0,
|
|
hasHyper: 0,
|
|
aboutAllergy: '',
|
|
aboutTakingPils: '',
|
|
aboutSportHobbies: '',
|
|
favoriteFoods: '',
|
|
unfavoriteFoods: '',
|
|
additionalInfo: '',
|
|
);
|
|
|
|
await tester.pumpWidget(createTestWidget(sheet));
|
|
await tester.pumpAndSettle();
|
|
|
|
expect(find.byType(CredentialsScreen), findsOneWidget);
|
|
});
|
|
|
|
testWidgets('initializes with existing values', (tester) async {
|
|
const sheet = UserRegistrationSheet(
|
|
firstName: 'Test',
|
|
lastName: 'User',
|
|
email: 'test@example.com',
|
|
password: 'password123',
|
|
passwordConfirmation: 'password123',
|
|
birthdate: '',
|
|
gender: 'male',
|
|
location: '',
|
|
responseBody: '{}',
|
|
lang: 'ru',
|
|
weight: 70,
|
|
height: 175,
|
|
phone: '',
|
|
chestCircumference: 90,
|
|
waistCircumference: 80,
|
|
hipCircumference: 95,
|
|
bloodPressureUp: 0,
|
|
bloodPressureDown: 0,
|
|
hasHypo: 0,
|
|
hasHyper: 0,
|
|
aboutAllergy: '',
|
|
aboutTakingPils: '',
|
|
aboutSportHobbies: '',
|
|
favoriteFoods: '',
|
|
unfavoriteFoods: '',
|
|
additionalInfo: '',
|
|
);
|
|
|
|
await tester.pumpWidget(createTestWidget(sheet));
|
|
await tester.pumpAndSettle();
|
|
|
|
expect(find.byType(CredentialsScreen), findsOneWidget);
|
|
});
|
|
});
|
|
}
|
|
|