From 6c69d9e0877f5d2ac7f87168bbb8f08f571c7ba2 Mon Sep 17 00:00:00 2001 From: Nidhin Ninan Date: Tue, 28 Nov 2023 00:53:50 +0530 Subject: [PATCH 1/8] modified --- lib/widgets/pinned_post.dart | 47 ++++++------ .../widgets/pinned_post_test.dart | 71 +++++++++++++++++++ 2 files changed, 98 insertions(+), 20 deletions(-) create mode 100644 test/widget_tests/widgets/pinned_post_test.dart diff --git a/lib/widgets/pinned_post.dart b/lib/widgets/pinned_post.dart index c1bcab9d2..de3bd79f0 100644 --- a/lib/widgets/pinned_post.dart +++ b/lib/widgets/pinned_post.dart @@ -12,7 +12,7 @@ class PinnedPost extends StatelessWidget { /// contains the pinned post. /// - final List pinnedPost; + final List? pinnedPost; /// a_line_ending_with_end_punctuation. /// @@ -86,6 +86,7 @@ class PinnedPost extends StatelessWidget { @override Widget build(BuildContext context) { return Container( + key: const Key('hello'), child: pinnedPosts.isNotEmpty ? SizedBox( height: SizeConfig.screenHeight! * 0.25, @@ -109,28 +110,32 @@ class PinnedPost extends StatelessWidget { width: SizeConfig.screenWidth! / 4.1, child: Column( children: [ - CachedNetworkImage( - cacheKey: pinnedPosts[index]['postId'], - imageUrl: - (pinnedPosts[index]['imageUrl'] ?? '').isEmpty - ? 'placeHolderUrl' - : pinnedPosts[index]['imageUrl']!, - errorWidget: (context, url, error) { - return const CircularProgressIndicator(); - }, - height: SizeConfig.screenHeight! * 0.15, - fit: BoxFit.cover, + Expanded( + child: CachedNetworkImage( + cacheKey: pinnedPosts[index]['postId'], + imageUrl: + (pinnedPosts[index]['imageUrl'] ?? '').isEmpty + ? 'placeHolderUrl' + : pinnedPosts[index]['imageUrl']!, + errorWidget: (context, url, error) { + return const CircularProgressIndicator(); + }, + height: SizeConfig.screenHeight! * 0.15, + fit: BoxFit.cover, + ), ), const SizedBox(height: 5), Row( children: [ - Padding( - padding: const EdgeInsets.all(8.0), - child: Text( - '${pinnedPosts[index]['time']!}hr', - style: const TextStyle( - color: Colors.grey, - fontWeight: FontWeight.w200, + Expanded( + child: Padding( + padding: const EdgeInsets.all(8.0), + child: Text( + '${pinnedPosts[index]['time']!}hr', + style: const TextStyle( + color: Colors.grey, + fontWeight: FontWeight.w200, + ), ), ), ), @@ -149,7 +154,9 @@ class PinnedPost extends StatelessWidget { ), ), ) - : Container(), + : Container( + + ), ); } } diff --git a/test/widget_tests/widgets/pinned_post_test.dart b/test/widget_tests/widgets/pinned_post_test.dart new file mode 100644 index 000000000..3fda5c58f --- /dev/null +++ b/test/widget_tests/widgets/pinned_post_test.dart @@ -0,0 +1,71 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:talawa/demo_server_data/pinned_post_demo_data.dart'; +import 'package:talawa/locator.dart'; +import 'package:talawa/models/post/post_model.dart'; +import 'package:talawa/services/size_config.dart'; +import 'package:talawa/widgets/pinned_post.dart'; + +import '../../helpers/test_helpers.dart'; + +/// List of pinned posts. These are posts that have been marked as important. +List _pinnedPosts = + pinnedPostsDemoData.map((e) => Post.fromJson(e)).toList(); + +/// getter for pinned post. +/// +/// **params**: + +List get pinnedPosts { + return _pinnedPosts; +} + +/// main function. +/// +/// **params**: +/// None +/// +/// **returns**: +/// None +void main() { + setupLocator(); + locator().test(); + setUp(() { + registerServices(); + locator().test(); + }); + tearDown(() { + unregisterServices(); + }); + + testWidgets('If conatiner is coming on calling pinnedwidget', + (widgetTester) async { + await widgetTester.pumpWidget( + MaterialApp( + home: PinnedPost(pinnedPost: pinnedPosts), + ), + ); + await widgetTester.pumpAndSettle(); + expect(find.byKey(const Key('hello')), findsOneWidget); + }); + + testWidgets('Text widget is present when there are pinned posts', (widgetTester) async { + await widgetTester.pumpWidget( + MaterialApp( + home: PinnedPost(pinnedPost: pinnedPosts), + ), + ); + await widgetTester.pumpAndSettle(); + expect(find.byType(Text), findsWidgets); +}); + +testWidgets('Text widget displays the correct text', (widgetTester) async { + await widgetTester.pumpWidget( + MaterialApp( + home: PinnedPost(pinnedPost: pinnedPosts), + ), + ); + await widgetTester.pumpAndSettle(); + expect(find.text('Church Meeting'), findsOneWidget); +}); +} From cfd76a8bc8bc9abd9aaa2aadccd0a305e3ef51d6 Mon Sep 17 00:00:00 2001 From: Nidhin Ninan Date: Tue, 28 Nov 2023 00:59:46 +0530 Subject: [PATCH 2/8] modified --- test/widget_tests/widgets/pinned_post_test.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/widget_tests/widgets/pinned_post_test.dart b/test/widget_tests/widgets/pinned_post_test.dart index 3fda5c58f..e4317af1b 100644 --- a/test/widget_tests/widgets/pinned_post_test.dart +++ b/test/widget_tests/widgets/pinned_post_test.dart @@ -8,7 +8,7 @@ import 'package:talawa/widgets/pinned_post.dart'; import '../../helpers/test_helpers.dart'; -/// List of pinned posts. These are posts that have been marked as important. +/// List of pinned posts. List _pinnedPosts = pinnedPostsDemoData.map((e) => Post.fromJson(e)).toList(); From 39d818eb8761ea306f02cd68f8d6fae86aad310d Mon Sep 17 00:00:00 2001 From: Nidhin Ninan Date: Tue, 28 Nov 2023 17:45:56 +0530 Subject: [PATCH 3/8] modified --- test/widget_tests/widgets/pinned_post_test.dart | 1 + 1 file changed, 1 insertion(+) diff --git a/test/widget_tests/widgets/pinned_post_test.dart b/test/widget_tests/widgets/pinned_post_test.dart index e4317af1b..9ab5cbca6 100644 --- a/test/widget_tests/widgets/pinned_post_test.dart +++ b/test/widget_tests/widgets/pinned_post_test.dart @@ -68,4 +68,5 @@ testWidgets('Text widget displays the correct text', (widgetTester) async { await widgetTester.pumpAndSettle(); expect(find.text('Church Meeting'), findsOneWidget); }); + } From 090238ed8b6962cf17226c4f8c3eb8324d1617f9 Mon Sep 17 00:00:00 2001 From: Nidhin Ninan Date: Tue, 28 Nov 2023 18:08:58 +0530 Subject: [PATCH 4/8] modified --- lib/widgets/pinned_post.dart | 6 ++---- test/widget_tests/widgets/pinned_post_test.dart | 1 - 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/lib/widgets/pinned_post.dart b/lib/widgets/pinned_post.dart index de3bd79f0..9aeae3577 100644 --- a/lib/widgets/pinned_post.dart +++ b/lib/widgets/pinned_post.dart @@ -12,7 +12,7 @@ class PinnedPost extends StatelessWidget { /// contains the pinned post. /// - final List? pinnedPost; + final List pinnedPost; /// a_line_ending_with_end_punctuation. /// @@ -154,9 +154,7 @@ class PinnedPost extends StatelessWidget { ), ), ) - : Container( - - ), + : Container(), ); } } diff --git a/test/widget_tests/widgets/pinned_post_test.dart b/test/widget_tests/widgets/pinned_post_test.dart index 9ab5cbca6..e4317af1b 100644 --- a/test/widget_tests/widgets/pinned_post_test.dart +++ b/test/widget_tests/widgets/pinned_post_test.dart @@ -68,5 +68,4 @@ testWidgets('Text widget displays the correct text', (widgetTester) async { await widgetTester.pumpAndSettle(); expect(find.text('Church Meeting'), findsOneWidget); }); - } From 456dffacbaadd880f051c57d279b83a38561190a Mon Sep 17 00:00:00 2001 From: Nidhin Ninan Date: Tue, 28 Nov 2023 18:25:23 +0530 Subject: [PATCH 5/8] modified --- .../widgets/pinned_post_test.dart | 45 ++++++++++--------- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/test/widget_tests/widgets/pinned_post_test.dart b/test/widget_tests/widgets/pinned_post_test.dart index e4317af1b..8c2118c01 100644 --- a/test/widget_tests/widgets/pinned_post_test.dart +++ b/test/widget_tests/widgets/pinned_post_test.dart @@ -13,18 +13,18 @@ List _pinnedPosts = pinnedPostsDemoData.map((e) => Post.fromJson(e)).toList(); /// getter for pinned post. -/// +/// /// **params**: - + List get pinnedPosts { return _pinnedPosts; } /// main function. -/// +/// /// **params**: /// None -/// +/// /// **returns**: /// None void main() { @@ -49,23 +49,24 @@ void main() { expect(find.byKey(const Key('hello')), findsOneWidget); }); - testWidgets('Text widget is present when there are pinned posts', (widgetTester) async { - await widgetTester.pumpWidget( - MaterialApp( - home: PinnedPost(pinnedPost: pinnedPosts), - ), - ); - await widgetTester.pumpAndSettle(); - expect(find.byType(Text), findsWidgets); -}); + testWidgets('Text widget is present when there are pinned posts', + (widgetTester) async { + await widgetTester.pumpWidget( + MaterialApp( + home: PinnedPost(pinnedPost: pinnedPosts), + ), + ); + await widgetTester.pumpAndSettle(); + expect(find.byType(Text), findsWidgets); + }); -testWidgets('Text widget displays the correct text', (widgetTester) async { - await widgetTester.pumpWidget( - MaterialApp( - home: PinnedPost(pinnedPost: pinnedPosts), - ), - ); - await widgetTester.pumpAndSettle(); - expect(find.text('Church Meeting'), findsOneWidget); -}); + testWidgets('Text widget displays the correct text', (widgetTester) async { + await widgetTester.pumpWidget( + MaterialApp( + home: PinnedPost(pinnedPost: pinnedPosts), + ), + ); + await widgetTester.pumpAndSettle(); + expect(find.text('Church Meeting'), findsOneWidget); + }); } From 960d334d1fc4015be3c6b0b9e776a6aa46d097a9 Mon Sep 17 00:00:00 2001 From: Nidhin Ninan Date: Tue, 28 Nov 2023 21:21:42 +0530 Subject: [PATCH 6/8] modified --- lib/widgets/pinned_post.dart | 9 +++++---- .../widgets/pinned_post_test.dart | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/lib/widgets/pinned_post.dart b/lib/widgets/pinned_post.dart index 9aeae3577..5a0e1e2e5 100644 --- a/lib/widgets/pinned_post.dart +++ b/lib/widgets/pinned_post.dart @@ -3,6 +3,7 @@ import 'package:flutter/material.dart'; import 'package:talawa/locator.dart'; import 'package:talawa/models/post/post_model.dart'; import 'package:talawa/services/size_config.dart'; +import 'package:talawa/views/after_auth_screens/feed/pinned_post_screen.dart'; /// a_line_ending_with_end_punctuation. /// @@ -101,10 +102,10 @@ class PinnedPost extends StatelessWidget { child: GestureDetector( onTap: () { // final Map arg = {"index": "$index","post": pinnedPosts}; - navigationService.pushScreen( - '/pinnedpostscreen', - arguments: pinnedPosts[index], - ); + Navigator.of(context).push(MaterialPageRoute( + builder: (context) => + PinnedPostScreen(post: pinnedPosts[index]), + )); }, child: SizedBox( width: SizeConfig.screenWidth! / 4.1, diff --git a/test/widget_tests/widgets/pinned_post_test.dart b/test/widget_tests/widgets/pinned_post_test.dart index 8c2118c01..b3bbf1666 100644 --- a/test/widget_tests/widgets/pinned_post_test.dart +++ b/test/widget_tests/widgets/pinned_post_test.dart @@ -1,9 +1,12 @@ import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; +import 'package:mockito/mockito.dart'; import 'package:talawa/demo_server_data/pinned_post_demo_data.dart'; import 'package:talawa/locator.dart'; import 'package:talawa/models/post/post_model.dart'; +import 'package:talawa/services/navigation_service.dart'; import 'package:talawa/services/size_config.dart'; +import 'package:talawa/views/after_auth_screens/feed/pinned_post_screen.dart'; import 'package:talawa/widgets/pinned_post.dart'; import '../../helpers/test_helpers.dart'; @@ -28,11 +31,14 @@ List get pinnedPosts { /// **returns**: /// None void main() { + TestWidgetsFlutterBinding.ensureInitialized(); setupLocator(); locator().test(); + NavigationService navigationService; setUp(() { registerServices(); locator().test(); + navigationService = NavigationService(); }); tearDown(() { unregisterServices(); @@ -69,4 +75,17 @@ void main() { await widgetTester.pumpAndSettle(); expect(find.text('Church Meeting'), findsOneWidget); }); + + testWidgets('Tapping on a post triggers navigation', (widgetTester) async { + await widgetTester.pumpWidget( + MaterialApp( + home: PinnedPost(pinnedPost: pinnedPosts), + ), + ); + await widgetTester.pump(); + await widgetTester.tap(find.text('1hr')); + await widgetTester.pumpAndSettle(); + expect(find.byType(PinnedPost), findsNothing); + expect(find.byType(PinnedPostScreen), findsOneWidget); + }); } From 758f878ca2e5d857f02cbd31b293c57e7a3bf969 Mon Sep 17 00:00:00 2001 From: Nidhin Ninan Date: Tue, 28 Nov 2023 21:26:42 +0530 Subject: [PATCH 7/8] modified --- lib/widgets/pinned_post.dart | 11 ++++++----- test/widget_tests/widgets/pinned_post_test.dart | 4 ---- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/lib/widgets/pinned_post.dart b/lib/widgets/pinned_post.dart index 5a0e1e2e5..b16b8780b 100644 --- a/lib/widgets/pinned_post.dart +++ b/lib/widgets/pinned_post.dart @@ -1,6 +1,5 @@ import 'package:cached_network_image/cached_network_image.dart'; import 'package:flutter/material.dart'; -import 'package:talawa/locator.dart'; import 'package:talawa/models/post/post_model.dart'; import 'package:talawa/services/size_config.dart'; import 'package:talawa/views/after_auth_screens/feed/pinned_post_screen.dart'; @@ -102,10 +101,12 @@ class PinnedPost extends StatelessWidget { child: GestureDetector( onTap: () { // final Map arg = {"index": "$index","post": pinnedPosts}; - Navigator.of(context).push(MaterialPageRoute( - builder: (context) => - PinnedPostScreen(post: pinnedPosts[index]), - )); + Navigator.of(context).push( + MaterialPageRoute( + builder: (context) => + PinnedPostScreen(post: pinnedPosts[index]), + ), + ); }, child: SizedBox( width: SizeConfig.screenWidth! / 4.1, diff --git a/test/widget_tests/widgets/pinned_post_test.dart b/test/widget_tests/widgets/pinned_post_test.dart index b3bbf1666..8ba3ae445 100644 --- a/test/widget_tests/widgets/pinned_post_test.dart +++ b/test/widget_tests/widgets/pinned_post_test.dart @@ -1,10 +1,8 @@ import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; -import 'package:mockito/mockito.dart'; import 'package:talawa/demo_server_data/pinned_post_demo_data.dart'; import 'package:talawa/locator.dart'; import 'package:talawa/models/post/post_model.dart'; -import 'package:talawa/services/navigation_service.dart'; import 'package:talawa/services/size_config.dart'; import 'package:talawa/views/after_auth_screens/feed/pinned_post_screen.dart'; import 'package:talawa/widgets/pinned_post.dart'; @@ -34,11 +32,9 @@ void main() { TestWidgetsFlutterBinding.ensureInitialized(); setupLocator(); locator().test(); - NavigationService navigationService; setUp(() { registerServices(); locator().test(); - navigationService = NavigationService(); }); tearDown(() { unregisterServices(); From 742e6f26ac0479fb1acf308fe10339b31a1d9195 Mon Sep 17 00:00:00 2001 From: Nidhin Ninan Date: Wed, 29 Nov 2023 17:13:27 +0530 Subject: [PATCH 8/8] modified --- test/widget_tests/widgets/pinned_post_test.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/widget_tests/widgets/pinned_post_test.dart b/test/widget_tests/widgets/pinned_post_test.dart index 8ba3ae445..d2f038d4f 100644 --- a/test/widget_tests/widgets/pinned_post_test.dart +++ b/test/widget_tests/widgets/pinned_post_test.dart @@ -79,7 +79,7 @@ void main() { ), ); await widgetTester.pump(); - await widgetTester.tap(find.text('1hr')); + await widgetTester.tap(find.text('Church Meeting')); await widgetTester.pumpAndSettle(); expect(find.byType(PinnedPost), findsNothing); expect(find.byType(PinnedPostScreen), findsOneWidget);