-
-
Notifications
You must be signed in to change notification settings - Fork 479
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 for individual post screen written #2300
Merged
palisadoes
merged 20 commits into
PalisadoesFoundation:develop
from
AVtheking:fix/individual_post_screen_test
Jan 10, 2024
Merged
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
c277f9e
test for individual post screen written
AVtheking b45b2b1
removed pubspec.lock
AVtheking 477ec4a
fix falling test case"
AVtheking 0b81dfb
removed pubspec.lock
AVtheking cd18097
Comprehensive Language Translation Enhancement for App Globalization …
Dante291 b0969a3
Bump tj-actions/changed-files from 35 to 41 in /.github/workflows (#2…
dependabot[bot] 4bc2544
Add: GraphQl Test (#2298)
AyushRaghuvanshi 50f3ca4
Update pull-request.yml
palisadoes d270c05
fix failing test case
AVtheking 5244bde
Merge branch 'develop' into fix/individual_post_screen_test
AVtheking 2124a06
added pubspec.lock from develop
AVtheking e37c3ac
Merge branch 'develop' into fix/individual_post_screen_test
AVtheking 1eddad0
removed pubspec.lock
AVtheking 7e6acee
lock file
AVtheking b2c0efa
Comprehensive Language Translation Enhancement for App Globalization …
Dante291 e98141d
fix
AVtheking 701623b
fix
AVtheking 3cc697f
fix
AVtheking 55ce6b8
fix
AVtheking c7d55b2
Merge branch 'develop' into fix/individual_post_screen_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
266 changes: 266 additions & 0 deletions
266
test/views/after_auth_screens/feed/individual_post_test.dart
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,266 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_localizations/flutter_localizations.dart'; | ||
import 'package:flutter_test/flutter_test.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/size_config.dart'; | ||
import 'package:talawa/utils/app_localization.dart'; | ||
import 'package:talawa/view_model/lang_view_model.dart'; | ||
import 'package:talawa/views/after_auth_screens/feed/individual_post.dart'; | ||
import 'package:talawa/views/base_view.dart'; | ||
import 'package:talawa/widgets/post_widget.dart'; | ||
|
||
import '../../../helpers/test_helpers.dart'; | ||
import '../../../helpers/test_locator.dart'; | ||
|
||
Widget createIndividualPostViewWidget(Post post) { | ||
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: IndividualPostView(post: post), | ||
navigatorKey: navigationService.navigatorKey, | ||
); | ||
}, | ||
); | ||
} | ||
|
||
final LikedBy user = LikedBy(sId: "test_id"); | ||
|
||
final u1 = User( | ||
id: '123', | ||
firstName: 'Lakshay', | ||
lastName: 'Gupta', | ||
email: 'test@test.com', | ||
); | ||
final u2 = User( | ||
id: '123', | ||
firstName: 'Ankit', | ||
lastName: 'Varshney', | ||
email: 'test@test.com', | ||
); | ||
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: 'test@test.com', | ||
), | ||
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: 'test@test.com', | ||
), | ||
sId: "sid", | ||
createdAt: myBirthday, | ||
description: 'test description', | ||
organization: OrgInfo(admins: users), | ||
likedBy: likeby, | ||
comments: comments1, | ||
); | ||
Widget createLikedUserCircleAvatar(LikedBy user) { | ||
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: likedUserCircleAvatar(user), | ||
navigatorKey: navigationService.navigatorKey, | ||
); | ||
}, | ||
); | ||
} | ||
|
||
Widget createIndividualPageLikeSection() { | ||
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: IndividualPageLikeSection( | ||
usersLiked: [ | ||
LikedBy(sId: 'test1'), | ||
LikedBy(sId: 'test2'), | ||
LikedBy(sId: 'test3'), | ||
LikedBy(sId: 'test4'), | ||
], | ||
), | ||
navigatorKey: navigationService.navigatorKey, | ||
); | ||
}, | ||
); | ||
} | ||
|
||
Widget createIndividualPostCommentSectionWidget() { | ||
return MaterialApp( | ||
locale: const Locale('en'), | ||
localizationsDelegates: const [ | ||
AppLocalizationsDelegate(isTest: true), | ||
GlobalMaterialLocalizations.delegate, | ||
GlobalWidgetsLocalizations.delegate, | ||
], | ||
home: BaseView<AppLanguage>( | ||
onModelReady: (model) { | ||
model.initialize(); | ||
}, | ||
builder: (context, model, child) { | ||
return IndividualPostCommentSection( | ||
comments: comments, | ||
postID: 'test post id', | ||
); | ||
}, | ||
), | ||
); | ||
} | ||
|
||
Widget createCommentTemplateWidget(Comment comment) { | ||
return MaterialApp( | ||
locale: const Locale('en'), | ||
localizationsDelegates: const [ | ||
AppLocalizationsDelegate(isTest: true), | ||
GlobalMaterialLocalizations.delegate, | ||
GlobalWidgetsLocalizations.delegate, | ||
], | ||
home: BaseView<AppLanguage>( | ||
onModelReady: (model) { | ||
model.initialize(); | ||
}, | ||
builder: (context, model, child) { | ||
return CommentTemplate(comment: comment); | ||
}, | ||
), | ||
); | ||
} | ||
|
||
void main() { | ||
SizeConfig().test(); | ||
testSetupLocator(); | ||
|
||
setUp(() { | ||
registerServices(); | ||
}); | ||
|
||
group("testing Individual Post View ", () { | ||
testWidgets("test IndividualPostWidget", (WidgetTester tester) async { | ||
await tester.pumpWidget(createIndividualPostViewWidget(post)); | ||
await tester.pumpAndSettle(); | ||
|
||
expect(find.byKey(const Key('indi_post_tf_key')), findsOneWidget); | ||
await tester.enterText( | ||
find.byKey(const Key('indi_post_tf_key')), | ||
'Test Comment', | ||
); | ||
await tester.pumpAndSettle(); | ||
|
||
//verify that the text is entered in the text field | ||
expect(find.text('Test Comment'), findsOneWidget); | ||
|
||
// Tap the send button. | ||
await tester.tap(find.byType(TextButton)); | ||
await tester.pumpAndSettle(); | ||
|
||
expect(find.byType(NewsPost), findsOneWidget); | ||
expect(find.byType(IndividualPageLikeSection), findsOneWidget); | ||
expect(find.byType(IndividualPostCommentSection), findsOneWidget); | ||
}); | ||
}); | ||
|
||
group("Test for likedUserCircleAvatar", () { | ||
testWidgets("checking if likedUserCircleAvatar widget correctly shows up", | ||
(WidgetTester tester) async { | ||
await tester.pumpWidget(createLikedUserCircleAvatar(user)); | ||
await tester.pumpAndSettle(); | ||
|
||
expect(find.byType(CircleAvatar), findsOneWidget); | ||
}); | ||
}); | ||
group("Test for IndividualPageLikeSection", () { | ||
testWidgets( | ||
"checking if IndividualPageLikeSection widget correctly shows up", | ||
(WidgetTester tester) async { | ||
await tester.pumpWidget(createIndividualPageLikeSection()); | ||
await tester.pumpAndSettle(); | ||
expect(find.text("Liked by"), findsOneWidget); | ||
|
||
expect(find.byType(Row), findsOneWidget); | ||
expect( | ||
find.byWidget(likedUserCircleAvatar(user)), | ||
findsNWidgets(4), | ||
); | ||
}); | ||
}); | ||
|
||
group("Test for IndividualPostCommentSection", () { | ||
testWidgets( | ||
"checking if IndividualPostCommentSection widget correctly shows up", | ||
(WidgetTester tester) async { | ||
await tester.pumpWidget(createIndividualPostCommentSectionWidget()); | ||
await tester.pumpAndSettle(); | ||
|
||
expect(find.text("Comments"), findsOneWidget); | ||
}); | ||
}); | ||
group("Test for CommentTemplate", () { | ||
testWidgets("checking the comment template widgets", | ||
(WidgetTester tester) async { | ||
await tester.pumpWidget(createCommentTemplateWidget(comment)); | ||
await tester.pumpAndSettle(); | ||
|
||
expect(find.byType(Row), findsOneWidget); | ||
expect(find.byType(CircleAvatar), findsOneWidget); | ||
expect(find.byType(Column), findsOneWidget); | ||
expect( | ||
find.text( | ||
"${comment.creator!.firstName!} ${comment.creator!.lastName!}", | ||
), | ||
findsOneWidget, | ||
); | ||
expect(find.text(comment.text!), findsOneWidget); | ||
}); | ||
}); | ||
} |
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.
why this?
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 copied the lock file from develop branch