-
-
Notifications
You must be signed in to change notification settings - Fork 488
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
written test for post_modal.dart #2304
Changes from 2 commits
324d8cd
bef405a
b83921a
742eaf7
618879b
99c0d9b
40099ff
4deb30a
066f23e
733444a
82cf3db
3d2108e
5b91039
6e21a80
15c15cc
e22de04
87a5c4e
3046abc
bcb0864
a2f6f95
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,6 +44,7 @@ class PostBottomModal extends StatelessWidget { | |
), | ||
), | ||
TextButton( | ||
key: const Key('reportPost'), | ||
onPressed: () { | ||
navigationService.showTalawaErrorSnackBar( | ||
'Your Report has been sent to the Admin', | ||
|
@@ -74,6 +75,7 @@ class PostBottomModal extends StatelessWidget { | |
), | ||
), | ||
TextButton( | ||
key: const Key('deletePost'), | ||
onPressed: () { | ||
deletePost != null | ||
? deletePost!(post) | ||
|
@@ -89,6 +91,7 @@ class PostBottomModal extends StatelessWidget { | |
), | ||
actions: <Widget>[ | ||
TextButton( | ||
key: const Key('yes'), | ||
onPressed: () { | ||
navigationService.showTalawaErrorSnackBar( | ||
'Post was deleted if you had the rights!', | ||
|
@@ -99,6 +102,7 @@ class PostBottomModal extends StatelessWidget { | |
child: const Text("Yes"), | ||
), | ||
TextButton( | ||
key: const Key('no'), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have provided them more descriptive name |
||
onPressed: () { | ||
Navigator.pop(context); | ||
}, | ||
Comment on lines
106
to
108
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These lines are missing. Please write the test for it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have written test for these lines also |
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1013,6 +1013,30 @@ packages: | |
url: "https://pub.dev" | ||
source: hosted | ||
version: "6.7.1" | ||
leak_tracker: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is this package and why is it added ? |
||
dependency: transitive | ||
description: | ||
name: leak_tracker | ||
sha256: "41b90ceaec6d79819f31e975e61d479516efe701dea35f891b2f986c1b031422" | ||
url: "https://pub.dev" | ||
source: hosted | ||
version: "9.0.17" | ||
leak_tracker_flutter_testing: | ||
dependency: transitive | ||
description: | ||
name: leak_tracker_flutter_testing | ||
sha256: "54808cfcfa87dbc0d74c61ac063d624adf1bd5c0407301f32b06c783c60dc4ca" | ||
url: "https://pub.dev" | ||
source: hosted | ||
version: "2.0.0" | ||
leak_tracker_testing: | ||
dependency: transitive | ||
description: | ||
name: leak_tracker_testing | ||
sha256: "7e71be3c161472f6c9158ac8875dd8de575060d60b5d159ebca3600ea32c9116" | ||
url: "https://pub.dev" | ||
source: hosted | ||
version: "1.0.6" | ||
lint: | ||
dependency: "direct dev" | ||
description: | ||
|
@@ -1033,26 +1057,26 @@ packages: | |
dependency: transitive | ||
description: | ||
name: matcher | ||
sha256: "1803e76e6653768d64ed8ff2e1e67bea3ad4b923eb5c56a295c3e634bad5960e" | ||
sha256: d2323aa2060500f906aa31a895b4030b6da3ebdcc5619d14ce1aada65cd161cb | ||
url: "https://pub.dev" | ||
source: hosted | ||
version: "0.12.16" | ||
version: "0.12.16+1" | ||
material_color_utilities: | ||
dependency: transitive | ||
description: | ||
name: material_color_utilities | ||
sha256: "9528f2f296073ff54cb9fee677df673ace1218163c3bc7628093e7eed5203d41" | ||
sha256: "0e0a020085b65b6083975e499759762399b4475f766c21668c4ecca34ea74e5a" | ||
url: "https://pub.dev" | ||
source: hosted | ||
version: "0.5.0" | ||
version: "0.8.0" | ||
meta: | ||
dependency: transitive | ||
description: | ||
name: meta | ||
sha256: a6e590c838b18133bb482a2745ad77c5bb7715fb0451209e1a7567d416678b8e | ||
sha256: d584fa6707a52763a52446f02cc621b077888fb63b93bbcb1143a7be5a0c0c04 | ||
url: "https://pub.dev" | ||
source: hosted | ||
version: "1.10.0" | ||
version: "1.11.0" | ||
mime: | ||
dependency: transitive | ||
description: | ||
|
@@ -1137,10 +1161,10 @@ packages: | |
dependency: transitive | ||
description: | ||
name: path | ||
sha256: "8829d8a55c13fc0e37127c29fedf290c102f4e40ae94ada574091fe0ff96c917" | ||
sha256: "087ce49c3f0dc39180befefc60fdb4acd8f8620e5682fe2476afd0b3688bb4af" | ||
url: "https://pub.dev" | ||
source: hosted | ||
version: "1.8.3" | ||
version: "1.9.0" | ||
path_parsing: | ||
dependency: transitive | ||
description: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,176 @@ | ||
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:talawa/enums/enums.dart'; | ||
import 'package:talawa/models/comment/comment_model.dart'; | ||
import 'package:talawa/models/organization/org_info.dart'; | ||
import 'package:talawa/models/post/post_model.dart'; | ||
import 'package:talawa/models/user/user_info.dart'; | ||
import 'package:talawa/services/navigation_service.dart'; | ||
import 'package:talawa/services/size_config.dart'; | ||
import 'package:talawa/utils/app_localization.dart'; | ||
import 'package:talawa/view_model/lang_view_model.dart'; | ||
import 'package:talawa/views/base_view.dart'; | ||
import 'package:talawa/widgets/post_modal.dart'; | ||
|
||
import '../../helpers/test_helpers.dart'; | ||
import '../../helpers/test_locator.dart'; | ||
|
||
class MockFunction extends Mock { | ||
void call(Post post); | ||
} | ||
|
||
class MockNavigationService extends Mock implements NavigationService {} | ||
|
||
final MockFunction mockDeletePost = MockFunction(); | ||
final LikedBy user = LikedBy(sId: "test_id"); | ||
|
||
final u1 = User( | ||
id: '123', | ||
firstName: 'Lakshay', | ||
lastName: 'Gupta', | ||
email: '[email protected]', | ||
); | ||
final u2 = User( | ||
id: '123', | ||
firstName: 'Ankit', | ||
lastName: 'Varshney', | ||
email: '[email protected]', | ||
); | ||
final List<User> users = [u1, u2]; | ||
List<Comments> comments = [ | ||
Comments(sId: 'comment1'), | ||
Comments(sId: 'comment2'), | ||
Comments(sId: 'comment3'), | ||
Comments(sId: 'comment4'), | ||
Comments(sId: 'comment5'), | ||
Comments(sId: 'comment6'), | ||
]; | ||
final comment = Comment( | ||
creator: User( | ||
id: '123', | ||
firstName: 'Ankit', | ||
lastName: 'Varshney', | ||
email: '[email protected]', | ||
), | ||
createdAt: '123456', | ||
text: 'test text', | ||
post: 'test post', | ||
likeCount: 'test count', | ||
); | ||
|
||
final LikedBy l1 = LikedBy(sId: 'test1'); | ||
final LikedBy l2 = LikedBy(sId: 'test2'); | ||
final List<LikedBy> likeby = [l1, l2]; | ||
|
||
final comment1 = Comments(sId: 'comment1'); | ||
final comment2 = Comments(sId: 'comment2'); | ||
final comment3 = Comments(sId: 'comment3'); | ||
final List<Comments> comments1 = [comment1, comment2, comment3]; | ||
|
||
final myBirthday = DateTime.utc(2004, DateTime.june, 16, 5, 30, 0, 0, 0); | ||
final post = Post( | ||
creator: User( | ||
id: '123', | ||
firstName: 'John', | ||
lastName: 'Doe', | ||
email: '[email protected]', | ||
), | ||
sId: "sid", | ||
createdAt: myBirthday, | ||
description: 'test description', | ||
organization: OrgInfo(admins: users), | ||
likedBy: likeby, | ||
comments: comments1, | ||
); | ||
Widget createPostBottomModal() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add new lines to make the code more readable. |
||
return BaseView<AppLanguage>( | ||
onModelReady: (model) => model.initialize(), | ||
builder: (context, model, child) { | ||
return MaterialApp( | ||
locale: const Locale('en'), | ||
localizationsDelegates: const [ | ||
AppLocalizationsDelegate(isTest: true), | ||
GlobalMaterialLocalizations.delegate, | ||
GlobalWidgetsLocalizations.delegate, | ||
], | ||
home: PostBottomModal( | ||
post: post, | ||
deletePost: mockDeletePost, | ||
), | ||
navigatorKey: navigationService.navigatorKey, | ||
); | ||
}, | ||
); | ||
} | ||
|
||
void main() { | ||
SizeConfig().test(); | ||
testSetupLocator(); | ||
|
||
setUp(() { | ||
registerServices(); | ||
}); | ||
tearDown(() => unregisterServices()); | ||
|
||
group('PostBottomModalTest -', () { | ||
testWidgets('has a post widget', (tester) async { | ||
await tester.pumpWidget(createPostBottomModal()); | ||
await tester.pumpAndSettle(); | ||
|
||
expect(find.byType(PostBottomModal), findsOneWidget); | ||
expect(find.byKey(const Key('reportPost')), findsOneWidget); | ||
|
||
await tester.tap(find.byKey(const Key('reportPost'))); | ||
await tester.pumpAndSettle(); | ||
verify( | ||
navigationService.showTalawaErrorSnackBar( | ||
'Your Report has been sent to the Admin', | ||
MessageType.info, | ||
), | ||
).called(1); | ||
}); | ||
testWidgets('Testing the delete Post button', (WidgetTester tester) async { | ||
await tester.pumpWidget(createPostBottomModal()); | ||
await tester.pumpAndSettle(); | ||
expect(find.byIcon(Icons.delete), findsOneWidget); | ||
expect(find.byKey(const Key("deletePost")), findsOneWidget); | ||
await tester.tap(find.byKey(const Key("deletePost"))); | ||
await tester.pumpAndSettle(); | ||
|
||
verify(mockDeletePost.call(post)).called(1); | ||
|
||
expect(find.byType(AlertDialog), findsOneWidget); | ||
expect(find.byKey(const Key("yes")), findsOneWidget); | ||
expect(find.text("The post was deleted"), findsOneWidget); | ||
|
||
await tester.pumpAndSettle(); | ||
await tester.tap(find.byKey(const Key("yes"))); | ||
await tester.pumpAndSettle(); | ||
|
||
verify( | ||
navigationService.showTalawaErrorSnackBar( | ||
'Post was deleted if you had the rights!', | ||
MessageType.info, | ||
), | ||
).called(1); | ||
}); | ||
testWidgets("Testing no button of alertDialogBox", | ||
(WidgetTester tester) async { | ||
await tester.pumpWidget(createPostBottomModal()); | ||
await tester.pumpAndSettle(); | ||
expect(find.byKey(const Key("deletePost")), findsOneWidget); | ||
await tester.tap(find.byKey(const Key("deletePost"))); | ||
await tester.pumpAndSettle(); | ||
|
||
verify(mockDeletePost.call(post)).called(1); | ||
|
||
expect(find.byType(AlertDialog), findsOneWidget); | ||
expect(find.byKey(const Key('no')), findsOneWidget); | ||
await tester.tap(find.byKey(const Key("no"))); | ||
await tester.pumpAndSettle(); | ||
expect(find.byType(AlertDialog), findsNothing); | ||
}); | ||
}); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Give a descriptive name to the key.