diff --git a/lib/view_model/after_auth_view_models/chat_view_models/select_contact_view_model.dart b/lib/view_model/after_auth_view_models/chat_view_models/select_contact_view_model.dart index 35265c394d..321db17e1b 100644 --- a/lib/view_model/after_auth_view_models/chat_view_models/select_contact_view_model.dart +++ b/lib/view_model/after_auth_view_models/chat_view_models/select_contact_view_model.dart @@ -1,6 +1,3 @@ -// ignore_for_file: talawa_api_doc -// ignore_for_file: talawa_good_doc_comments - import 'package:talawa/locator.dart'; import 'package:talawa/models/user/user_info.dart'; import 'package:talawa/services/org_service.dart'; @@ -12,20 +9,35 @@ import 'package:talawa/view_model/base_view_model.dart'; /// * `getCurrentOrgUsersList` : to get all users of current organization. class SelectContactViewModel extends BaseModel { late OrganizationService _organizationService; + + /// orgMembersList is used to store all users of current organization. late List orgMembersList = []; - // initialisation + /// This function initializes the [SelectContactViewModel] class. + /// + /// more_info_if_required + /// + /// **params**: + /// None + /// + /// **returns**: + /// None void initialise() { _organizationService = locator(); } - /// This function is used to get all users list of an current organization. + /// function to get all users of current organization. + /// + /// **params**: + /// None + /// + /// **returns**: + /// * `Future`: void Future getCurrentOrgUsersList() async { if (orgMembersList.isEmpty) { orgMembersList = await _organizationService .getOrgMembersList(userConfig.currentOrg.id!); + notifyListeners(); } - - //return orgMembersList; } } diff --git a/lib/views/after_auth_screens/chat/select_contact.dart b/lib/views/after_auth_screens/chat/select_contact.dart index 94b014afa4..180abe47c9 100644 --- a/lib/views/after_auth_screens/chat/select_contact.dart +++ b/lib/views/after_auth_screens/chat/select_contact.dart @@ -1,6 +1,3 @@ -// ignore_for_file: talawa_api_doc -// ignore_for_file: talawa_good_doc_comments - import 'package:flutter/material.dart'; import 'package:talawa/locator.dart'; import 'package:talawa/view_model/after_auth_view_models/chat_view_models/select_contact_view_model.dart'; @@ -38,15 +35,16 @@ class _SelectContactState extends State { ), ), body: BaseView( - onModelReady: (model) { + onModelReady: (model) async { model.initialise(); - model.getCurrentOrgUsersList(); + await model.getCurrentOrgUsersList(); }, builder: (context, model, child) { return ListView.builder( itemCount: model.orgMembersList.length, itemBuilder: (context, index) { return GestureDetector( + key: Key('select_contact_gesture_$index'), onTap: () { // Navigator.push(context, MaterialPageRoute(builder: (context)=>ChatMessageScreen(chat: ChatListTileDataModel(ChatUser(model.orgMembersList[index].firstName,model.orgMembersList[index].id,model.orgMembersList[index].image),null,0)))); }, diff --git a/test/views/after_auth_screens/chat/select_contact_test.dart b/test/views/after_auth_screens/chat/select_contact_test.dart index 1513df7e5c..e581e4f524 100644 --- a/test/views/after_auth_screens/chat/select_contact_test.dart +++ b/test/views/after_auth_screens/chat/select_contact_test.dart @@ -1,6 +1,3 @@ -// ignore_for_file: talawa_api_doc -// ignore_for_file: talawa_good_doc_comments - import 'package:flutter/material.dart'; import 'package:flutter_localizations/flutter_localizations.dart'; import 'package:flutter_test/flutter_test.dart'; @@ -78,8 +75,8 @@ void main() { registerViewModels(); final model = SelectContactViewModel(); model.initialise(); - final User user1 = User(id: "fakeUser1"); - final User user2 = User(id: "fakeUser2"); + final User user1 = User(id: "fakeUser1", firstName: "Shivam"); + final User user2 = User(id: "fakeUser2", firstName: "Talawa"); final List users = [user1, user2]; when(organizationService.getOrgMembersList("XYZ")) @@ -109,4 +106,33 @@ void main() { expect(find.byType(Scaffold), findsOneWidget); }); + + testWidgets("Test if list view is visible", (WidgetTester tester) async { + await tester.runAsync(() async { + await tester.pumpWidget(createApp()); + await tester.pump(); + await tester.pumpAndSettle(const Duration(milliseconds: 4000)); + + expect(find.byType(ListView), findsOneWidget); + expect( + find.byKey( + const ValueKey('select_contact_gesture_0'), + ), + findsNWidgets(1), + ); + expect( + find.byKey( + const ValueKey('select_contact_gesture_1'), + ), + findsNWidgets(1), + ); + final gesturedetect = find.byKey( + const ValueKey('select_contact_gesture_1'), + ); + await tester.tap(gesturedetect); + + expect(find.text('Shivam'), findsOneWidget); + expect(find.text('Talawa'), findsOneWidget); + }); + }); }