Skip to content

Commit

Permalink
Select contact test (PalisadoesFoundation#2301)
Browse files Browse the repository at this point in the history
* Created Test

* Updated Formatting
  • Loading branch information
imshivam-gupta authored and palisadian committed Jan 10, 2024
1 parent fdee105 commit 4c7c5b0
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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<User> orgMembersList = [];

// initialisation
/// This function initializes the [SelectContactViewModel] class.
///
/// more_info_if_required
///
/// **params**:
/// None
///
/// **returns**:
/// None
void initialise() {
_organizationService = locator<OrganizationService>();
}

/// 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>`: void
Future<void> getCurrentOrgUsersList() async {
if (orgMembersList.isEmpty) {
orgMembersList = await _organizationService
.getOrgMembersList(userConfig.currentOrg.id!);
notifyListeners();
}

//return orgMembersList;
}
}
8 changes: 3 additions & 5 deletions lib/views/after_auth_screens/chat/select_contact.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -38,15 +35,16 @@ class _SelectContactState extends State<SelectContact> {
),
),
body: BaseView<SelectContactViewModel>(
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))));
},
Expand Down
36 changes: 31 additions & 5 deletions test/views/after_auth_screens/chat/select_contact_test.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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<User> users = [user1, user2];

when(organizationService.getOrgMembersList("XYZ"))
Expand Down Expand Up @@ -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);
});
});
}

0 comments on commit 4c7c5b0

Please sign in to comment.