Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test : Added widget test for home_page.dart #523

Merged
merged 4 commits into from
Mar 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/views/pages/chat/groups.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class _GroupsState extends State<Groups> {
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
key: Key('GROUPS_APP_BAR'),
title: Text(
'Chats',
style: TextStyle(color: Colors.white),
Expand Down
1 change: 1 addition & 0 deletions lib/views/pages/events/events.dart
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ class _EventsState extends State<Events> {
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
key: Key('EVENTS_APP_BAR'),
title: Text(
'Events',
style: TextStyle(color: Colors.white),
Expand Down
69 changes: 44 additions & 25 deletions lib/views/pages/home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,7 @@ class _HomePageState extends State<HomePage> {
void initState() {
super.initState();
currentIndex = widget.openPageIndex;
_controller =
PersistentTabController(initialIndex: currentIndex);
Provider.of<GraphQLConfiguration>(context, listen: false).getOrgUrl();
Provider.of<Preferences>(context, listen: false).getCurrentOrgId();
_controller = PersistentTabController(initialIndex: currentIndex);
}

void dispose() {
Expand Down Expand Up @@ -73,32 +70,32 @@ class _HomePageState extends State<HomePage> {
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,
),
];
}
Expand All @@ -111,16 +108,38 @@ class _HomePageState extends State<HomePage> {

@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<GraphQLConfiguration>(
create: (_) => GraphQLConfiguration(),
),
ChangeNotifierProvider<Preferences>(
create: (_) => Preferences(),
)
],
child: Builder(builder: (BuildContext context) {
BuildContext rootContext = context;
Provider.of<GraphQLConfiguration>(rootContext, listen: false)
.getOrgUrl();
Provider.of<Preferences>(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),
));
}),
);
}
}
}
1 change: 1 addition & 0 deletions lib/views/pages/members/members.dart
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ class _OrganizationsState extends State<Organizations> {
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
key: Key('ORGANIZATION_APP_BAR'),
title: Text(
'Members',
style: TextStyle(color: Colors.white),
Expand Down
2 changes: 1 addition & 1 deletion lib/views/pages/newsfeed/newsfeed.dart
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class _NewsFeedState extends State<NewsFeed> {
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())
Expand Down
1 change: 1 addition & 0 deletions lib/views/pages/organization/profile_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ class _ProfilePageState extends State<ProfilePage> {
@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'),))
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
131 changes: 131 additions & 0 deletions test/widget_tests/home_page_test.dart
Original file line number Diff line number Diff line change
@@ -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<GraphQLConfiguration>(
create: (_) => GraphQLConfiguration(),
),
ChangeNotifierProvider<OrgController>(
create: (_) => OrgController(),
),
ChangeNotifierProvider<AuthController>(
create: (_) => AuthController(),
),
ChangeNotifierProvider<Preferences>(
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);
});
});
}