diff --git a/lib/router.dart b/lib/router.dart index 86fd7f8a1..f0e069e26 100644 --- a/lib/router.dart +++ b/lib/router.dart @@ -206,7 +206,7 @@ Route generateRoute(RouteSettings settings) { // Returns the ProfilePage Widget case Routes.profilePage: return MaterialPageRoute( - builder: (context) => const ProfilePage(key: Key('Profile')), + builder: (context) => ProfilePage(key: const Key('Profile')), ); // Return the DemoProfilePage Widget diff --git a/lib/views/after_auth_screens/profile/profile_page.dart b/lib/views/after_auth_screens/profile/profile_page.dart index 5f8f2864e..e0fcbc288 100644 --- a/lib/views/after_auth_screens/profile/profile_page.dart +++ b/lib/views/after_auth_screens/profile/profile_page.dart @@ -6,11 +6,15 @@ import 'package:talawa/constants/routing_constants.dart'; import 'package:talawa/enums/enums.dart'; import 'package:talawa/locator.dart'; import 'package:talawa/models/options/options.dart'; +import 'package:talawa/models/organization/org_info.dart'; +import 'package:talawa/models/post/post_model.dart'; +import 'package:talawa/models/user/user_info.dart'; import 'package:talawa/plugins/talawa_plugin_provider.dart'; import 'package:talawa/services/size_config.dart'; import 'package:talawa/utils/app_localization.dart'; import 'package:talawa/view_model/after_auth_view_models/profile_view_models/profile_page_view_model.dart'; import 'package:talawa/view_model/main_screen_view_model.dart'; +import 'package:talawa/views/after_auth_screens/feed/individual_post.dart'; import 'package:talawa/views/base_view.dart'; import 'package:talawa/widgets/custom_avatar.dart'; import 'package:talawa/widgets/custom_list_tile.dart'; @@ -18,8 +22,9 @@ import 'package:talawa/widgets/from_palisadoes.dart'; import 'package:talawa/widgets/raised_round_edge_button.dart'; /// ProfilePage returns a widget that renders a page of user's profile. +// ignore: must_be_immutable class ProfilePage extends StatelessWidget { - const ProfilePage({ + ProfilePage({ required Key key, this.homeModel, }) : super(key: key); @@ -28,6 +33,40 @@ class ProfilePage extends StatelessWidget { /// final MainScreenViewModel? homeModel; + /// a_line_ending_with_end_punctuation. + /// + /// more_info_if_required + Post samplePost = Post( + sId: '123', + description: 'This is a sample post description.', + createdAt: DateTime.now().subtract(const Duration(days: 2)), + imageUrl: + 'https://images.unsplash.com/photo-1701725313832-d8f7fadb3006?w=600&auto=format&fit=crop&q=60&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxlZGl0b3JpYWwtZmVlZHwzfHx8ZW58MHx8fHx8', + base64String: 'base64encodedstring', + videoUrl: 'https://example.com/sample_video.mp4', + creator: User( + id: 'user123', + firstName: 'John', + lastName: 'Doe', + email: 'john.doe@example.com', + image: 'https://example.com/user_avatar.jpg', + ), + organization: OrgInfo( + id: 'org456', + name: 'Sample Organization', + description: 'This is a sample organization.', + image: 'https://example.com/org_logo.png', + ), + likedBy: [ + LikedBy(sId: 'like123'), + LikedBy(sId: 'like456'), + ], + comments: [ + Comments(sId: 'comment123'), + Comments(sId: 'comment456'), + ], + ); + @override Widget build(BuildContext context) { return BaseView( @@ -206,20 +245,7 @@ class ProfilePage extends StatelessWidget { const Tab(text: 'Tasks'), ], views: [ - ColoredBox( - color: Theme.of(context).colorScheme.background, - child: GridView.count( - mainAxisSpacing: 5, - crossAxisCount: 3, - children: [ - Image.asset('assets/images/pfp2.png'), - Image.asset('assets/images/pfp2.png'), - Image.asset('assets/images/pfp2.png'), - Image.asset('assets/images/pfp2.png'), - Image.asset('assets/images/pfp2.png'), - ], - ), - ), + IndividualPostView(post: samplePost), Container( color: Theme.of(context).colorScheme.background, ), diff --git a/test/widget_tests/after_auth_screens/profile/profile_page_test.dart b/test/widget_tests/after_auth_screens/profile/profile_page_test.dart new file mode 100644 index 000000000..5b74fd1e3 --- /dev/null +++ b/test/widget_tests/after_auth_screens/profile/profile_page_test.dart @@ -0,0 +1,201 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +// import 'package:googleapis/blogger/v3.dart'; +import 'package:mockito/mockito.dart'; +import 'package:talawa/models/post/post_model.dart'; +import 'package:talawa/services/size_config.dart'; +import '../../../helpers/test_helpers.dart'; +import '../../../helpers/test_locator.dart'; +import '../feed/individual_post_test.dart'; + +// ... (other imports) + +/// a_line_ending_with_end_punctuation. +/// +/// more_info_if_required +/// +/// **params**: +/// None +/// +/// **returns**: +/// None +void main() { + SizeConfig().test(); + testSetupLocator(); + + setUp(() { + registerServices(); + }); + + group('Test for likedUserCircleAvatar', () { + testWidgets('Check if the likedUserCircleAvatar shows up', (tester) async { + await tester.pumpWidget(createLikedUserCircleAvatarWidget()); + await tester.pump(); + + final findStack = find.byType(Stack); + + expect(findStack, findsNWidgets(2)); + }); + }); + + group('Test for IndividualPageLikeSection', () { + testWidgets('Check if the IndividualPageLikeSection shows up', + (tester) async { + await tester.pumpWidget(createIndividualPageLikeSectionWidget()); + await tester.pump(); + + final findColumn = find.byType(Column); + + expect(findColumn, findsNWidgets(1)); + }); + + testWidgets( + 'Check if the likedUserCircleAvatar in IndividualPageLikeSection shows up', + (tester) async { + await tester.pumpWidget(createIndividualPageLikeSectionWidget()); + await tester.pump(); + + final findStack = find.byType(Stack); + + expect(findStack, findsNWidgets(5)); + }); + }); + + group('Test for CommentTemplate', () { + testWidgets('Check if the CommentTemplate shows up', (tester) async { + await tester.pumpWidget(createCommentTemplateWidget()); + await tester.pump(); + + final findStack = find.byType(Row); + + expect(findStack, findsNWidgets(1)); + }); + + testWidgets('Check if the name is displayed in CommentTemplate', + (tester) async { + await tester.pumpWidget(createCommentTemplateWidget()); + await tester.pump(); + + final findStack = find.text('Ayush Chaudhary'); + + expect(findStack, findsNWidgets(1)); + }); + + testWidgets('Check if the comment text is displayed in CommentTemplate', + (tester) async { + await tester.pumpWidget(createCommentTemplateWidget()); + await tester.pump(); + + final findStack = find.text('test text'); + + expect(findStack, findsNWidgets(1)); + }); + }); + + // Add more test groups for other widgets + + group('Individualpostview tests', () { + testWidgets("Check if the IndividualPostView shows up", + (WidgetTester tester) async { + await tester.runAsync(() async { + ///making a sample data + /// also wrote all the detail + /// used in the individual post + + final commentJson1 = { + 'creator': { + '_id': '123', + 'firstName': 'Ayush', + 'lastName': 'Chaudhary', + 'email': 'test@test.com', + }, + 'createdAt': '123456', + 'text': 'test text', + 'post': 'test post', + 'likeCount': 'test count', + }; + final commentJson2 = { + 'creator': { + '_id': '123', + 'firstName': 'John', + 'lastName': 'Doe', + 'email': 'test@test.com', + }, + 'createdAt': '123456', + 'text': 'test text', + 'post': 'test post', + 'likeCount': 'test count', + }; + + final commentsJson = [commentJson1, commentJson2]; + + ///returning a service response through mocking, + ///this method was called in + ///comment view model and was returning null + ///until I made a mock response. + + when(commentsService.getCommentsForPost('PostID')) + .thenAnswer((realInvocation) async { + return commentsJson; + }); + + /// using the mock post made before me + + final Post post = getPostMockModel(); + + ///returning mock reponse of post model when + ///.likedby is called on the model + + when(post.likedBy).thenReturn([LikedBy(sId: "xzy1")]); + + await tester.pumpWidget(createIndividualPostViewWidget(post1: post)); + await tester.pump(); + + /// checking if the individual post + /// screen pops up + + expect(find.byType(Scaffold), findsNWidgets(2)); + + ///finding the text field via its ID + + final textfield = find.byKey(const Key('indi_post_tf_key')); + + /// check if the textfield shows up + + expect(textfield, findsOneWidget); + + ///finding the text field via its type + + final textbtn = find.byType(TextButton); + + ///check if btn exist + + expect(textbtn, findsOneWidget); + + ///checking if the onPressed of + ///text button is working when tapped + + await tester.tap(textbtn); + await tester.pump(); + + ///tapping the text field + ///to check if it shows up + + await tester.tap(textfield); + await tester.pump(); + + /// Checking if the submit button is working, + /// when keyboard send action is called + + await tester.showKeyboard(textfield); + + /// keyboard action can be + /// simulated using the + /// testTextInput method + + await tester.testTextInput.receiveAction(TextInputAction.send); + await tester.pump(); + }); + }); + }); +}