-
-
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
Merged
palisadoes
merged 20 commits into
PalisadoesFoundation:develop
from
AVtheking:fix/test_for_post_modal
Jan 10, 2024
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
324d8cd
written test for post_modal.dart
AVtheking bef405a
written the missing test
AVtheking b83921a
descriptive name to the key
AVtheking 742eaf7
fix failing test
AVtheking 618879b
created settings page (#2299)
Azad99-9 99c0d9b
rebased
AVtheking 40099ff
descriptive name to the key
AVtheking 4deb30a
Select contact test (#2301)
imshivam-gupta 066f23e
fixed fetch events bug (#2308)
Azad99-9 733444a
Refactor: Decouple ViewModel by Moving UI Logic to View (#2306)
Dante291 82cf3db
fix: Removed all references to Google firebase (#2257)
Abhisheksainii 3d2108e
Bump syncfusion_flutter_datepicker from 24.1.43 to 24.1.44 (#2315)
dependabot[bot] 5b91039
Bump url_launcher_platform_interface from 2.2.0 to 2.3.0 (#2314)
dependabot[bot] 6e21a80
Bump image_picker from 1.0.5 to 1.0.6 (#2313)
dependabot[bot] 15c15cc
Bump video_player from 2.8.1 to 2.8.2 (#2317)
dependabot[bot] e22de04
Bump google_maps_flutter from 2.5.0 to 2.5.1 (#2316)
dependabot[bot] 87a5c4e
merged develop branch
AVtheking 3046abc
Merge branch 'develop' into fix/test_for_post_modal
AVtheking bcb0864
fix
AVtheking a2f6f95
fix failing test
AVtheking File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1843,4 +1843,4 @@ packages: | |
version: "3.1.2" | ||
sdks: | ||
dart: ">=3.2.0 <3.13.0" | ||
flutter: ">=3.16.0" | ||
flutter: ">=3.16.0" | ||
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. Not entirely sure about this EOF line. Commenting just in case. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,202 @@ | ||
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'; | ||
|
||
//Mock classes | ||
class MockFunction extends Mock { | ||
void call(Post post); | ||
} | ||
|
||
class MockNavigationService extends Mock implements NavigationService {} | ||
|
||
//test data | ||
final MockFunction mockDeletePost = MockFunction(); | ||
final LikedBy user = LikedBy(sId: "test_id"); | ||
|
||
//fake user data | ||
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'), | ||
]; | ||
|
||
//fake comment data | ||
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); | ||
|
||
//fake post data | ||
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(); | ||
|
||
// Verify the existence of PostBottomModal widget and reportPost button | ||
expect(find.byType(PostBottomModal), findsOneWidget); | ||
expect(find.byKey(const Key('reportPost')), findsOneWidget); | ||
|
||
// Tap the reportPost button and verify the behavior | ||
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', (tester) async { | ||
await tester.pumpWidget(createPostBottomModal()); | ||
await tester.pumpAndSettle(); | ||
|
||
// Verify the existence of delete Post button | ||
expect(find.byIcon(Icons.delete), findsOneWidget); | ||
expect(find.byKey(const Key('deletePost')), findsOneWidget); | ||
|
||
// Tap the delete Post button and verify the behavior | ||
await tester.tap(find.byKey(const Key('deletePost'))); | ||
await tester.pumpAndSettle(); | ||
|
||
verify(mockDeletePost.call(post)).called(1); | ||
|
||
// Verify the presence of AlertDialog and its elements | ||
expect(find.byType(AlertDialog), findsOneWidget); | ||
expect(find.byKey(const Key('alert_dialog_yes_btn')), findsOneWidget); | ||
expect(find.text('The post was deleted'), findsOneWidget); | ||
|
||
// Tap the yes button in AlertDialog and verify the behavior | ||
await tester.tap(find.byKey(const Key('alert_dialog_yes_btn'))); | ||
await tester.pumpAndSettle(); | ||
|
||
verify( | ||
navigationService.showTalawaErrorSnackBar( | ||
'Post was deleted if you had the rights!', | ||
MessageType.info, | ||
), | ||
).called(1); | ||
}); | ||
|
||
testWidgets("Testing no button of alertDialogBox", (tester) async { | ||
await tester.pumpWidget(createPostBottomModal()); | ||
await tester.pumpAndSettle(); | ||
|
||
// Tap the delete Post button and verify the behavior | ||
expect(find.byKey(const Key('deletePost')), findsOneWidget); | ||
await tester.tap(find.byKey(const Key('deletePost'))); | ||
await tester.pumpAndSettle(); | ||
|
||
verify(mockDeletePost.call(post)).called(1); | ||
|
||
// Verify the presence of AlertDialog and its no button | ||
expect(find.byType(AlertDialog), findsOneWidget); | ||
expect(find.byKey(const Key('alert_dialog_no_btn')), findsOneWidget); | ||
|
||
// Tap the no button in AlertDialog and verify the behavior | ||
await tester.tap(find.byKey(const Key('alert_dialog_no_btn'))); | ||
await tester.pumpAndSettle(); | ||
|
||
// Verify that AlertDialog is dismissed | ||
expect(find.byType(AlertDialog), findsNothing); | ||
}); | ||
}); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
These lines are missing. Please write the test for it.
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.
https://app.codecov.io/gh/PalisadoesFoundation/talawa/pull/2304/blob/lib/widgets/post_modal.dart
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.
I have written test for these lines also