forked from eatvio/eatvio_app
fix(chat): initialize startDate to current date when personal diet is not enabled and streamline widget layout for improved readability
This commit is contained in:
@@ -0,0 +1,133 @@
|
||||
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/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/phone_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:flutter_dotenv/flutter_dotenv.dart';
|
||||
import 'package:mockito/annotations.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
import 'package:eatvio_app/core/prefs.dart';
|
||||
|
||||
import 'phone_screen_test.mocks.dart';
|
||||
|
||||
@GenerateMocks([RegistrationRepository, Prefs])
|
||||
void main() {
|
||||
group('PhoneScreen', () {
|
||||
setUp(() async {
|
||||
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'));
|
||||
});
|
||||
|
||||
Widget createTestWidget(Widget child, RegistrationCubit cubit) {
|
||||
return MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
home: BlocProvider<RegistrationCubit>(
|
||||
create: (_) => cubit,
|
||||
child: Scaffold(body: child),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
testWidgets('should display phone screen with empty phone', (WidgetTester tester) async {
|
||||
// Arrange
|
||||
final mockRepository = MockRegistrationRepository();
|
||||
final cubit = RegistrationCubit(
|
||||
registrationRepository: mockRepository,
|
||||
prefs: MockPrefs(),
|
||||
);
|
||||
final sheet = UserRegistrationSheet(
|
||||
firstName: 'John',
|
||||
lastName: 'Doe',
|
||||
email: 'test@example.com',
|
||||
password: 'password',
|
||||
passwordConfirmation: 'password',
|
||||
birthdate: '1990-01-01',
|
||||
gender: 'male',
|
||||
location: 'Moscow',
|
||||
responseBody: '{}',
|
||||
lang: 'ru',
|
||||
weight: 70,
|
||||
height: 175,
|
||||
phone: '',
|
||||
chestCircumference: 90,
|
||||
waistCircumference: 80,
|
||||
hipCircumference: 95,
|
||||
bloodPressureUp: 120,
|
||||
bloodPressureDown: 80,
|
||||
hasHypo: 0,
|
||||
hasHyper: 0,
|
||||
aboutAllergy: '',
|
||||
aboutTakingPils: '',
|
||||
aboutSportHobbies: '',
|
||||
favoriteFoods: '',
|
||||
unfavoriteFoods: '',
|
||||
additionalInfo: '',
|
||||
);
|
||||
final widget = PhoneScreen(sheet: sheet);
|
||||
|
||||
// Act
|
||||
await tester.pumpWidget(createTestWidget(widget, cubit));
|
||||
await tester.pump();
|
||||
|
||||
// Assert
|
||||
expect(find.byType(PhoneScreen), findsOneWidget);
|
||||
expect(find.text('Номер телефона'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('should display phone screen with pre-filled phone', (WidgetTester tester) async {
|
||||
// Arrange
|
||||
final mockRepository = MockRegistrationRepository();
|
||||
final cubit = RegistrationCubit(
|
||||
registrationRepository: mockRepository,
|
||||
prefs: MockPrefs(),
|
||||
);
|
||||
final sheet = UserRegistrationSheet(
|
||||
firstName: 'John',
|
||||
lastName: 'Doe',
|
||||
email: 'test@example.com',
|
||||
password: 'password',
|
||||
passwordConfirmation: 'password',
|
||||
birthdate: '1990-01-01',
|
||||
gender: 'male',
|
||||
location: 'Moscow',
|
||||
responseBody: '{}',
|
||||
lang: 'ru',
|
||||
weight: 70,
|
||||
height: 175,
|
||||
phone: '+7 (999) 123 45 67',
|
||||
chestCircumference: 90,
|
||||
waistCircumference: 80,
|
||||
hipCircumference: 95,
|
||||
bloodPressureUp: 120,
|
||||
bloodPressureDown: 80,
|
||||
hasHypo: 0,
|
||||
hasHyper: 0,
|
||||
aboutAllergy: '',
|
||||
aboutTakingPils: '',
|
||||
aboutSportHobbies: '',
|
||||
favoriteFoods: '',
|
||||
unfavoriteFoods: '',
|
||||
additionalInfo: '',
|
||||
);
|
||||
final widget = PhoneScreen(sheet: sheet);
|
||||
|
||||
// Act
|
||||
await tester.pumpWidget(createTestWidget(widget, cubit));
|
||||
await tester.pump();
|
||||
|
||||
// Assert
|
||||
expect(find.byType(PhoneScreen), findsOneWidget);
|
||||
expect(find.text('+7 (999) 123 45 67'), findsOneWidget);
|
||||
|
||||
cubit.close();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user