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,113 @@
|
||||
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/presentation/bloc/verify_email_cubit/verify_email_cubit.dart';
|
||||
import 'package:eatvio_app/features/registration/presentation/bloc/verify_email_cubit/verify_email_state.dart';
|
||||
import 'package:eatvio_app/features/registration/presentation/widgets/change_email_dialog.dart';
|
||||
import 'package:flutter/material.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 'change_email_dialog_test.mocks.dart';
|
||||
|
||||
@GenerateNiceMocks([MockSpec<VerifyEmailCubit>()])
|
||||
void main() {
|
||||
group('ChangeEmailDialog', () {
|
||||
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) {
|
||||
return MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
home: Scaffold(
|
||||
body: Builder(
|
||||
builder: (context) => Column(
|
||||
children: [
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (_) => child,
|
||||
);
|
||||
},
|
||||
child: const Text('Show Dialog'),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
testWidgets('should display dialog with current email pre-filled', (WidgetTester tester) async {
|
||||
// Arrange
|
||||
final mockCubit = MockVerifyEmailCubit();
|
||||
when(mockCubit.state).thenReturn(const VerifyEmailState());
|
||||
const currentEmail = 'test@example.com';
|
||||
final widget = ChangeEmailDialog(
|
||||
currentEmail: currentEmail,
|
||||
verifyEmailCubit: mockCubit,
|
||||
);
|
||||
|
||||
// Act
|
||||
await tester.pumpWidget(createTestWidget(widget));
|
||||
await tester.tap(find.text('Show Dialog'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// Assert
|
||||
expect(find.text('Сменить email'), findsOneWidget);
|
||||
expect(find.text(currentEmail), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('should show error for empty email', (WidgetTester tester) async {
|
||||
// Arrange
|
||||
final mockCubit = MockVerifyEmailCubit();
|
||||
when(mockCubit.state).thenReturn(const VerifyEmailState());
|
||||
const currentEmail = 'test@example.com';
|
||||
final widget = ChangeEmailDialog(
|
||||
currentEmail: currentEmail,
|
||||
verifyEmailCubit: mockCubit,
|
||||
);
|
||||
|
||||
// Act
|
||||
await tester.pumpWidget(createTestWidget(widget));
|
||||
await tester.tap(find.text('Show Dialog'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
final textField = find.byType(TextField);
|
||||
await tester.enterText(textField, '');
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// Assert
|
||||
expect(find.text('Введите email'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('should close dialog when Отмена button is tapped', (WidgetTester tester) async {
|
||||
// Arrange
|
||||
final mockCubit = MockVerifyEmailCubit();
|
||||
when(mockCubit.state).thenReturn(const VerifyEmailState());
|
||||
const currentEmail = 'test@example.com';
|
||||
final widget = ChangeEmailDialog(
|
||||
currentEmail: currentEmail,
|
||||
verifyEmailCubit: mockCubit,
|
||||
);
|
||||
|
||||
// Act
|
||||
await tester.pumpWidget(createTestWidget(widget));
|
||||
await tester.tap(find.text('Show Dialog'));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('Отмена'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// Assert
|
||||
expect(find.text('Сменить email'), findsNothing);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
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/presentation/bloc/verify_email_cubit/verify_email_cubit.dart';
|
||||
import 'package:eatvio_app/features/registration/presentation/widgets/code_not_received_dialog.dart';
|
||||
import 'package:flutter/material.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 'code_not_received_dialog_test.mocks.dart';
|
||||
|
||||
@GenerateNiceMocks([MockSpec<VerifyEmailCubit>()])
|
||||
void main() {
|
||||
group('CodeNotReceivedDialog', () {
|
||||
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) {
|
||||
return MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
home: Scaffold(
|
||||
body: Builder(
|
||||
builder: (context) => Column(
|
||||
children: [
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (_) => child,
|
||||
);
|
||||
},
|
||||
child: const Text('Show Dialog'),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
testWidgets('should display dialog with correct text', (WidgetTester tester) async {
|
||||
// Arrange
|
||||
final mockCubit = MockVerifyEmailCubit();
|
||||
const currentEmail = 'test@example.com';
|
||||
final widget = CodeNotReceivedDialog(
|
||||
currentEmail: currentEmail,
|
||||
verifyEmailCubit: mockCubit,
|
||||
);
|
||||
|
||||
// Act
|
||||
await tester.pumpWidget(createTestWidget(widget));
|
||||
await tester.tap(find.text('Show Dialog'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// Assert
|
||||
expect(find.text('Почему может не приходить код?'), findsOneWidget);
|
||||
expect(find.text('Понятно'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('should close dialog when Понятно button is tapped', (WidgetTester tester) async {
|
||||
// Arrange
|
||||
final mockCubit = MockVerifyEmailCubit();
|
||||
const currentEmail = 'test@example.com';
|
||||
final widget = CodeNotReceivedDialog(
|
||||
currentEmail: currentEmail,
|
||||
verifyEmailCubit: mockCubit,
|
||||
);
|
||||
|
||||
// Act
|
||||
await tester.pumpWidget(createTestWidget(widget));
|
||||
await tester.tap(find.text('Show Dialog'));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('Понятно'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// Assert
|
||||
expect(find.text('Почему может не приходить код?'), findsNothing);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user