From cadc3475840cb19c2c673987afae559e0b3f6a39 Mon Sep 17 00:00:00 2001 From: ANKIT VARSHNEY <132201033+AVtheking@users.noreply.github.com> Date: Wed, 10 Jan 2024 21:58:35 +0530 Subject: [PATCH] test for individual post screen written (#2300) * test for individual post screen written * removed pubspec.lock * fix falling test case" * removed pubspec.lock * Comprehensive Language Translation Enhancement for App Globalization (#2290) * Comprehensive Language Translation Enhancement for App Globalization * adding more translations * testing * test * test * test * proper format for translation files * formating * formating * formating * fixing translation * fixing linting errors * writing test for missing lines * writing test for missing lines * writing test for missing lines * fixing translations * fixing translations * fixing translations * fixing translations * Bump tj-actions/changed-files from 35 to 41 in /.github/workflows (#2302) Bumps [tj-actions/changed-files](https://github.com/tj-actions/changed-files) from 35 to 41. - [Release notes](https://github.com/tj-actions/changed-files/releases) - [Changelog](https://github.com/tj-actions/changed-files/blob/main/HISTORY.md) - [Commits](https://github.com/tj-actions/changed-files/compare/v35...v41) --- updated-dependencies: - dependency-name: tj-actions/changed-files dependency-type: direct:production ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Add: GraphQl Test (#2298) * Update pull-request.yml * fix failing test case * added pubspec.lock from develop * removed pubspec.lock * lock file * Comprehensive Language Translation Enhancement for App Globalization (#2290) * Comprehensive Language Translation Enhancement for App Globalization * adding more translations * testing * test * test * test * proper format for translation files * formating * formating * formating * fixing translation * fixing linting errors * writing test for missing lines * writing test for missing lines * writing test for missing lines * fixing translations * fixing translations * fixing translations * fixing translations * fix * fix * fix * fix --------- Signed-off-by: dependabot[bot] Co-authored-by: Parag Gupta <103507835+Dante291@users.noreply.github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Ayush Raghuwanshi <62144720+AyushRaghuvanshi@users.noreply.github.com> Co-authored-by: Peter Harrison <16875803+palisadoes@users.noreply.github.com> --- pubspec.lock | 2 +- .../feed/individual_post_test.dart | 266 ++++++++++++++++++ 2 files changed, 267 insertions(+), 1 deletion(-) create mode 100644 test/views/after_auth_screens/feed/individual_post_test.dart diff --git a/pubspec.lock b/pubspec.lock index 77e2873cb3..26e172a960 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -1843,4 +1843,4 @@ packages: version: "3.1.2" sdks: dart: ">=3.2.0 <3.13.0" - flutter: ">=3.16.0" \ No newline at end of file + flutter: ">=3.16.0" diff --git a/test/views/after_auth_screens/feed/individual_post_test.dart b/test/views/after_auth_screens/feed/individual_post_test.dart new file mode 100644 index 0000000000..2751718211 --- /dev/null +++ b/test/views/after_auth_screens/feed/individual_post_test.dart @@ -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( + 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 users = [u1, u2]; +List 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 likeby = [l1, l2]; + +final comment1 = Comments(sId: 'comment1'); +final comment2 = Comments(sId: 'comment2'); +final comment3 = Comments(sId: 'comment3'); +final List 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( + 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( + 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( + 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( + 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); + }); + }); +}