From c9fb01146d079a4e30bcc4626ce9bb1fb70ed0e3 Mon Sep 17 00:00:00 2001 From: utkarshshendge Date: Sat, 27 Mar 2021 11:34:01 +0530 Subject: [PATCH 1/4] Update pubspec.yaml --- pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pubspec.yaml b/pubspec.yaml index 9003aa561..5fd2d2f77 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -35,7 +35,7 @@ dependencies: graphql_flutter: ^3.0.1 email_validator: ^1.0.4 fluttertoast: ^7.1.8 - persistent_bottom_nav_bar: ^1.5.5 + persistent_bottom_nav_bar: ^3.2.0 file_picker: ^2.0.7 timeline_list: ^0.0.5 flutter_sticky_header: ^0.4.5 From 203a4a579a36038bd107d5ce36cc729adc45bc1d Mon Sep 17 00:00:00 2001 From: utkarshshendge Date: Sat, 27 Mar 2021 11:41:34 +0530 Subject: [PATCH 2/4] Add keys for widget tests --- lib/views/pages/chat/groups.dart | 1 + lib/views/pages/events/events.dart | 1 + lib/views/pages/members/members.dart | 1 + lib/views/pages/newsfeed/newsfeed.dart | 2 +- lib/views/pages/organization/profile_page.dart | 1 + 5 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/views/pages/chat/groups.dart b/lib/views/pages/chat/groups.dart index 665e11839..b37820aa2 100644 --- a/lib/views/pages/chat/groups.dart +++ b/lib/views/pages/chat/groups.dart @@ -18,6 +18,7 @@ class _GroupsState extends State { Widget build(BuildContext context) { return Scaffold( appBar: AppBar( + key: Key('GROUPS_APP_BAR'), title: Text( 'Chats', style: TextStyle(color: Colors.white), diff --git a/lib/views/pages/events/events.dart b/lib/views/pages/events/events.dart index c7ae45555..2417efadc 100644 --- a/lib/views/pages/events/events.dart +++ b/lib/views/pages/events/events.dart @@ -199,6 +199,7 @@ class _EventsState extends State { Widget build(BuildContext context) { return Scaffold( appBar: AppBar( + key: Key('EVENTS_APP_BAR'), title: Text( 'Events', style: TextStyle(color: Colors.white), diff --git a/lib/views/pages/members/members.dart b/lib/views/pages/members/members.dart index 4a2dccf34..2aed58570 100644 --- a/lib/views/pages/members/members.dart +++ b/lib/views/pages/members/members.dart @@ -124,6 +124,7 @@ class _OrganizationsState extends State { Widget build(BuildContext context) { return Scaffold( appBar: AppBar( + key: Key('ORGANIZATION_APP_BAR'), title: Text( 'Members', style: TextStyle(color: Colors.white), diff --git a/lib/views/pages/newsfeed/newsfeed.dart b/lib/views/pages/newsfeed/newsfeed.dart index e5e22c98a..c811b14e5 100644 --- a/lib/views/pages/newsfeed/newsfeed.dart +++ b/lib/views/pages/newsfeed/newsfeed.dart @@ -97,7 +97,7 @@ class _NewsFeedState extends State { Widget build(BuildContext context) { return Scaffold( - appBar: CustomAppBar('NewsFeed'), + appBar: CustomAppBar('NewsFeed',key: Key('NEWSFEED_APP_BAR')), floatingActionButton: addPostFab(), body: postList.isEmpty ? Center(child: CircularProgressIndicator()) diff --git a/lib/views/pages/organization/profile_page.dart b/lib/views/pages/organization/profile_page.dart index 737cf69e3..e3e3fe958 100644 --- a/lib/views/pages/organization/profile_page.dart +++ b/lib/views/pages/organization/profile_page.dart @@ -188,6 +188,7 @@ class _ProfilePageState extends State { @override Widget build(BuildContext context) { return Scaffold( + key: Key('PROFILE_PAGE_SCAFFOLD'), backgroundColor: Colors.white, body: userDetails.isEmpty || isCreator == null ? Center(child: CircularProgressIndicator(key: Key('loading'),)) From 274fb7c57e3beee6cda98248e9292255bd2475d1 Mon Sep 17 00:00:00 2001 From: utkarshshendge Date: Sat, 27 Mar 2021 11:44:41 +0530 Subject: [PATCH 3/4] Upgrade persistent_bottom_bar --- lib/views/pages/home_page.dart | 69 ++++++++++++++++++++++------------ 1 file changed, 44 insertions(+), 25 deletions(-) diff --git a/lib/views/pages/home_page.dart b/lib/views/pages/home_page.dart index 6efee5816..e52a4d237 100644 --- a/lib/views/pages/home_page.dart +++ b/lib/views/pages/home_page.dart @@ -40,10 +40,7 @@ class _HomePageState extends State { void initState() { super.initState(); currentIndex = widget.openPageIndex; - _controller = - PersistentTabController(initialIndex: currentIndex); - Provider.of(context, listen: false).getOrgUrl(); - Provider.of(context, listen: false).getCurrentOrgId(); + _controller = PersistentTabController(initialIndex: currentIndex); } void dispose() { @@ -73,32 +70,32 @@ class _HomePageState extends State { PersistentBottomNavBarItem( //mentioning the screen home in the bottom bar icon: Icon(Icons.home), title: ("Home"), - activeColor: Colors.white, - inactiveColor: Colors.white, + activeColorPrimary: Colors.white, + inactiveColorPrimary: Colors.white, ), PersistentBottomNavBarItem( //mentioning the screen chats in the bottom bar icon: Icon(Icons.chat), title: ("Chats"), - activeColor: Colors.white, - inactiveColor: Colors.white, + activeColorPrimary: Colors.white, + inactiveColorPrimary: Colors.white, ), PersistentBottomNavBarItem( //mentioning the Events home in the bottom bar icon: Icon(Icons.calendar_today), title: ("Events"), - activeColor: Colors.white, - inactiveColor: Colors.white, + activeColorPrimary: Colors.white, + inactiveColorPrimary: Colors.white, ), PersistentBottomNavBarItem( //mentioning the screen home in the bottom bar icon: Icon(Icons.group), title: ("Members"), - activeColor: Colors.white, - inactiveColor: Colors.white, + activeColorPrimary: Colors.white, + inactiveColorPrimary: Colors.white, ), PersistentBottomNavBarItem( //mentioning the screen Profile in the bottom bar icon: Icon(Icons.folder), title: ("Profile"), - activeColor: Colors.white, - inactiveColor: Colors.white, + activeColorPrimary: Colors.white, + inactiveColorPrimary: Colors.white, ), ]; } @@ -111,16 +108,38 @@ class _HomePageState extends State { @override Widget build(BuildContext context) { - return - PersistentTabView( //calling the Persistent tab view here - backgroundColor: UIData.primaryColor, - controller: _controller, - items: _navBarsItems(), - screens: _buildScreens(), - confineInSafeArea: true, - handleAndroidBackButtonPress: true, - iconSize: 26.0, - navBarStyle: NavBarStyle.style4, + return MultiProvider( + providers: [ + ChangeNotifierProvider( + create: (_) => GraphQLConfiguration(), + ), + ChangeNotifierProvider( + create: (_) => Preferences(), + ) + ], + child: Builder(builder: (BuildContext context) { + BuildContext rootContext = context; + Provider.of(rootContext, listen: false) + .getOrgUrl(); + Provider.of(rootContext, listen: false).getCurrentOrgId(); + return PersistentTabView(rootContext, + backgroundColor: UIData.primaryColor, + controller: _controller, + items: _navBarsItems(), + screens: _buildScreens(), + confineInSafeArea: true, + handleAndroidBackButtonPress: true, + navBarStyle: NavBarStyle.style4, + itemAnimationProperties: ItemAnimationProperties( + duration: Duration(milliseconds: 200), + curve: Curves.ease, + ), + screenTransitionAnimation: ScreenTransitionAnimation( + animateTabTransition: true, + curve: Curves.ease, + duration: Duration(milliseconds: 200), + )); + }), ); } -} +} \ No newline at end of file From 3e3dde21f7d0270f0572722c78ad95e62c2b865e Mon Sep 17 00:00:00 2001 From: utkarshshendge Date: Sat, 27 Mar 2021 11:47:29 +0530 Subject: [PATCH 4/4] Add widget test for home_page.dart --- test/widget_tests/home_page_test.dart | 131 ++++++++++++++++++++++++++ 1 file changed, 131 insertions(+) create mode 100644 test/widget_tests/home_page_test.dart diff --git a/test/widget_tests/home_page_test.dart b/test/widget_tests/home_page_test.dart new file mode 100644 index 000000000..91e5f7e0e --- /dev/null +++ b/test/widget_tests/home_page_test.dart @@ -0,0 +1,131 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:persistent_bottom_nav_bar/persistent-tab-view.dart'; +import 'package:provider/provider.dart'; + +import '../../lib/controllers/auth_controller.dart'; +import '../../lib/controllers/org_controller.dart'; +import '../../lib/services/preferences.dart'; +import '../../lib/utils/GQLClient.dart'; +import '../../lib/views/pages/home_page.dart'; + +Widget createHomePageScreen() => MultiProvider( + providers: [ + ChangeNotifierProvider( + create: (_) => GraphQLConfiguration(), + ), + ChangeNotifierProvider( + create: (_) => OrgController(), + ), + ChangeNotifierProvider( + create: (_) => AuthController(), + ), + ChangeNotifierProvider( + create: (_) => Preferences(), + ), + ], + child: MaterialApp( + home: HomePage(), + ), + ); + +void main() { + final TestWidgetsFlutterBinding binding = + TestWidgetsFlutterBinding.ensureInitialized(); + group('HomePage Widget Test', () { + testWidgets("Testing if HomePage shows up", (tester) async { + await tester.pumpWidget(createHomePageScreen()); + + // Verify if HomePage Page shows up by checking PersistentTabView. + expect(find.byType(PersistentTabView), findsOneWidget); + }); + + testWidgets("Testing overflow of New Article in a mobile screen", + (tester) async { + binding.window.physicalSizeTestValue = Size(440, 800); + binding.window.devicePixelRatioTestValue = 1.0; + + await tester.pumpWidget(createHomePageScreen()); + // Verify if HomePage Page shows up by checking PersistentTabView. + expect(find.byType(PersistentTabView), findsOneWidget); + }); + + testWidgets("Testing overflow of New Article in a tablet screen", + (tester) async { + binding.window.physicalSizeTestValue = Size(1024, 768); + binding.window.devicePixelRatioTestValue = 1.0; + + await tester.pumpWidget(createHomePageScreen()); + // Verify if HomePage Page shows up by checking PersistentTabView. + expect(find.byType(PersistentTabView), findsOneWidget); + }); + + testWidgets('Verifying presence of icons in HomePage', (tester) async { + await tester.pumpWidget(createHomePageScreen()); + //detecting icons by find.byIcon(Icons.home) + expect(find.byIcon(Icons.home), findsOneWidget); + expect(find.byIcon(Icons.chat), findsOneWidget); + expect(find.byIcon(Icons.calendar_today), findsOneWidget); + expect(find.byIcon(Icons.group), findsOneWidget); + expect(find.byIcon(Icons.folder), findsOneWidget); + }); + + testWidgets('Verifying if the first page is NEWSFEED', (tester) async { + await tester.pumpWidget(createHomePageScreen()); + expect(find.byKey(Key('NEWSFEED_APP_BAR')), findsOneWidget); + //any other page should not be there + expect(find.byKey(Key('GROUPS_APP_BAR')), findsNothing); + }); + + testWidgets('Testing if Groups Page Shows up', (tester) async { + await tester.pumpWidget(createHomePageScreen()); + //checking if the first page is newsfeed page + expect(find.byKey(Key('NEWSFEED_APP_BAR')), findsOneWidget); + expect(find.byKey(Key('GROUPS_APP_BAR')), findsNothing); + var chatIcon = find.byIcon(Icons.chat); + //tapping the chatIcon + await tester.tap(chatIcon); + await tester.pumpAndSettle(); + //Group page should be present + expect(find.byKey(Key('GROUPS_APP_BAR')), findsOneWidget); + }); + + testWidgets('Testing if Events Page Shows up', (tester) async { + await tester.pumpWidget(createHomePageScreen()); + //checking if the first page is newsfeed page + expect(find.byKey(Key('NEWSFEED_APP_BAR')), findsOneWidget); + //Events page should be absent + expect(find.byKey(Key('EVENTS_APP_BAR')), findsNothing); + var calendarIcon = find.byIcon(Icons.calendar_today); + //tapping on calendarIcon + await tester.tap(calendarIcon); + await tester.pump(); + //events page should show up + expect(find.byKey(Key('EVENTS_APP_BAR')), findsOneWidget); + }); + + testWidgets('Testing if Member Page Shows up', (tester) async { + await tester.pumpWidget(createHomePageScreen()); + //checking if newsfeed page is present + expect(find.byKey(Key('NEWSFEED_APP_BAR')), findsOneWidget); + expect(find.byKey(Key('ORGANIZATION_APP_BAR')), findsNothing); + var groupIcon = find.byIcon(Icons.group); + await tester.tap(groupIcon); + await tester.pump(); + //Member page should show up + expect(find.byKey(Key('ORGANIZATION_APP_BAR')), findsOneWidget); + }); + + testWidgets('Testing if Profile Page Shows up', (tester) async { + await tester.pumpWidget(createHomePageScreen()); + //checking if newsfeed page is present + expect(find.byKey(Key('NEWSFEED_APP_BAR')), findsOneWidget); + expect(find.byKey(Key('PROFILE_PAGE_SCAFFOLD')), findsNothing); + var folderIcon = find.byIcon(Icons.folder); + await tester.tap(folderIcon); + await tester.pump(); + //profile page should show up + expect(find.byKey(Key('PROFILE_PAGE_SCAFFOLD')), findsOneWidget); + }); + }); +}