From d630e2afbf7d7ce26f985bf3db6dbef9afa7af0a Mon Sep 17 00:00:00 2001 From: Mayankpulse333 Date: Sun, 29 Dec 2024 03:37:33 +0530 Subject: [PATCH 1/3] added --- .../profile/edit_profile_page_test.dart | 120 ++++++++++++++++++ 1 file changed, 120 insertions(+) create mode 100644 test/views/after_auth_screens/profile/edit_profile_page_test.dart diff --git a/test/views/after_auth_screens/profile/edit_profile_page_test.dart b/test/views/after_auth_screens/profile/edit_profile_page_test.dart new file mode 100644 index 000000000..df5c85845 --- /dev/null +++ b/test/views/after_auth_screens/profile/edit_profile_page_test.dart @@ -0,0 +1,120 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_localizations/flutter_localizations.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:mockito/mockito.dart'; +import 'package:talawa/utils/app_localization.dart'; +import 'package:talawa/view_model/after_auth_view_models/profile_view_models/edit_profile_view_model.dart'; +import 'package:talawa/views/after_auth_screens/profile/edit_profile_page.dart'; +import 'package:talawa/views/base_view.dart'; + +import '../../../helpers/test_helpers.dart'; +import '../../../helpers/test_locator.dart'; + +Widget createEditProfilePage({required EditProfilePageViewModel viewModel}) { + return BaseView( + onModelReady: (model) => model.initialize(), + builder: (context, model, child) { + return MaterialApp( + locale: const Locale('en'), + localizationsDelegates: [ + const AppLocalizationsDelegate(isTest: true), + GlobalMaterialLocalizations.delegate, + GlobalWidgetsLocalizations.delegate, + ], + home: Scaffold( + key: const Key('EditProfileScreenScaffold'), + body: EditProfilePage(), + ), + ); + }, + ); +} + +void main() { + setUpAll(() { + TestWidgetsFlutterBinding.ensureInitialized(); + testSetupLocator(); + registerServices(); + }); + + group('EditProfilePage Tests', () { + testWidgets('Check if profile image and button are displayed', + (tester) async { + await tester.pumpWidget( + createEditProfilePage( + viewModel: locator(), + ), + ); + await tester.pumpAndSettle(); + + expect(find.byKey(const Key('profilepic')), findsOneWidget); + expect(find.byKey(const Key('AddRemoveImageButton')), findsOneWidget); + }); + + testWidgets('Test Add/Remove Image Button functionality', (tester) async { + await tester.pumpWidget( + createEditProfilePage( + viewModel: locator(), + ), + ); + await tester.pumpAndSettle(); + + final addRemoveButton = find.byKey(const Key('AddRemoveImageButton')); + await tester.tap(addRemoveButton); + await tester.pumpAndSettle(); + + expect(find.byType(BottomSheet), findsOneWidget); + final cameraButton = find.byKey(const Key('selectCamera')); + final galleryButton = find.byKey(const Key('selectGallery')); + expect(cameraButton, findsOneWidget); + expect(galleryButton, findsOneWidget); + + await tester.tap(cameraButton); + await tester.pumpAndSettle(); + }); + + testWidgets('Check if first and last name text fields are present', + (tester) async { + await tester.pumpWidget( + createEditProfilePage( + viewModel: locator(), + ), + ); + await tester.pumpAndSettle(); + + expect(find.byKey(const Key('FirstNameTextField')), findsOneWidget); + expect(find.byType(TextFormField), findsWidgets); + }); + + testWidgets('Test Update button functionality', (tester) async { + await tester.pumpWidget( + createEditProfilePage( + viewModel: locator(), + ), + ); + await tester.pumpAndSettle(); + + final updateButton = find.byKey(const Key('updatebtn')); + expect(updateButton, findsOneWidget); + + await tester.tap(updateButton); + await tester.pump(); + verify(locator().updateUserProfile( + firstName: anyNamed('firstName'), + lastName: anyNamed('lastName'), + newImage: anyNamed('newImage'))); + }); + + testWidgets('Check if Email section is displayed', (tester) async { + await tester.pumpWidget( + createEditProfilePage( + viewModel: locator(), + ), + ); + await tester.pumpAndSettle(); + + expect(find.textContaining('Email'), findsOneWidget); + expect(find.byIcon(Icons.email), findsOneWidget); + }); + }); +} From 6ec2164e2f09fb42e33bc2cc60806077e03991dd Mon Sep 17 00:00:00 2001 From: Mayankpulse333 Date: Sun, 29 Dec 2024 03:46:47 +0530 Subject: [PATCH 2/3] adding const in it --- .../after_auth_screens/profile/edit_profile_page_test.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/views/after_auth_screens/profile/edit_profile_page_test.dart b/test/views/after_auth_screens/profile/edit_profile_page_test.dart index df5c85845..d11321d2b 100644 --- a/test/views/after_auth_screens/profile/edit_profile_page_test.dart +++ b/test/views/after_auth_screens/profile/edit_profile_page_test.dart @@ -21,8 +21,8 @@ Widget createEditProfilePage({required EditProfilePageViewModel viewModel}) { GlobalMaterialLocalizations.delegate, GlobalWidgetsLocalizations.delegate, ], - home: Scaffold( - key: const Key('EditProfileScreenScaffold'), + home: const Scaffold( + key: Key('EditProfileScreenScaffold'), body: EditProfilePage(), ), ); From 9477b722f01ea56cf3b5ba0ab36f7793066c45ec Mon Sep 17 00:00:00 2001 From: Mayankpulse333 Date: Sun, 29 Dec 2024 03:54:37 +0530 Subject: [PATCH 3/3] fixing linting issue --- .../profile/edit_profile_page_test.dart | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/test/views/after_auth_screens/profile/edit_profile_page_test.dart b/test/views/after_auth_screens/profile/edit_profile_page_test.dart index d11321d2b..d214cf7a0 100644 --- a/test/views/after_auth_screens/profile/edit_profile_page_test.dart +++ b/test/views/after_auth_screens/profile/edit_profile_page_test.dart @@ -14,14 +14,14 @@ Widget createEditProfilePage({required EditProfilePageViewModel viewModel}) { return BaseView( onModelReady: (model) => model.initialize(), builder: (context, model, child) { - return MaterialApp( - locale: const Locale('en'), + return const MaterialApp( + locale: Locale('en'), localizationsDelegates: [ - const AppLocalizationsDelegate(isTest: true), + AppLocalizationsDelegate(isTest: true), GlobalMaterialLocalizations.delegate, GlobalWidgetsLocalizations.delegate, ], - home: const Scaffold( + home: Scaffold( key: Key('EditProfileScreenScaffold'), body: EditProfilePage(), ), @@ -37,6 +37,10 @@ void main() { registerServices(); }); + tearDownAll(() { + locator.reset(); + }); + group('EditProfilePage Tests', () { testWidgets('Check if profile image and button are displayed', (tester) async { @@ -99,10 +103,13 @@ void main() { await tester.tap(updateButton); await tester.pump(); - verify(locator().updateUserProfile( - firstName: anyNamed('firstName'), - lastName: anyNamed('lastName'), - newImage: anyNamed('newImage'))); + verify( + locator().updateUserProfile( + firstName: 'Test', + lastName: 'User', + newImage: null, + ), + ); }); testWidgets('Check if Email section is displayed', (tester) async {