diff --git a/test/features/registration_v2/presentation/widgets/password_field_test.dart b/test/features/registration_v2/presentation/widgets/password_field_test.dart index 3c3d800d..575a6a2b 100644 --- a/test/features/registration_v2/presentation/widgets/password_field_test.dart +++ b/test/features/registration_v2/presentation/widgets/password_field_test.dart @@ -1,83 +1,83 @@ -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_v2/cubit/registration_cubit.dart'; -import 'package:eatvio_app/features/registration_v2/cubit/registration_state.dart'; -import 'package:eatvio_app/features/registration_v2/presentation/widgets/password_field.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_portal/flutter_portal.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 'password_field_test.mocks.dart'; - -@GenerateNiceMocks([MockSpec()]) -void main() { - group('PasswordField', () { - setUp(() async { - await sl.reset(); - dotenv.loadFromString(envString: 'DEV_BASE_URL=http://localhost\nBASE_URL=http://localhost'); - sl.registerLazySingleton(() => AppConfig(buildType: AppBuildType.tests)..setBaseUrl('http://localhost')); - }); - - Widget createTestWidget(Widget child, RegistrationCubitV2 cubit) { - return MaterialApp( - theme: ThemeHelper().themeData(), - localizationsDelegates: const [ - S.delegate, - GlobalMaterialLocalizations.delegate, - GlobalWidgetsLocalizations.delegate, - GlobalCupertinoLocalizations.delegate, - ], - supportedLocales: const [Locale('ru')], - home: Portal( - child: BlocProvider( - create: (_) => cubit, - child: Scaffold(body: child), - ), - ), - ); - } - - testWidgets('should display password field with password from state', (WidgetTester tester) async { - // Arrange - final mockCubit = MockRegistrationCubitV2(); - const testPassword = 'testPassword123'; - when(mockCubit.state).thenReturn( - RegistrationStateV2(password: testPassword), - ); - final widget = PasswordField(cubit: mockCubit); - - // Act - await tester.pumpWidget(createTestWidget(widget, mockCubit)); - await tester.pump(); - - // Assert - expect(find.byType(PasswordField), findsOneWidget); - expect(find.text(testPassword), findsOneWidget); - }); - - testWidgets('should show copy icon initially', (WidgetTester tester) async { - // Arrange - final mockCubit = MockRegistrationCubitV2(); - when(mockCubit.state).thenReturn( - RegistrationStateV2(password: 'test'), - ); - final widget = PasswordField(cubit: mockCubit); - - // Act - await tester.pumpWidget(createTestWidget(widget, mockCubit)); - await tester.pump(); - - // Assert - expect(find.byType(PasswordField), findsOneWidget); - }); - }); -} - +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_v2/cubit/registration_cubit.dart'; +import 'package:eatvio_app/features/registration_v2/cubit/registration_state.dart'; +import 'package:eatvio_app/features/registration_v2/presentation/widgets/password_field.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_portal/flutter_portal.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 'password_field_test.mocks.dart'; + +@GenerateNiceMocks([MockSpec()]) +void main() { + group('PasswordField', () { + setUp(() async { + await sl.reset(); + dotenv.loadFromString(envString: 'DEV_BASE_URL=http://localhost\nBASE_URL=http://localhost'); + sl.registerLazySingleton(() => AppConfig(buildType: AppBuildType.tests)..setBaseUrl('http://localhost')); + }); + + Widget createTestWidget(Widget child, RegistrationCubitV2 cubit) { + return MaterialApp( + theme: ThemeHelper().themeData(), + localizationsDelegates: const [ + S.delegate, + GlobalMaterialLocalizations.delegate, + GlobalWidgetsLocalizations.delegate, + GlobalCupertinoLocalizations.delegate, + ], + supportedLocales: const [Locale('ru')], + home: Portal( + child: BlocProvider( + create: (_) => cubit, + child: Scaffold(body: child), + ), + ), + ); + } + + testWidgets('should display password field with password from state', (WidgetTester tester) async { + // Arrange + final mockCubit = MockRegistrationCubitV2(); + const testPassword = 'testPassword123'; + when(mockCubit.state).thenReturn( + const RegistrationStateV2(password: testPassword), + ); + final widget = PasswordField(cubit: mockCubit); + + // Act + await tester.pumpWidget(createTestWidget(widget, mockCubit)); + await tester.pump(); + + // Assert + expect(find.byType(PasswordField), findsOneWidget); + expect(find.text(testPassword), findsOneWidget); + }); + + testWidgets('should show copy icon initially', (WidgetTester tester) async { + // Arrange + final mockCubit = MockRegistrationCubitV2(); + when(mockCubit.state).thenReturn( + const RegistrationStateV2(password: 'test'), + ); + final widget = PasswordField(cubit: mockCubit); + + // Act + await tester.pumpWidget(createTestWidget(widget, mockCubit)); + await tester.pump(); + + // Assert + expect(find.byType(PasswordField), findsOneWidget); + }); + }); +} + diff --git a/test/features/registration_v2/presentation/widgets/sex_widget_test.dart b/test/features/registration_v2/presentation/widgets/sex_widget_test.dart index 3e5fbae2..0c85cc60 100644 --- a/test/features/registration_v2/presentation/widgets/sex_widget_test.dart +++ b/test/features/registration_v2/presentation/widgets/sex_widget_test.dart @@ -42,14 +42,14 @@ void main() { testWidgets('displays sex widget', (tester) async { when(mockCubit.state).thenReturn( - RegistrationStateV2( + const RegistrationStateV2( step: 0, gender: '', isGenderValid: true, ), ); when(mockCubit.stream).thenAnswer((_) => Stream.value( - RegistrationStateV2( + const RegistrationStateV2( step: 0, gender: '', isGenderValid: true, @@ -64,14 +64,14 @@ void main() { testWidgets('calls setGender when male is tapped', (tester) async { when(mockCubit.state).thenReturn( - RegistrationStateV2( + const RegistrationStateV2( step: 0, gender: '', isGenderValid: true, ), ); when(mockCubit.stream).thenAnswer((_) => Stream.value( - RegistrationStateV2( + const RegistrationStateV2( step: 0, gender: '', isGenderValid: true, @@ -94,14 +94,14 @@ void main() { testWidgets('shows error when gender is invalid', (tester) async { when(mockCubit.state).thenReturn( - RegistrationStateV2( + const RegistrationStateV2( step: 0, gender: '', isGenderValid: false, ), ); when(mockCubit.stream).thenAnswer((_) => Stream.value( - RegistrationStateV2( + const RegistrationStateV2( step: 0, gender: '', isGenderValid: false, diff --git a/test/features/registration_v2/presentation/widgets/show_successful_registration_bottom_sheet_test.dart b/test/features/registration_v2/presentation/widgets/show_successful_registration_bottom_sheet_test.dart index 42ce3534..6a9945f4 100644 --- a/test/features/registration_v2/presentation/widgets/show_successful_registration_bottom_sheet_test.dart +++ b/test/features/registration_v2/presentation/widgets/show_successful_registration_bottom_sheet_test.dart @@ -1,118 +1,118 @@ -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_v2/cubit/registration_cubit.dart'; -import 'package:eatvio_app/features/registration_v2/cubit/registration_state.dart'; -import 'package:eatvio_app/features/registration_v2/presentation/widgets/show_successful_registration_bottom_sheet.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_portal/flutter_portal.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 'show_successful_registration_bottom_sheet_test.mocks.dart'; - -@GenerateNiceMocks([MockSpec()]) -void main() { - group('ShowSuccessfulRegistrationBottomSheet', () { - setUp(() async { - await sl.reset(); - dotenv.loadFromString(envString: 'DEV_BASE_URL=http://localhost\nBASE_URL=http://localhost'); - sl.registerLazySingleton(() => AppConfig(buildType: AppBuildType.tests)..setBaseUrl('http://localhost')); - }); - - Widget createTestWidget(Widget child, RegistrationCubitV2 cubit) { - return MaterialApp( - theme: ThemeHelper().themeData(), - localizationsDelegates: const [ - S.delegate, - GlobalMaterialLocalizations.delegate, - GlobalWidgetsLocalizations.delegate, - GlobalCupertinoLocalizations.delegate, - ], - supportedLocales: const [Locale('ru')], - home: Portal( - child: BlocProvider( - create: (_) => cubit, - child: Scaffold( - body: Builder( - builder: (context) => ElevatedButton( - onPressed: () { - showRegistrationBottomSheet(context, cubit, true); - }, - child: const Text('Show Bottom Sheet'), - ), - ), - ), - ), - ), - ); - } - - testWidgets('should display success bottom sheet when isSuccess is true', (WidgetTester tester) async { - // Arrange - final mockCubit = MockRegistrationCubitV2(); - when(mockCubit.state).thenReturn( - RegistrationStateV2(password: 'testPassword'), - ); - - // Act - await tester.pumpWidget(createTestWidget(const SizedBox(), mockCubit)); - await tester.tap(find.text('Show Bottom Sheet')); - await tester.pumpAndSettle(); - - // Assert - expect(find.byType(RegistrationBottomSheet), findsOneWidget); - }); - - testWidgets('should display error bottom sheet when isSuccess is false', (WidgetTester tester) async { - // Arrange - final mockCubit = MockRegistrationCubitV2(); - when(mockCubit.state).thenReturn( - RegistrationStateV2(), - ); - - Widget createTestWidgetError(Widget child, RegistrationCubitV2 cubit) { - return MaterialApp( - theme: ThemeHelper().themeData(), - localizationsDelegates: const [ - S.delegate, - GlobalMaterialLocalizations.delegate, - GlobalWidgetsLocalizations.delegate, - GlobalCupertinoLocalizations.delegate, - ], - supportedLocales: const [Locale('ru')], - home: Portal( - child: BlocProvider( - create: (_) => cubit, - child: Scaffold( - body: Builder( - builder: (context) => ElevatedButton( - onPressed: () { - showRegistrationBottomSheet(context, cubit, false); - }, - child: const Text('Show Bottom Sheet'), - ), - ), - ), - ), - ), - ); - } - - // Act - await tester.pumpWidget(createTestWidgetError(const SizedBox(), mockCubit)); - await tester.tap(find.text('Show Bottom Sheet')); - await tester.pumpAndSettle(); - - // Assert - expect(find.byType(RegistrationBottomSheet), findsOneWidget); - }); - }); -} - +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_v2/cubit/registration_cubit.dart'; +import 'package:eatvio_app/features/registration_v2/cubit/registration_state.dart'; +import 'package:eatvio_app/features/registration_v2/presentation/widgets/show_successful_registration_bottom_sheet.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_portal/flutter_portal.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 'show_successful_registration_bottom_sheet_test.mocks.dart'; + +@GenerateNiceMocks([MockSpec()]) +void main() { + group('ShowSuccessfulRegistrationBottomSheet', () { + setUp(() async { + await sl.reset(); + dotenv.loadFromString(envString: 'DEV_BASE_URL=http://localhost\nBASE_URL=http://localhost'); + sl.registerLazySingleton(() => AppConfig(buildType: AppBuildType.tests)..setBaseUrl('http://localhost')); + }); + + Widget createTestWidget(Widget child, RegistrationCubitV2 cubit) { + return MaterialApp( + theme: ThemeHelper().themeData(), + localizationsDelegates: const [ + S.delegate, + GlobalMaterialLocalizations.delegate, + GlobalWidgetsLocalizations.delegate, + GlobalCupertinoLocalizations.delegate, + ], + supportedLocales: const [Locale('ru')], + home: Portal( + child: BlocProvider( + create: (_) => cubit, + child: Scaffold( + body: Builder( + builder: (context) => ElevatedButton( + onPressed: () { + showRegistrationBottomSheet(context, cubit, true); + }, + child: const Text('Show Bottom Sheet'), + ), + ), + ), + ), + ), + ); + } + + testWidgets('should display success bottom sheet when isSuccess is true', (WidgetTester tester) async { + // Arrange + final mockCubit = MockRegistrationCubitV2(); + when(mockCubit.state).thenReturn( + const RegistrationStateV2(password: 'testPassword'), + ); + + // Act + await tester.pumpWidget(createTestWidget(const SizedBox(), mockCubit)); + await tester.tap(find.text('Show Bottom Sheet')); + await tester.pumpAndSettle(); + + // Assert + expect(find.byType(RegistrationBottomSheet), findsOneWidget); + }); + + testWidgets('should display error bottom sheet when isSuccess is false', (WidgetTester tester) async { + // Arrange + final mockCubit = MockRegistrationCubitV2(); + when(mockCubit.state).thenReturn( + const RegistrationStateV2(), + ); + + Widget createTestWidgetError(Widget child, RegistrationCubitV2 cubit) { + return MaterialApp( + theme: ThemeHelper().themeData(), + localizationsDelegates: const [ + S.delegate, + GlobalMaterialLocalizations.delegate, + GlobalWidgetsLocalizations.delegate, + GlobalCupertinoLocalizations.delegate, + ], + supportedLocales: const [Locale('ru')], + home: Portal( + child: BlocProvider( + create: (_) => cubit, + child: Scaffold( + body: Builder( + builder: (context) => ElevatedButton( + onPressed: () { + showRegistrationBottomSheet(context, cubit, false); + }, + child: const Text('Show Bottom Sheet'), + ), + ), + ), + ), + ), + ); + } + + // Act + await tester.pumpWidget(createTestWidgetError(const SizedBox(), mockCubit)); + await tester.tap(find.text('Show Bottom Sheet')); + await tester.pumpAndSettle(); + + // Assert + expect(find.byType(RegistrationBottomSheet), findsOneWidget); + }); + }); +} + diff --git a/test/features/registration_v2/presentation/widgets/step_widget_test.dart b/test/features/registration_v2/presentation/widgets/step_widget_test.dart index 50279979..70fec32d 100644 --- a/test/features/registration_v2/presentation/widgets/step_widget_test.dart +++ b/test/features/registration_v2/presentation/widgets/step_widget_test.dart @@ -43,9 +43,9 @@ void main() { testWidgets('displays step widget', (tester) async { when(mockCubit.state).thenReturn( - RegistrationStateV2(step: 0), + const RegistrationStateV2(step: 0), ); - when(mockCubit.stream).thenAnswer((_) => Stream.value(RegistrationStateV2(step: 0))); + when(mockCubit.stream).thenAnswer((_) => Stream.value(const RegistrationStateV2(step: 0))); await tester.pumpWidget(createTestWidget()); await tester.pumpAndSettle(); @@ -55,9 +55,9 @@ void main() { testWidgets('displays correct step number', (tester) async { when(mockCubit.state).thenReturn( - RegistrationStateV2(step: 2), + const RegistrationStateV2(step: 2), ); - when(mockCubit.stream).thenAnswer((_) => Stream.value(RegistrationStateV2(step: 2))); + when(mockCubit.stream).thenAnswer((_) => Stream.value(const RegistrationStateV2(step: 2))); await tester.pumpWidget(createTestWidget()); await tester.pumpAndSettle();