From a1cf1f6513cdb693cbefc901806f029de0a71706 Mon Sep 17 00:00:00 2001 From: Glen Dsouza Date: Sat, 4 May 2024 22:59:13 +0530 Subject: [PATCH] Fix UI Theme issues in Light/Dark Mode (#2501) * Fix UI issues in Light Mode * remove comments from explore_events.dart * Add Missing Trailing comma * Add tests for post_widget * Add trailing comma --- lib/constants/custom_theme.dart | 20 +- .../app_settings/app_settings_page.dart | 10 +- .../events/explore_events.dart | 92 ++- .../feed/organization_feed.dart | 11 +- .../profile/profile_page.dart | 23 +- lib/views/pre_auth_screens/login.dart | 2 +- lib/views/pre_auth_screens/set_url.dart | 3 +- lib/widgets/custom_alert_dialog.dart | 3 +- lib/widgets/custom_avatar.dart | 9 +- lib/widgets/event_card.dart | 1 + lib/widgets/post_detailed_page.dart | 34 +- lib/widgets/post_list_widget.dart | 6 +- lib/widgets/post_modal.dart | 43 +- lib/widgets/post_widget.dart | 132 ++-- .../app_settings/app_setting_page_test.dart | 6 +- .../pre_auth_screens/set_url_page_test.dart | 218 +++++-- .../widgets/post_widget_test.dart | 603 +++--------------- 17 files changed, 397 insertions(+), 819 deletions(-) diff --git a/lib/constants/custom_theme.dart b/lib/constants/custom_theme.dart index 15909e59d..8f01eee81 100644 --- a/lib/constants/custom_theme.dart +++ b/lib/constants/custom_theme.dart @@ -1,9 +1,7 @@ -// ignore_for_file: talawa_api_doc -// ignore_for_file: talawa_good_doc_comments - import 'package:flutter/material.dart'; ///This file contains various custom themes. +/// ///For instance, lightTheme, darkTheme, _lightTextTheme, _darkTextTheme, etc. ///These are imported to other files/widgets to apply the required themes. class TalawaTheme { @@ -25,6 +23,7 @@ class TalawaTheme { static const Color _darkInWhite = Color(0xffffffff); static const Color _darkColorSchemePrimary = Color(0xfffabc57); + /// Theme for light mode. static final lightTheme = ThemeData( scaffoldBackgroundColor: _lightScaffoldColor, textSelectionTheme: const TextSelectionThemeData( @@ -41,10 +40,14 @@ class TalawaTheme { primaryContainer: _lightPrimaryVariantColor, primary: _lightColorSchemePrimary, secondary: Color(0xffF5F5F5), + onSecondary: Colors.black, secondaryContainer: _darkScaffoldColor, + tertiary: Colors.black26, + tertiaryContainer: Color.fromARGB(255, 231, 231, 231), ).copyWith(secondary: _lightAccentColor), ); + /// Theme for dark mode. static final darkTheme = ThemeData( textSelectionTheme: const TextSelectionThemeData( cursorColor: _darkCursorColor, @@ -61,7 +64,10 @@ class TalawaTheme { primaryContainer: _darkPrimaryVariantColor, primary: _darkColorSchemePrimary, secondary: Colors.black, + onSecondary: Colors.white, secondaryContainer: _lightScaffoldColor, + tertiary: Colors.white70, + tertiaryContainer: Color.fromARGB(255, 61, 61, 61), ).copyWith(secondary: _darkAccentColor), ); @@ -78,12 +84,8 @@ class TalawaTheme { fontSize: 16, color: Color(0xFF737373), ), - bodyLarge: TextStyle( - fontSize: 14, - ), - bodyMedium: TextStyle( - fontSize: 14, - ), + bodyLarge: TextStyle(fontSize: 14, color: Color(0xFF737373)), + bodyMedium: TextStyle(fontSize: 14), bodySmall: TextStyle( fontWeight: FontWeight.w400, color: Color(0xFF737373), diff --git a/lib/views/after_auth_screens/app_settings/app_settings_page.dart b/lib/views/after_auth_screens/app_settings/app_settings_page.dart index 3398a51e1..c718f5cb8 100644 --- a/lib/views/after_auth_screens/app_settings/app_settings_page.dart +++ b/lib/views/after_auth_screens/app_settings/app_settings_page.dart @@ -22,10 +22,6 @@ class AppSettingsPage extends StatelessWidget { @override Widget build(BuildContext context) { - // Scaffold implements the basic Material Design visual layout structure. - //Learn more about Scaffold class - //[here](https://api.flutter.dev/flutter/material/Scaffold-class.html). - // const String _talawaWebsite = ''; const String talawaDocs = 'https://docs.talawa.io'; const String talawaGithub = 'https://github.com/PalisadoesFoundation/talawa'; @@ -59,10 +55,6 @@ class AppSettingsPage extends StatelessWidget { child: Column( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ - // SizedBox( - // height: SizeConfig.screenHeight! * 0.77, - // child: - // ), Flexible( child: SingleChildScrollView( scrollDirection: Axis.vertical, @@ -299,7 +291,7 @@ class AppSettingsPage extends StatelessWidget { return CustomAlertDialog( reverse: true, dialogSubTitle: 'Are you sure you want to logout?', - successText: 'LogOut', + successText: 'Logout', success: () async { try { final bool isLogoutSuccessful = diff --git a/lib/views/after_auth_screens/events/explore_events.dart b/lib/views/after_auth_screens/events/explore_events.dart index 119b31553..16fe3561d 100644 --- a/lib/views/after_auth_screens/events/explore_events.dart +++ b/lib/views/after_auth_screens/events/explore_events.dart @@ -18,7 +18,7 @@ class ExploreEvents extends StatelessWidget { this.homeModel, }) : super(key: key); - /// [homeModal] is a type of [MainScreenViewModel] which provides methods to handle the data for this component. + /// Represents the view model for the home screen. final MainScreenViewModel? homeModel; @override @@ -28,8 +28,7 @@ class ExploreEvents extends StatelessWidget { builder: (context, model, child) { return Scaffold( appBar: AppBar( - // AppBar returns widget for the header. - backgroundColor: Theme.of(context).primaryColor, + backgroundColor: Colors.green, key: const Key( "ExploreEventsAppBar", ), @@ -43,13 +42,11 @@ class ExploreEvents extends StatelessWidget { style: Theme.of(context).textTheme.titleLarge!.copyWith( fontWeight: FontWeight.w600, fontSize: 20, + color: Colors.white, ), ), leading: IconButton( - // returns a button of menu icon to redirect to home. - color: Theme.of( - context, - ).iconTheme.color, + color: Colors.white, icon: const Icon( Icons.menu, ), @@ -61,7 +58,6 @@ class ExploreEvents extends StatelessWidget { padding: EdgeInsets.only( right: SizeConfig.screenWidth! * 0.027, ), - // if the events is not empty then renders button for searching the events else renders just a box. child: model.events.isNotEmpty ? IconButton( onPressed: () { @@ -73,17 +69,15 @@ class ExploreEvents extends StatelessWidget { ), ); }, - icon: Icon( + icon: const Icon( Icons.search, - size: (SizeConfig.safeBlockHorizontal ?? 4) * 5, + color: Colors.white, ), ) : const SizedBox(), ), ], ), - // if the model is still fetching the events list then renders the Circular Progress Indicator - // else render refresh icon along with the list of searched events for exploration. body: model.isBusy ? const Center( child: CircularProgressIndicator(), @@ -100,6 +94,9 @@ class ExploreEvents extends StatelessWidget { ), child: Column( children: [ + SizedBox( + height: SizeConfig.screenHeight! * 0.013, + ), Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, @@ -107,27 +104,24 @@ class ExploreEvents extends StatelessWidget { Expanded( flex: 2, child: GestureDetector( - onTap: () { - showModalBottomSheet( - context: context, - builder: (_) { - return dropDownList( - model, - context, - ); - }, - ); - }, + onTap: () => showModalBottomSheet( + backgroundColor: Colors.white, + context: context, + builder: (_) => dropDownList( + model, + context, + ), + ), child: Card( + surfaceTintColor: Theme.of(context) + .colorScheme + .secondaryContainer, color: Theme.of(context) .colorScheme .onPrimary, child: Container( - padding: EdgeInsets.symmetric( - vertical: (SizeConfig - .safeBlockHorizontal ?? - 4) * - 3, + padding: const EdgeInsets.symmetric( + vertical: 12, ), child: Row( mainAxisAlignment: @@ -156,30 +150,25 @@ class ExploreEvents extends StatelessWidget { Expanded( flex: 3, child: GestureDetector( - onTap: () { - showDialog( - // on tap open the Explore Event Dialog. - context: context, - builder: (_) { - return const ExploreEventDialog( - key: Key('ExploreEvents'), - ); - }, - ); - }, + onTap: () => showDialog( + context: context, + builder: (_) => + const ExploreEventDialog( + key: Key('ExploreEvents'), + ), + ), child: Card( + surfaceTintColor: Theme.of(context) + .colorScheme + .secondaryContainer, key: homeModel?.keySEDateFilter, color: Theme.of(context) .colorScheme .onPrimary, child: Container( - padding: EdgeInsets.symmetric( - vertical: (SizeConfig - .safeBlockHorizontal ?? - 4) * - 3, + padding: const EdgeInsets.symmetric( + vertical: 12, ), - // width: SizeConfig.screenWidth! * 0.30, child: Row( mainAxisAlignment: MainAxisAlignment.spaceEvenly, @@ -215,6 +204,9 @@ class ExploreEvents extends StatelessWidget { Expanded( flex: 1, child: Card( + surfaceTintColor: Theme.of(context) + .colorScheme + .secondaryContainer, color: Theme.of(context) .colorScheme .onPrimary, @@ -234,10 +226,8 @@ class ExploreEvents extends StatelessWidget { ], ), SizedBox( - height: SizeConfig.screenHeight! * 0.027, + height: SizeConfig.screenHeight! * 0.020, ), - // if the events model is empty then renders a box with text as "Empty List" - // else renders lists of the all event tile. model.events.isEmpty ? SizedBox( height: SizeConfig.screenHeight! * 0.5, @@ -285,11 +275,7 @@ class ExploreEvents extends StatelessWidget { key: homeModel?.keySEAdd, heroTag: "AddEventFab", backgroundColor: Theme.of(context).colorScheme.background, - onPressed: () { - navigationService.pushScreen( - "/createEventPage", - ); - }, + onPressed: () => navigationService.pushScreen("/createEventPage"), icon: Icon( Icons.add, color: Theme.of(context).colorScheme.secondary, diff --git a/lib/views/after_auth_screens/feed/organization_feed.dart b/lib/views/after_auth_screens/feed/organization_feed.dart index 1aabe61af..5913f121e 100644 --- a/lib/views/after_auth_screens/feed/organization_feed.dart +++ b/lib/views/after_auth_screens/feed/organization_feed.dart @@ -60,24 +60,23 @@ class _OrganizationFeedState extends State { ), ), appBar: AppBar( - // AppBar returns a widget for the header of the page. backgroundColor: Colors.green, - // Theme.of(context).primaryColor, elevation: 0.0, centerTitle: true, title: Text( model.currentOrgName, key: widget.homeModel?.keySHOrgName, style: Theme.of(context).textTheme.titleLarge!.copyWith( + fontWeight: FontWeight.w600, fontSize: 20, color: Colors.white, ), ), leading: IconButton( key: widget.homeModel?.keySHMenuIcon, - icon: Icon( + icon: const Icon( Icons.menu, - color: Theme.of(context).iconTheme.color, + color: Colors.white, ), onPressed: () { MainScreenViewModel.scaffoldKey.currentState!.openDrawer(); @@ -132,7 +131,9 @@ class _OrganizationFeedState extends State { pinnedPost: model.pinnedPosts, model: widget.homeModel!, ), - // Show PostListWidget if there are posts, otherwise show the 'no posts' message + SizedBox( + height: SizeConfig.screenHeight! * 0.01, + ), model.posts.isNotEmpty ? PostListWidget( key: widget.homeModel?.keySHPost, diff --git a/lib/views/after_auth_screens/profile/profile_page.dart b/lib/views/after_auth_screens/profile/profile_page.dart index 9accd7066..fa43731b2 100644 --- a/lib/views/after_auth_screens/profile/profile_page.dart +++ b/lib/views/after_auth_screens/profile/profile_page.dart @@ -22,8 +22,7 @@ class ProfilePage extends StatelessWidget { this.homeModel, }) : super(key: key); - /// MainScreenViewModel. - /// + /// represents MainScreenViewModel. final MainScreenViewModel? homeModel; @override @@ -35,11 +34,10 @@ class ProfilePage extends StatelessWidget { key: model.scaffoldKey, appBar: AppBar( backgroundColor: Colors.green, - // Theme.of(context).primaryColor, elevation: 0.0, centerTitle: true, leading: IconButton( - color: Theme.of(context).iconTheme.color, + color: Colors.white, icon: const Icon(Icons.menu), onPressed: () => MainScreenViewModel.scaffoldKey.currentState!.openDrawer(), @@ -48,9 +46,8 @@ class ProfilePage extends StatelessWidget { title: Text( AppLocalizations.of(context)!.strictTranslate('Profile'), style: Theme.of(context).textTheme.titleLarge!.copyWith( - // fontWeight: FontWeight.w600, - fontSize: SizeConfig.screenHeight! * 0.03, - fontFamily: 'open-sans', + fontWeight: FontWeight.w600, + fontSize: 20, color: Colors.white, ), ), @@ -60,7 +57,10 @@ class ProfilePage extends StatelessWidget { onPressed: () { navigationService.pushScreen(Routes.appSettings); }, - icon: const Icon(Icons.settings), + icon: const Icon( + Icons.settings, + color: Colors.white, + ), ), ], ), @@ -103,9 +103,7 @@ class ProfilePage extends StatelessWidget { child: Text( '${model.currentUser.firstName!} ${model.currentUser.lastName!}', style: TextStyle( - color: Colors.white, fontSize: SizeConfig.screenHeight! * 0.025, - fontFamily: 'open-sans', ), ), ), @@ -144,9 +142,8 @@ class ProfilePage extends StatelessWidget { .focusedBorder! .borderSide .color, - backgroundColor: Theme.of(context) - .colorScheme - .secondaryContainer, + backgroundColor: + Theme.of(context).colorScheme.tertiary, ), ], ), diff --git a/lib/views/pre_auth_screens/login.dart b/lib/views/pre_auth_screens/login.dart index 2fc9b39fa..6495c6cd4 100644 --- a/lib/views/pre_auth_screens/login.dart +++ b/lib/views/pre_auth_screens/login.dart @@ -183,7 +183,7 @@ class _LoginState extends State { onTap: () => model.login(), textColor: const Color(0xFF008A37), key: const Key('LoginButton'), - backgroundColor: Colors.white, + backgroundColor: Theme.of(context).colorScheme.tertiary, ), SizedBox(height: SizeConfig.screenHeight! * 0.0215), ], diff --git a/lib/views/pre_auth_screens/set_url.dart b/lib/views/pre_auth_screens/set_url.dart index 3e123aaa6..520811c85 100644 --- a/lib/views/pre_auth_screens/set_url.dart +++ b/lib/views/pre_auth_screens/set_url.dart @@ -156,8 +156,7 @@ class _SetUrlState extends State { .focusedBorder! .borderSide .color, - backgroundColor: - Theme.of(context).colorScheme.secondaryContainer, + backgroundColor: Theme.of(context).colorScheme.tertiary, ), SizedBox( height: SizeConfig.screenHeight! * 0.0215, diff --git a/lib/widgets/custom_alert_dialog.dart b/lib/widgets/custom_alert_dialog.dart index 312c3d47d..7b434365e 100644 --- a/lib/widgets/custom_alert_dialog.dart +++ b/lib/widgets/custom_alert_dialog.dart @@ -74,12 +74,13 @@ class CustomAlertDialog extends StatelessWidget { onTap: () => success(), buttonLabel: AppLocalizations.of(context)!.strictTranslate(successText), textColor: const Color(0xFF008A37), - backgroundColor: Colors.white, + backgroundColor: Theme.of(context).colorScheme.tertiary, width: SizeConfig.screenWidth! * 0.2, height: SizeConfig.screenHeight! * 0.06, ), ]; return AlertDialog( + surfaceTintColor: Theme.of(context).colorScheme.secondaryContainer, title: Text( AppLocalizations.of(context)!.strictTranslate(dialogTitle), style: Theme.of(context) diff --git a/lib/widgets/custom_avatar.dart b/lib/widgets/custom_avatar.dart index 9126cd49b..7d8ce4343 100644 --- a/lib/widgets/custom_avatar.dart +++ b/lib/widgets/custom_avatar.dart @@ -1,4 +1,3 @@ -// ignore_for_file: talawa_good_doc_comments, talawa_api_doc import 'package:cached_network_image/cached_network_image.dart'; import 'package:flutter/material.dart'; import 'package:flutter_cache_manager/flutter_cache_manager.dart'; @@ -48,10 +47,10 @@ class CustomAvatar extends StatelessWidget { child: Center( child: Text( firstAlphabet!, - style: Theme.of(context) - .textTheme - .bodySmall! - .copyWith(fontSize: fontSize), + style: Theme.of(context).textTheme.bodySmall!.copyWith( + fontSize: fontSize, + color: Theme.of(context).colorScheme.onSecondary, + ), ), ), ) diff --git a/lib/widgets/event_card.dart b/lib/widgets/event_card.dart index 6e1691b5c..52480d78b 100644 --- a/lib/widgets/event_card.dart +++ b/lib/widgets/event_card.dart @@ -36,6 +36,7 @@ class EventCard extends StatelessWidget { child: Stack( children: [ Card( + surfaceTintColor: Theme.of(context).colorScheme.secondaryContainer, shape: RoundedRectangleBorder( side: isRegistered && userConfig.currentUser.id != event.creator!.id diff --git a/lib/widgets/post_detailed_page.dart b/lib/widgets/post_detailed_page.dart index aad904c8d..42dbf68eb 100644 --- a/lib/widgets/post_detailed_page.dart +++ b/lib/widgets/post_detailed_page.dart @@ -1,4 +1,3 @@ -// ignore_for_file: talawa_good_doc_comments, talawa_api_doc import 'package:flutter/material.dart'; import 'package:talawa/utils/app_localization.dart'; @@ -11,7 +10,6 @@ class DescriptionTextWidget extends StatefulWidget { const DescriptionTextWidget({required this.text}); /// actual description to be displayed. - /// final String text; @override @@ -20,23 +18,15 @@ class DescriptionTextWidget extends StatefulWidget { class _DescriptionTextWidgetState extends State { /// before clicking show more. - /// - /// late String firstHalf; /// After the show more. - /// - /// late String secondHalf; /// tags in the post. - /// late String tag; - //setting the flag to true initially - /// is show more turned on. - /// - /// + /// setting the flag to true initially (is show more turned on). bool flag = true; @override @@ -65,23 +55,24 @@ class _DescriptionTextWidgetState extends State { @override Widget build(BuildContext context) { return Container( - padding: const EdgeInsets.symmetric(horizontal: 10.0, vertical: 5.0), + padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 5.0), child: secondHalf.isEmpty ? Column( children: [ Text( firstHalf, - style: Theme.of(context) - .textTheme - .bodyMedium! - .copyWith(fontFamily: 'open-sans', color: Colors.black38), + textAlign: TextAlign.justify, + style: Theme.of(context).textTheme.bodyMedium!.copyWith( + fontFamily: 'open-sans', + color: Theme.of(context).colorScheme.onSecondary, + ), ), tag != "" ? Text( "# $tag", style: Theme.of(context).textTheme.bodyMedium!.copyWith( fontFamily: 'open-sans', - color: Colors.black38, + color: Theme.of(context).colorScheme.onSecondary, ), ) : Container(), @@ -93,10 +84,11 @@ class _DescriptionTextWidgetState extends State { // If the flag is true, we only display the firstHalf. // If it is false, we display the entire text. flag ? ("$firstHalf...") : (firstHalf + secondHalf), - style: Theme.of(context) - .textTheme - .bodyMedium! - .copyWith(fontFamily: 'open-sans'), + textAlign: TextAlign.justify, + style: Theme.of(context).textTheme.bodyMedium!.copyWith( + fontFamily: 'open-sans', + color: Theme.of(context).colorScheme.onSecondary, + ), ), Row( mainAxisAlignment: MainAxisAlignment.end, diff --git a/lib/widgets/post_list_widget.dart b/lib/widgets/post_list_widget.dart index 5f0cd08b7..2364e16a6 100644 --- a/lib/widgets/post_list_widget.dart +++ b/lib/widgets/post_list_widget.dart @@ -11,17 +11,13 @@ class PostListWidget extends StatelessWidget { this.deletePost, }); - /// lis of all the post. - /// + /// list of all the post. final List posts; /// This function is passed for the handling the action to be performed when the comment button is clicked. - /// - /// to see the function check the place where the widget is called. final Function(Post)? function; /// Function the deleting the post. - /// final Function(Post)? deletePost; @override diff --git a/lib/widgets/post_modal.dart b/lib/widgets/post_modal.dart index 6a47c9e00..d26a8c226 100644 --- a/lib/widgets/post_modal.dart +++ b/lib/widgets/post_modal.dart @@ -4,8 +4,6 @@ import 'package:talawa/locator.dart'; import 'package:talawa/models/post/post_model.dart'; /// To add options to the bottom nav bar, increase the height too. -/// -/// class PostBottomModal extends StatelessWidget { const PostBottomModal({ super.key, @@ -15,18 +13,12 @@ class PostBottomModal extends StatelessWidget { }); /// This function is passed for the handling the action to be performed when the comment button is clicked. - /// - /// to see the function check the place where the widget is called. final Function(Post)? function; - /// To delete the post if user can. - /// - /// only work if the post is made by the user + /// To delete the post if user can (only work if the post is made by the user). final Function(Post)? deletePost; /// Post object containing all the data related to the post. - /// - /// see the post model to get more information regarding this final Post post; @override @@ -36,11 +28,11 @@ class PostBottomModal extends StatelessWidget { Center( child: Row( children: [ - const Padding( - padding: EdgeInsets.fromLTRB(20, 0, 0, 0), + Padding( + padding: const EdgeInsets.fromLTRB(20, 0, 0, 0), child: Icon( Icons.report_gmailerrorred_outlined, - color: Colors.black38, + color: Theme.of(context).colorScheme.tertiary, ), ), TextButton( @@ -52,13 +44,9 @@ class PostBottomModal extends StatelessWidget { ); Navigator.pop(context); }, - child: const Text( + child: Text( 'Report the post to the Admin', - style: TextStyle( - color: Colors.black38, - fontSize: 20, - fontFamily: 'open-sans', - ), + style: Theme.of(context).textTheme.bodyLarge, ), ), ], @@ -67,20 +55,17 @@ class PostBottomModal extends StatelessWidget { Center( child: Row( children: [ - const Padding( - padding: EdgeInsets.fromLTRB(20, 0, 0, 0), + Padding( + padding: const EdgeInsets.fromLTRB(20, 0, 0, 0), child: Icon( Icons.delete, - color: Colors.black38, + color: Theme.of(context).colorScheme.tertiary, ), ), TextButton( key: const Key('deletePost'), onPressed: () { - deletePost != null - ? deletePost!(post) - // ignore: unnecessary_statements - : {}; + deletePost?.call(post); showDialog( context: context, builder: (BuildContext builder) { @@ -113,13 +98,9 @@ class PostBottomModal extends StatelessWidget { }, ); }, - child: const Text( + child: Text( 'The post was deleted', - style: TextStyle( - color: Colors.black38, - fontSize: 20, - fontFamily: 'open-sans', - ), + style: Theme.of(context).textTheme.bodyLarge, ), ), ], diff --git a/lib/widgets/post_widget.dart b/lib/widgets/post_widget.dart index 7ec420a3a..807f49037 100644 --- a/lib/widgets/post_widget.dart +++ b/lib/widgets/post_widget.dart @@ -12,8 +12,6 @@ import 'package:talawa/widgets/post_detailed_page.dart'; import 'package:talawa/widgets/post_modal.dart'; /// Stateless class to show the fetched post. -/// -/// entirely ui based widget class NewsPost extends StatelessWidget { const NewsPost({ super.key, @@ -23,29 +21,25 @@ class NewsPost extends StatelessWidget { }); /// Post object containing all the data related to the post. - /// - /// see the post model to get more information regarding this final Post post; /// This function is passed for the handling the action to be performed when the comment button is clicked. - /// - /// to see the function check the place where the widget is called. final Function(Post)? function; - /// To delete the post if user can. - /// - /// only work if the post is made by the user + /// To delete the post if user can (only work if the post is made by the user). final Function(Post)? deletePost; @override Widget build(BuildContext context) { return Padding( padding: const EdgeInsets.all(8.0), - child: Container( - decoration: const BoxDecoration( - color: Colors.white, - borderRadius: BorderRadius.all(Radius.circular(16)), + child: Card( + elevation: 5, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(8), ), + surfaceTintColor: Theme.of(context).colorScheme.secondaryContainer, + color: Theme.of(context).colorScheme.tertiaryContainer, child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ @@ -58,58 +52,49 @@ class NewsPost extends StatelessWidget { "${'${GraphqlConfig.orgURI}'.replaceFirst('/graphql', '')}/${post.creator!.image}", fontSize: 20, ), - title: Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Text( - "${post.creator!.firstName} ${post.creator!.lastName}", - style: const TextStyle( - fontSize: 16, - fontWeight: FontWeight.w400, - color: Colors.black38, + title: Text( + "${post.creator!.firstName} ${post.creator!.lastName}", + style: TextStyle( + fontSize: 16, + fontWeight: FontWeight.w400, + color: Theme.of(context).colorScheme.onSecondary, + ), + ), + trailing: IconButton( + key: const Key('reportButton'), + onPressed: () => showModalBottomSheet( + context: context, + builder: (BuildContext context1) => Container( + key: const Key('reportPost'), + height: 120, + decoration: BoxDecoration( + color: Theme.of(context).primaryColor, + borderRadius: const BorderRadius.only( + topRight: Radius.circular(16), + topLeft: Radius.circular(16), + ), ), - ), - IconButton( - onPressed: () { - showModalBottomSheet( - context: context, - builder: (BuildContext context1) { - return Container( - height: 120, - decoration: const BoxDecoration( - color: Colors.white, - borderRadius: BorderRadius.only( - topRight: Radius.circular(16), - topLeft: Radius.circular(16), - ), - ), - child: PostBottomModal( - post: post, - deletePost: deletePost, - function: function, - ), - ); - }, - ); - }, - icon: const Icon( - Icons.report_gmailerrorred_outlined, - color: Colors.black38, + child: PostBottomModal( + post: post, + deletePost: deletePost, + function: function, ), ), - ], + ), + icon: Icon( + Icons.report_gmailerrorred_outlined, + color: Theme.of(context).colorScheme.onSecondary, + ), ), ), - post.imageUrl == null - ? DescriptionTextWidget(text: post.description!) - : Container(), post.imageUrl != null ? Container( - height: 380, + key: const Key('postParentContainer'), + height: 340, color: Colors.white, child: PostContainer(photoUrl: post.imageUrl), ) - : Container(), + : DescriptionTextWidget(text: post.description!), BaseView( onModelReady: (model) { model.initialize(post.likedBy ?? [], post.sId); @@ -126,29 +111,25 @@ class NewsPost extends StatelessWidget { child: Column( children: [ MultiReactButton( - toggle: () { - model.toggleIsLiked(); - }, + toggle: () => model.toggleIsLiked(), ), Text( "${model.likedBy.length}", - style: const TextStyle( + style: TextStyle( fontFamily: 'open-sans', - color: Colors.black38, + color: + Theme.of(context).colorScheme.onSecondary, ), ), ], ), ), - const SizedBox( - width: 20, - ), Container( child: Column( children: [ GestureDetector( - onTap: () => - function != null ? function!(post) : {}, + key: const Key('commentButton'), + onTap: () => function?.call(post), child: Padding( padding: const EdgeInsets.all(8.0), child: SizedBox( @@ -166,8 +147,9 @@ class NewsPost extends StatelessWidget { ), Text( "${post.comments!.length}", - style: const TextStyle( - color: Colors.black38, + style: TextStyle( + color: + Theme.of(context).colorScheme.onSecondary, ), ), ], @@ -177,8 +159,8 @@ class NewsPost extends StatelessWidget { padding: const EdgeInsets.fromLTRB(120, 0, 0, 0), child: Text( ' ${post.getPostCreatedDuration()}', - style: const TextStyle( - color: Colors.black38, + style: TextStyle( + color: Theme.of(context).colorScheme.onSecondary, fontSize: 12, ), ), @@ -195,13 +177,12 @@ class NewsPost extends StatelessWidget { mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ GestureDetector( - onTap: () => function != null ? function!(post) : {}, + onTap: () => function?.call(post), child: Text( - //TODO: Currently the Liked Model contain on SID of USER who liked the post, thus my name here "${AppLocalizations.of(context)!.strictTranslate("Liked")} by ...", - style: const TextStyle( + style: TextStyle( fontFamily: 'open-sans', - color: Colors.black38, + color: Theme.of(context).colorScheme.onSecondary, ), ), ), @@ -216,9 +197,8 @@ class NewsPost extends StatelessWidget { child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ - post.imageUrl != null - ? DescriptionTextWidget(text: post.description!) - : Container(), + if (post.imageUrl != null) + DescriptionTextWidget(text: post.description!), ], ), ), diff --git a/test/widget_tests/after_auth_screens/app_settings/app_setting_page_test.dart b/test/widget_tests/after_auth_screens/app_settings/app_setting_page_test.dart index 482866e45..9fb34de38 100644 --- a/test/widget_tests/after_auth_screens/app_settings/app_setting_page_test.dart +++ b/test/widget_tests/after_auth_screens/app_settings/app_setting_page_test.dart @@ -267,7 +267,7 @@ Future main() async { await tester.tap(find.byKey(const Key('Logout'))); await tester.pumpAndSettle(); - final logoutButton = find.textContaining('LogOut'); + final logoutButton = find.textContaining('Logout').last; await tester.tap(logoutButton); unregisterServices(); @@ -299,7 +299,7 @@ Future main() async { await tester.tap(find.byKey(const Key('Logout'))); await tester.pumpAndSettle(); - final logoutButton = find.textContaining('LogOut'); + final logoutButton = find.textContaining('Logout').last; await tester.tap(logoutButton); }); @@ -314,7 +314,7 @@ Future main() async { await tester.tap(find.byKey(const Key('Logout'))); await tester.pumpAndSettle(); - final logoutButton = find.textContaining('LogOut'); + final logoutButton = find.textContaining('Logout').last; await tester.tap(logoutButton); verify(navigationService.pop()); diff --git a/test/widget_tests/pre_auth_screens/set_url_page_test.dart b/test/widget_tests/pre_auth_screens/set_url_page_test.dart index 65db66041..fc9b6d16f 100644 --- a/test/widget_tests/pre_auth_screens/set_url_page_test.dart +++ b/test/widget_tests/pre_auth_screens/set_url_page_test.dart @@ -1,15 +1,8 @@ -// ignore_for_file: talawa_api_doc -// ignore_for_file: talawa_good_doc_comments - -// import 'dart:io'; - import 'package:flutter/material.dart'; -// import 'package:flutter/services.dart'; import 'package:flutter_localizations/flutter_localizations.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:hive/hive.dart'; import 'package:mockito/mockito.dart'; -// import 'package:path_provider/path_provider.dart' as path; import 'package:provider/provider.dart'; import 'package:qr_code_scanner/qr_code_scanner.dart'; import 'package:talawa/constants/custom_theme.dart'; @@ -27,32 +20,18 @@ import 'package:talawa/widgets/rich_text.dart'; import '../../helpers/test_helpers.dart'; -Widget createSetUrlScreenLight({ThemeMode themeMode = ThemeMode.light}) => - MultiProvider( - providers: [ - ChangeNotifierProvider( - create: (_) => AppLanguage(isTest: true), - ), - ], - child: MaterialApp( - localizationsDelegates: [ - const AppLocalizationsDelegate(isTest: true), - GlobalMaterialLocalizations.delegate, - GlobalWidgetsLocalizations.delegate, - ], - key: const Key('Root'), - themeMode: themeMode, - theme: TalawaTheme.lightTheme, - home: const SetUrl( - key: Key('SetUrl'), - uri: 'null', - ), - navigatorKey: navigationService.navigatorKey, - onGenerateRoute: router.generateRoute, - ), - ); - -Widget createSetUrlScreenDark({ThemeMode themeMode = ThemeMode.dark}) => +/// Returns the SetUrlScreen widget. +/// +/// **params**: +/// * `themeMode`: ThemeMode of the app. +/// * `theme`: ThemeData of the app. +/// +/// **returns**: +/// * `Widget`: SetUrlScreen widget. +Widget createSetUrlScreen({ + ThemeMode themeMode = ThemeMode.light, + ThemeData? theme, +}) => MultiProvider( providers: [ ChangeNotifierProvider( @@ -67,6 +46,7 @@ Widget createSetUrlScreenDark({ThemeMode themeMode = ThemeMode.dark}) => ], key: const Key('Root'), themeMode: themeMode, + theme: theme ?? TalawaTheme.lightTheme, darkTheme: TalawaTheme.darkTheme, home: const SetUrl( key: Key('SetUrl'), @@ -101,7 +81,12 @@ Future main() async { group('Select Language Screen Widget Test in light mode', () { testWidgets("Testing if Select Language Screen shows up", (tester) async { //pushing setUrlScreen - await tester.pumpWidget(createSetUrlScreenLight()); + await tester.pumpWidget( + createSetUrlScreen( + themeMode: ThemeMode.light, + theme: TalawaTheme.lightTheme, + ), + ); await tester.pumpAndSettle(); //initializing the screenScaffold Finder @@ -121,7 +106,12 @@ Future main() async { testWidgets("Testing if icon button shows up", (tester) async { //pushing setUrlScreen - await tester.pumpWidget(createSetUrlScreenLight()); + await tester.pumpWidget( + createSetUrlScreen( + themeMode: ThemeMode.light, + theme: TalawaTheme.lightTheme, + ), + ); await tester.pumpAndSettle(); //initializing the logo Finder @@ -141,7 +131,12 @@ Future main() async { }); testWidgets("Testing if app logo shows up", (tester) async { //pushing setUrlScreen - await tester.pumpWidget(createSetUrlScreenLight()); + await tester.pumpWidget( + createSetUrlScreen( + themeMode: ThemeMode.light, + theme: TalawaTheme.lightTheme, + ), + ); await tester.pumpAndSettle(); //initializing the logo Finder @@ -161,7 +156,12 @@ Future main() async { testWidgets("Testing if custom rich text shows up", (tester) async { //pushing setUrlScreen - await tester.pumpWidget(createSetUrlScreenLight()); + await tester.pumpWidget( + createSetUrlScreen( + themeMode: ThemeMode.light, + theme: TalawaTheme.lightTheme, + ), + ); await tester.pumpAndSettle(); //initializing the custom rich text widget Finder @@ -214,7 +214,12 @@ Future main() async { }); testWidgets("Testing the Url Input text form field", (tester) async { //pushing setUrlScreen - await tester.pumpWidget(createSetUrlScreenLight()); + await tester.pumpWidget( + createSetUrlScreen( + themeMode: ThemeMode.light, + theme: TalawaTheme.lightTheme, + ), + ); await tester.pumpAndSettle(); //initializing the url input field widget Finder @@ -260,7 +265,12 @@ Future main() async { }); testWidgets("Testing change language button", (tester) async { //pushing setUrlScreen - await tester.pumpWidget(createSetUrlScreenLight()); + await tester.pumpWidget( + createSetUrlScreen( + themeMode: ThemeMode.light, + theme: TalawaTheme.lightTheme, + ), + ); await tester.pumpAndSettle(); //initializing the change language widget Finder @@ -283,7 +293,12 @@ Future main() async { }); testWidgets("Testing if login button works", (tester) async { //pushing setUrlScreen - await tester.pumpWidget(createSetUrlScreenLight()); + await tester.pumpWidget( + createSetUrlScreen( + themeMode: ThemeMode.light, + theme: TalawaTheme.lightTheme, + ), + ); await tester.pumpAndSettle(); //initializing the login button Finder @@ -295,7 +310,7 @@ Future main() async { expect( (tester.firstWidget(loginButtonWidget) as RaisedRoundedButton) .backgroundColor, - TalawaTheme.lightTheme.colorScheme.secondaryContainer, + TalawaTheme.lightTheme.colorScheme.tertiary, ); expect( (tester.firstWidget(loginButtonWidget) as RaisedRoundedButton) @@ -315,7 +330,12 @@ Future main() async { testWidgets("Check navigation to Login page when Login button is pressed.", (tester) async { - await tester.pumpWidget(createSetUrlScreenDark()); + await tester.pumpWidget( + createSetUrlScreen( + themeMode: ThemeMode.dark, + theme: TalawaTheme.darkTheme, + ), + ); await tester.pump(); expect(find.byKey(const Key('SetUrlScreenScaffold')), findsOneWidget); @@ -332,7 +352,12 @@ Future main() async { }); testWidgets("Testing if signup button works", (tester) async { //pushing setUrlScreen - await tester.pumpWidget(createSetUrlScreenLight()); + await tester.pumpWidget( + createSetUrlScreen( + themeMode: ThemeMode.light, + theme: TalawaTheme.lightTheme, + ), + ); await tester.pumpAndSettle(); //initializing the signup button Finder @@ -364,7 +389,12 @@ Future main() async { "Testing onFieldSubmitted in TextFormField by simulating keyboard hits", (tester) async { //pushing setUrlScreen - await tester.pumpWidget(createSetUrlScreenLight()); + await tester.pumpWidget( + createSetUrlScreen( + themeMode: ThemeMode.light, + theme: TalawaTheme.lightTheme, + ), + ); await tester.pumpAndSettle(); final formFinder = find.ancestor( @@ -382,7 +412,12 @@ Future main() async { }); testWidgets("Testing onTap in sign up button", (tester) async { //pushing setUrlScreen - await tester.pumpWidget(createSetUrlScreenLight()); + await tester.pumpWidget( + createSetUrlScreen( + themeMode: ThemeMode.light, + theme: TalawaTheme.lightTheme, + ), + ); await tester.pumpAndSettle(); final btnFinder = find.byKey(const Key('SignUpButton')); @@ -398,7 +433,12 @@ Future main() async { testWidgets("Testing onTap in Change Language Gesture Detector", (tester) async { //pushing setUrlScreen - await tester.pumpWidget(createSetUrlScreenLight()); + await tester.pumpWidget( + createSetUrlScreen( + themeMode: ThemeMode.light, + theme: TalawaTheme.lightTheme, + ), + ); await tester.pumpAndSettle(); final gestureDetectorFinder = find.byKey(const Key('ChangeLanguage')); @@ -425,7 +465,12 @@ Future main() async { group('Select Language Screen Widget Test in dark mode', () { testWidgets("Testing if Select Language Screen shows up", (tester) async { //pushing setUrlScreen - await tester.pumpWidget(createSetUrlScreenDark()); + await tester.pumpWidget( + createSetUrlScreen( + themeMode: ThemeMode.dark, + theme: TalawaTheme.darkTheme, + ), + ); await tester.pumpAndSettle(); //initializing the screenScaffold Finder @@ -445,7 +490,12 @@ Future main() async { testWidgets("Testing if icon button shows up", (tester) async { //pushing setUrlScreen - await tester.pumpWidget(createSetUrlScreenLight()); + await tester.pumpWidget( + createSetUrlScreen( + themeMode: ThemeMode.light, + theme: TalawaTheme.lightTheme, + ), + ); await tester.pumpAndSettle(); //initializing the logo Finder @@ -465,7 +515,12 @@ Future main() async { }); testWidgets("Check if QR button works", (tester) async { //pushing setUrlScreen - await tester.pumpWidget(createSetUrlScreenDark()); + await tester.pumpWidget( + createSetUrlScreen( + themeMode: ThemeMode.dark, + theme: TalawaTheme.darkTheme, + ), + ); await tester.pumpAndSettle(); final iconButton = find.byIcon(Icons.qr_code_scanner); @@ -479,7 +534,12 @@ Future main() async { }); testWidgets("Testing if app logo shows up", (tester) async { //pushing setUrlScreen - await tester.pumpWidget(createSetUrlScreenDark()); + await tester.pumpWidget( + createSetUrlScreen( + themeMode: ThemeMode.dark, + theme: TalawaTheme.darkTheme, + ), + ); await tester.pumpAndSettle(); //initializing the logo Finder @@ -498,7 +558,12 @@ Future main() async { }); testWidgets("Testing if custom rich text shows up", (tester) async { //pushing setUrlScreen - await tester.pumpWidget(createSetUrlScreenDark()); + await tester.pumpWidget( + createSetUrlScreen( + themeMode: ThemeMode.dark, + theme: TalawaTheme.darkTheme, + ), + ); await tester.pumpAndSettle(); //initializing the custom rich text widget Finder @@ -551,7 +616,12 @@ Future main() async { }); testWidgets("Testing the Url Input text form field", (tester) async { //pushing setUrlScreen - await tester.pumpWidget(createSetUrlScreenDark()); + await tester.pumpWidget( + createSetUrlScreen( + themeMode: ThemeMode.dark, + theme: TalawaTheme.darkTheme, + ), + ); await tester.pumpAndSettle(); //initializing the url input field widget Finder @@ -597,7 +667,12 @@ Future main() async { }); testWidgets("Testing change language button", (tester) async { //pushing setUrlScreen - await tester.pumpWidget(createSetUrlScreenDark()); + await tester.pumpWidget( + createSetUrlScreen( + themeMode: ThemeMode.dark, + theme: TalawaTheme.darkTheme, + ), + ); await tester.pumpAndSettle(); //initializing the change language widget Finder @@ -620,7 +695,12 @@ Future main() async { }); testWidgets("Testing if login button works", (tester) async { //pushing setUrlScreen - await tester.pumpWidget(createSetUrlScreenDark()); + await tester.pumpWidget( + createSetUrlScreen( + themeMode: ThemeMode.dark, + theme: TalawaTheme.darkTheme, + ), + ); await tester.pumpAndSettle(); //initializing the login button Finder @@ -632,7 +712,7 @@ Future main() async { expect( (tester.firstWidget(loginButtonWidget) as RaisedRoundedButton) .backgroundColor, - TalawaTheme.darkTheme.colorScheme.secondaryContainer, + TalawaTheme.darkTheme.colorScheme.tertiary, ); expect( (tester.firstWidget(loginButtonWidget) as RaisedRoundedButton) @@ -652,7 +732,12 @@ Future main() async { }); testWidgets("Testing if signup button works", (tester) async { //pushing setUrlScreen - await tester.pumpWidget(createSetUrlScreenDark()); + await tester.pumpWidget( + createSetUrlScreen( + themeMode: ThemeMode.dark, + theme: TalawaTheme.darkTheme, + ), + ); await tester.pumpAndSettle(); //initializing the signup button Finder @@ -684,7 +769,12 @@ Future main() async { "Testing onFieldSubmitted in TextFormField by simulating keyboard hits", (tester) async { //pushing setUrlScreen - await tester.pumpWidget(createSetUrlScreenDark()); + await tester.pumpWidget( + createSetUrlScreen( + themeMode: ThemeMode.dark, + theme: TalawaTheme.darkTheme, + ), + ); await tester.pumpAndSettle(); final formFinder = find.ancestor( @@ -702,7 +792,12 @@ Future main() async { }); testWidgets("Testing onTap in sign up button", (tester) async { //pushing setUrlScreen - await tester.pumpWidget(createSetUrlScreenDark()); + await tester.pumpWidget( + createSetUrlScreen( + themeMode: ThemeMode.dark, + theme: TalawaTheme.darkTheme, + ), + ); await tester.pumpAndSettle(); final btnFinder = find.byKey(const Key('SignUpButton')); @@ -718,7 +813,12 @@ Future main() async { testWidgets("Testing onTap in Change Language Gesture Detector", (tester) async { //pushing setUrlScreen - await tester.pumpWidget(createSetUrlScreenDark()); + await tester.pumpWidget( + createSetUrlScreen( + themeMode: ThemeMode.dark, + theme: TalawaTheme.darkTheme, + ), + ); await tester.pumpAndSettle(); final gestureDetectorFinder = find.byKey(const Key('ChangeLanguage')); diff --git a/test/widget_tests/widgets/post_widget_test.dart b/test/widget_tests/widgets/post_widget_test.dart index 20f266928..5064449a9 100644 --- a/test/widget_tests/widgets/post_widget_test.dart +++ b/test/widget_tests/widgets/post_widget_test.dart @@ -1,12 +1,8 @@ -// ignore_for_file: talawa_api_doc -// ignore_for_file: talawa_good_doc_comments - -// import 'dart:convert'; - 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:network_image_mock/network_image_mock.dart'; import 'package:talawa/constants/custom_theme.dart'; import 'package:talawa/locator.dart'; import 'package:talawa/models/post/post_model.dart'; @@ -19,15 +15,27 @@ import 'package:talawa/widgets/custom_avatar.dart'; import 'package:talawa/widgets/multi_reaction.dart'; import 'package:talawa/widgets/post_container.dart'; import 'package:talawa/widgets/post_detailed_page.dart'; +import 'package:talawa/widgets/post_modal.dart'; import 'package:talawa/widgets/post_widget.dart'; // import 'package:talawa/widgets/video_widget.dart'; // import 'package:visibility_detector/visibility_detector.dart'; import '../../helpers/test_helpers.dart'; +/// Key for NewsPost widget. const Key newsPostKey = Key("newsPostKey"); + +/// Key for PostContainer widget. const Key postContainerKey = Key("postContainerKey"); +/// [createNewsPostWidget] is a method that returns a NewsPost widget. +/// +/// **params**: +/// * `function`: Function(Post)? - function to be called when the post comment is clicked. +/// * `post`: Post object containing all the data related to the post. +/// +/// **returns**: +/// * `Widget`: NewsPost widget. Widget createNewsPostWidget([Function(Post)? function, Post? post]) { return MaterialApp( locale: const Locale('en'), @@ -48,26 +56,6 @@ Widget createNewsPostWidget([Function(Post)? function, Post? post]) { ); } -Widget createPostContainerWidget() { - return MaterialApp( - locale: const Locale('en'), - localizationsDelegates: [ - const AppLocalizationsDelegate(isTest: true), - GlobalMaterialLocalizations.delegate, - GlobalWidgetsLocalizations.delegate, - ], - themeMode: ThemeMode.light, - theme: TalawaTheme.lightTheme, - home: const Scaffold( - body: PostContainer( - key: postContainerKey, - photoUrl: - "https://dcblog.b-cdn.net/wp-content/uploads/2021/02/Full-form-of-URL-1-1024x824.jpg", - ), - ), - ); -} - void main() { SizeConfig().test(); locator.registerSingleton(NavigationService()); @@ -130,78 +118,21 @@ void main() { // ); }); }); - testWidgets("Test if onTap is functional", (WidgetTester tester) async { + + testWidgets("test onTap of GestureDetector's", (tester) async { await tester.runAsync(() async { int clicked = 0; - void func(Post post) { - clicked++; - } - - await tester.pumpWidget(createNewsPostWidget(func)); + await tester + .pumpWidget(createNewsPostWidget((Post post) => clicked++)); await tester.pump(); - final postFinder = find.byKey(newsPostKey); - final columnFinder = - find.descendant(of: postFinder, matching: find.byType(Column)); - final column2Finder = columnFinder.at(2); - final secondColumnWidget = - tester.firstWidget(column2Finder) as Column; - print(secondColumnWidget); - // final firstPaddingWidget = secondColumnWidget.children[0] as Padding; - // final firstGestureDetectorFinder = find.descendant( - // of: find.byWidget(firstPaddingWidget), - // matching: find.byType(GestureDetector), - // ); - // final firstGestureDetectorWidget = - // tester.firstWidget(firstGestureDetectorFinder) as GestureDetector; - // await tester.tap(find.byWidget(firstGestureDetectorWidget).first); + await tester.tap(find.byKey(const Key('commentButton'))); await tester.pump(); - expect(clicked, 0); - - // final secondGestureDetectorFinder = find.descendant( - // of: find.byWidget(firstPaddingWidget), - // matching: find.byType(GestureDetector), - // ); - // final secondGestureDetectorWidget = tester - // .firstWidget(secondGestureDetectorFinder.last) as GestureDetector; - // await tester.tap(find.byWidget(secondGestureDetectorWidget).first); - // await tester.pump(); - // expect(clicked, 0); + expect(clicked, 1); - // final thirdPaddingWidget = secondColumnWidget.children[2] as Padding; - // - // final second3GestureDetectorFinder = find.descendant( - // of: find.byWidget(thirdPaddingWidget), - // matching: find.byType(GestureDetector), - // ); - // final second3GestureDetectorWidget = - // tester.firstWidget(second3GestureDetectorFinder.last) - // as GestureDetector; - // await tester.tap(find.byWidget(second3GestureDetectorWidget)); - // await tester.pump(); - // expect(clicked, 3); - // - // final first3GestureDetectorFinder = find.descendant( - // of: find.byWidget(thirdPaddingWidget), - // matching: find.byType(GestureDetector), - // ); - // final first3GestureDetectorWidget = tester - // .firstWidget(first3GestureDetectorFinder) as GestureDetector; - // await tester.tap(find.byWidget(first3GestureDetectorWidget)); - // await tester.pump(); - - // expect( - // first3GestureDetectorWidget.child, - // isA() - // .having((icon) => icon.icon, "icon", Icons.thumb_up) - // .having( - // (icon) => icon.color, - // "color", - // equals( - // const Color(0xff737373), - // ), - // ), - // ); + await tester.tap(find.byType(GestureDetector).last); + await tester.pump(); + expect(clicked, 2); }); }); }); @@ -231,9 +162,9 @@ void main() { // Testing if all direct children of column are there expect(firstColumnWidget.children[0], isA()); expect(firstColumnWidget.children[1], isA()); - expect(firstColumnWidget.children[2], isA()); + // expect(firstColumnWidget.children[2], isA()); expect( - firstColumnWidget.children[3], + firstColumnWidget.children[2], isA>(), ); }); @@ -278,7 +209,7 @@ void main() { expect(customAvatarWidget.firstAlphabet, 'T'); // Tests if leading of list tile is custom avatar - expect(listTileWidget.title.runtimeType, Row); + expect(listTileWidget.title.runtimeType, Text); final textsOfListTileFinder = find.descendant( of: listTileFinder.first, @@ -330,35 +261,7 @@ void main() { expect(descriptionTextWidget.text, "TestDescription"); }); }); - testWidgets("Test props of Container containing the Post Container", - (WidgetTester tester) async { - await tester.runAsync(() async { - await tester.pumpWidget(createNewsPostWidget()); - await tester.pump(); - final postFinder = find.byKey(newsPostKey); - final columnFinder = find - .descendant(of: postFinder, matching: find.byType(Column)) - .first; - final containerWidget = (tester.firstWidget(columnFinder) as Column) - .children[2] as Container; - - // Testing if the text description is correct - // expect(containerWidget.constraints!.maxHeight, 400); - // expect(containerWidget.constraints!.minHeight, 400); - - expect( - containerWidget.color, - null, - ); - - final postContainerFinder = find.descendant( - of: find.byWidget(containerWidget), - matching: find.byType(PostContainer), - ); - expect(postContainerFinder, findsNothing); - }); - }); testWidgets("Test props of Base view", (WidgetTester tester) async { await tester.runAsync(() async { await tester.pumpWidget(createNewsPostWidget()); @@ -368,7 +271,7 @@ void main() { find.descendant(of: postFinder, matching: find.byType(Column)); final baseViewWidget = (tester.firstWidget(columnFinder) as Column) - .children[3] as BaseView; + .children[2] as BaseView; // Testing if the text description is correct expect(baseViewWidget.onModelReady, isNotNull); @@ -379,10 +282,6 @@ void main() { final secondColumnWidget = tester.firstWidget(column2Finder) as Column; print(secondColumnWidget); - // Testing if all direct children of column are there - // expect(secondColumnWidget.children[0], isA()); - // expect(secondColumnWidget.children[1], isA()); - // expect(secondColumnWidget.children[2], isA()); }); }); @@ -420,7 +319,6 @@ void main() { expect(reactionChangedCalled, true); }); }); - testWidgets('Test props first padding widget', (WidgetTester tester) async { await tester.runAsync(() async { @@ -435,62 +333,17 @@ void main() { final firstPaddingWidget = secondColumnWidget.children[0] as Padding; - // expect( - // // firstPaddingWidget.padding, - // const EdgeInsets.symmetric(horizontal: 16, vertical: 10), - // ); - // expect( - // firstPaddingWidget.child, - // isA() - // .having( - // (row) => row.mainAxisAlignment, - // 'mainAxisAlignment', - // MainAxisAlignment.spaceBetween, - // ) - // .having( - // (row) => row.children, - // "children", - // [ - // isA(), - // isA(), - // ], - // ), - // ); final firstGestureDetectorFinder = find.descendant( of: find.byWidget(firstPaddingWidget), matching: find.byType(GestureDetector), ); print(firstGestureDetectorFinder); - // final firstGestureDetectorWidget = tester - // .firstWidget(firstGestureDetectorFinder) as GestureDetector; - // expect(firstGestureDetectorWidget.onTap, isNotNull); - // expect(firstGestureDetectorWidget.onTap, isA()); - // expect( - // firstGestureDetectorWidget.child, - // isA().having((text) => text.data, "data", "0 Likes").having( - // (text) => text.style, - // "style", - // const TextStyle( - // fontFamily: 'open-sans', - // fontWeight: FontWeight.w800, - // ), - // ), - // ); final secondGestureDetectorFinder = find.descendant( of: find.byWidget(firstPaddingWidget), matching: find.byType(GestureDetector), ); print(secondGestureDetectorFinder); - // final secondGestureDetectorWidget = - // tester.firstWidget(secondGestureDetectorFinder.last) - // as GestureDetector; - // expect(secondGestureDetectorWidget.onTap, isNotNull); - // expect(secondGestureDetectorWidget.onTap, isA()); - // expect( - // secondGestureDetectorWidget.child, - // isA().having((text) => text.data, "data", "0 comments"), - // ); }); }); @@ -523,362 +376,60 @@ void main() { final secondColumnWidget = tester.firstWidget(column2Finder) as Column; print(secondColumnWidget); - // final thirdPaddingWidget = - // secondColumnWidget.children[2] as Padding; - // expect( - // thirdPaddingWidget.padding, - // const EdgeInsets.symmetric(horizontal: 16, vertical: 5), - // ); - // expect( - // thirdPaddingWidget.child, - // isA().having( - // (row) => row.children, - // "children", - // [ - // isA(), - // isA(), - // ], - // ), - // ); - // final first3GestureDetectorFinder = find.descendant( - // of: find.byWidget(thirdPaddingWidget), - // matching: find.byType(GestureDetector), - // ); - // final first3GestureDetectorWidget = tester - // .firstWidget(first3GestureDetectorFinder) as GestureDetector; - // expect(first3GestureDetectorWidget.onTap, isNotNull); - // expect(first3GestureDetectorWidget.onTap, isA()); - // expect( - // first3GestureDetectorWidget.child, - // isA() - // .having((icon) => icon.icon, "icon", Icons.thumb_up) - // .having( - // (icon) => icon.color, - // "color", - // const Color(0xff737373), - // ), - // ); - - // final second3GestureDetectorFinder = find.descendant( - // of: find.byWidget(thirdPaddingWidget), - // matching: find.byType(GestureDetector), - // ); - // final second3GestureDetectorWidget = - // tester.firstWidget(second3GestureDetectorFinder.last) - // as GestureDetector; - // expect(second3GestureDetectorWidget.onTap, isNotNull); - // expect(second3GestureDetectorWidget.onTap, isA()); - // expect( - // second3GestureDetectorWidget.child, - // isA() - // .having( - // (padding) => padding.padding, - // "padding", - // const EdgeInsets.only(left: 18.0), - // ) - // .having( - // (padding) => padding.child, - // "child", - // isA() - // .having((icon) => icon.icon, "icon", Icons.comment) - // .having( - // (icon) => icon.color, - // "color", - // const Color(0xff737373), - // ), - // ), - // ); + }); + }); + + testWidgets('Test if report button opens modal bottom sheet', + (WidgetTester tester) async { + await tester.pumpWidget(createNewsPostWidget()); + await tester.pump(); + + final reportButtonFinder = find.byKey(const Key('reportButton')); + expect(reportButtonFinder, findsOneWidget); + + await tester.tap(reportButtonFinder); + await tester.pumpAndSettle(); + + final modalBottomSheetFinder = + find.byKey(const Key('reportPost')).first; + expect(modalBottomSheetFinder, findsOneWidget); + + final postBottomModalFinder = find.byType(PostBottomModal); + expect(postBottomModalFinder, findsOneWidget); + }); + + testWidgets("Test post image", (tester) async { + await tester.runAsync(() async { + await mockNetworkImagesFor(() async { + final Post post = getPostMockModel(); + when(post.imageUrl).thenReturn( + "testImageUrl", + ); + + await tester.pumpWidget( + createNewsPostWidget( + null, + post, + ), + ); + + await tester.pumpAndSettle(); + + final postParentContainer = + find.byKey(const Key('postParentContainer')); + expect(postParentContainer, findsOneWidget); + final postContainer = find + .descendant( + of: postParentContainer, + matching: find.byType(PostContainer), + ) + .first; + + expect(postContainer, findsOneWidget); + }); }); }); }); }); }); - // - // group('Testing Post Container Widget -', () { - // testWidgets('Test if Post Container Widget shows', - // (WidgetTester tester) async { - // await tester.runAsync(() async { - // // https://dcblog.b-cdn.net/wp-content/uploads/2021/02/Full-form-of-URL-1-1024x824.jpg - // nock('https://dcblog.b-cdn.net') - // .get('wp-content/uploads/2021/02/Full-form-of-URL-1-1024x824.jpg') - // .reply(200, json.encode('{"id": "49c23ebc-c107-4dae-b1c6-5d325b8f8b58", "name": "Example campus" }')); - // await tester.pumpWidget(createPostContainerWidget()); - // await tester.pump(); - // final postContainerFinder = find.byKey(postContainerKey); - // expect(postContainerFinder, findsOneWidget); - // }); - // }); - // testWidgets('Test props of Visibility Detector', - // (WidgetTester tester) async { - // await tester.runAsync(() async { - // await tester.pumpWidget(createPostContainerWidget()); - // await tester.pump(); - // final postContainerFinder = find.byKey(postContainerKey); - // final visibilityDetectorFinder = find.descendant( - // of: postContainerFinder, - // matching: find.byType(VisibilityDetector), - // ); - // final visibilityDetectorWidget = - // tester.firstWidget(visibilityDetectorFinder) as VisibilityDetector; - // - // expect(visibilityDetectorFinder, findsOneWidget); - // expect(visibilityDetectorWidget.key, const Key('Post Id')); - // expect(visibilityDetectorWidget.onVisibilityChanged, isNotNull); - // expect(visibilityDetectorWidget.onVisibilityChanged, isA()); - // expect( - // visibilityDetectorWidget.child, - // isA().having( - // (stack) => stack.children, - // "children", - // [ - // isA(), - // isA(), - // ], - // ), - // ); - // }); - // }); - // testWidgets('Test props of PageView', (WidgetTester tester) async { - // await tester.runAsync(() async { - // await tester.pumpWidget(createPostContainerWidget()); - // await tester.pump(); - // final postContainerFinder = find.byKey(postContainerKey); - // final pageViewFinder = find.descendant( - // of: postContainerFinder, - // matching: find.byType(PageView), - // ); - // final pageViewWidget = tester.firstWidget(pageViewFinder) as PageView; - // expect(pageViewFinder, findsOneWidget); - // expect(pageViewWidget.scrollDirection, Axis.horizontal); - // expect( - // pageViewWidget.controller, - // isA().having( - // (pageController) => pageController.initialPage, - // "initial page", - // 0, - // ), - // ); - // expect(pageViewWidget.onPageChanged, isA()); - // }); - // }); - // testWidgets('Test children of PageView', (WidgetTester tester) async { - // await tester.runAsync(() async { - // await mockNetworkImagesFor(() async { - // await tester.pumpWidget(createPostContainerWidget()); - // await tester.pump(); - // final postContainerFinder = find.byKey(postContainerKey); - // final pageViewFinder = find.descendant( - // of: postContainerFinder, - // matching: find.byType(PageView), - // ); - // final centerFinder = find.ancestor( - // of: find.byType(VideoWidget), - // matching: find.descendant( - // of: pageViewFinder, - // matching: find.byType(Center), - // ), - // ); - // final imageFinder = find.descendant( - // of: pageViewFinder, - // matching: find.byType(Image), - // ); - // - // expect(centerFinder, findsOneWidget); - // expect(imageFinder, findsNothing); - // - // final centerWidget = tester.firstWidget(centerFinder) as Center; - // expect( - // centerWidget.child, - // isA() - // .having( - // (video) => video.url, - // "url", - // 'https://flutter.github.io/assets-for-api-docs/assets/videos/bee.mp4', - // ) - // .having((video) => video.play, "play", true), - // ); - // - // await tester.dragFrom( - // Offset( - // SizeConfig.screenWidth!, - // tester.getCenter(pageViewFinder).dy, - // ), - // Offset(-SizeConfig.screenWidth! * 2, 0), - // ); - // await tester.pump(); - // - // expect(centerFinder, findsOneWidget); - // expect(imageFinder, findsOneWidget); - // expect( - // tester.firstWidget(imageFinder), - // isA().having( - // (image) => image.image, - // "image", - // const NetworkImage( - // 'https://flutter.github.io/assets-for-api-docs/assets/widgets/owl.jpg', - // ), - // ), - // ); - // - // final paddingFinder = find.descendant( - // of: postContainerFinder, - // matching: find.byType(Padding), - // ); - // final paddingFinders = find.descendant( - // of: paddingFinder.at(1), - // matching: find.byType(Padding), - // ); - // final padding1Widgets = - // tester.firstWidget(paddingFinders.at(0)) as Padding; - // final padding2Widgets = - // tester.firstWidget(paddingFinders.at(3)) as Padding; - // await tester.pump(); - // expect((padding1Widgets.child! as Divider).color, Colors.grey); - // expect( - // (padding2Widgets.child! as Divider).color, - // TalawaTheme.lightTheme.colorScheme.primary, - // ); - // expect( - // (tester.firstWidget(pageViewFinder) as PageView).controller.page, - // 0.9, - // ); - // }); - // }); - // }); - // testWidgets('Test props of Padding', (WidgetTester tester) async { - // await tester.runAsync(() async { - // await tester.pumpWidget(createPostContainerWidget()); - // await tester.pump(); - // final postContainerFinder = find.byKey(postContainerKey); - // final paddingFinder = find.descendant( - // of: postContainerFinder, - // matching: find.byType(Padding), - // ); - // final paddingWidget = tester.firstWidget(paddingFinder) as Padding; - // expect( - // paddingWidget.padding, - // const EdgeInsets.symmetric(horizontal: 8.0), - // ); - // expect( - // paddingWidget.child, - // isA() - // .having( - // (column) => column.crossAxisAlignment, - // "cross axis alignment", - // CrossAxisAlignment.center, - // ) - // .having( - // (column) => column.mainAxisAlignment, - // "main axis alignment", - // MainAxisAlignment.end, - // ) - // .having( - // (column) => column.mainAxisSize, - // "main axis size", - // MainAxisSize.max, - // ) - // .having( - // (column) => column.children, - // "children", - // [isA()], - // ), - // ); - // }); - // }); - // testWidgets('Test props of second Padding', (WidgetTester tester) async { - // await tester.runAsync(() async { - // await tester.pumpWidget(createPostContainerWidget()); - // await tester.pump(); - // final postContainerFinder = find.byKey(postContainerKey); - // final paddingFinder = find.descendant( - // of: postContainerFinder, - // matching: find.byType(Padding), - // ); - // final paddingWidget = - // tester.firstWidget(paddingFinder.at(1)) as Padding; - // expect( - // paddingWidget.padding, - // const EdgeInsets.symmetric( - // horizontal: 100.0, - // vertical: 10.0, - // ), - // ); - // expect( - // paddingWidget.child, - // isA().having( - // (row) => row.children, - // "children", - // [ - // isA().having( - // (expanded) => expanded.child, - // "child", - // isA(), - // ), - // isA().having( - // (expanded) => expanded.child, - // "child", - // isA(), - // ), - // isA().having( - // (expanded) => expanded.child, - // "child", - // isA(), - // ), - // isA().having( - // (expanded) => expanded.child, - // "child", - // isA(), - // ), - // ], - // ), - // ); - // final paddingFinders = find.descendant( - // of: paddingFinder.at(1), - // matching: find.byType(Padding), - // ); - // final padding1Widgets = - // tester.firstWidget(paddingFinders.at(0)) as Padding; - // final padding2Widgets = - // tester.firstWidget(paddingFinders.at(3)) as Padding; - // - // expect( - // padding1Widgets.padding, - // const EdgeInsets.symmetric(horizontal: 5.0), - // ); - // expect( - // padding1Widgets.child, - // isA() - // .having( - // (divider) => divider.thickness, - // "thickness", - // 3.0, - // ) - // .having( - // (divider) => divider.color, - // "color", - // TalawaTheme.lightTheme.colorScheme.primary, - // ), - // ); - // - // expect( - // padding2Widgets.padding, - // const EdgeInsets.symmetric(horizontal: 5.0), - // ); - // expect( - // padding2Widgets.child, - // isA() - // .having( - // (divider) => divider.thickness, - // "thickness", - // 3.0, - // ) - // .having( - // (divider) => divider.color, - // "color", - // Colors.grey, - // ), - // ); - // }); - // }); - // }); }