Skip to content

Commit

Permalink
Fixes #1612 No Messaging When No Organizations are Created (#1782)
Browse files Browse the repository at this point in the history
* Fixes #1612 No Messaging When No Organizations are Created

* Add constant time-out for loading data.

* Add constant time-out for loading data.

* Fixed the failing test

* Fixed the failing test

* Removed the unsed imports.

* modified test

* formating
  • Loading branch information
Ayush0Chaudhary authored Jul 19, 2023
1 parent 481779d commit 6e051cd
Showing 1 changed file with 106 additions and 100 deletions.
206 changes: 106 additions & 100 deletions test/views/after_auth_screens/join_organisation_after_auth_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,17 @@
import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:talawa/enums/enums.dart';
import 'package:talawa/models/organization/org_info.dart';
import 'package:talawa/models/user/user_info.dart';
import 'package:talawa/services/graphql_config.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/view_model/pre_auth_view_models/select_organization_view_model.dart';
import 'package:talawa/views/after_auth_screens/join_org_after_auth/join_organisation_after_auth.dart';
import 'package:talawa/views/base_view.dart';
import 'package:talawa/widgets/organization_search_list.dart';

import '../../helpers/test_helpers.dart';
import '../../helpers/test_locator.dart';
Expand Down Expand Up @@ -58,46 +63,46 @@ void main() {
},
);

// testWidgets(
// "Check if children show up correctly",
// (tester) async {
// await tester.pumpWidget(createJoinOrgAfterAuth());
// await tester.pumpAndSettle(const Duration(seconds: 6));
//
// expect(
// find.byWidgetPredicate(
// (widget) => widget is Scaffold && widget.body is Column,
// ),
// findsOneWidget,
// );
//
// // expect(
// // find.byWidgetPredicate(
// // (widget) =>
// // widget is Column &&
// // widget.children[0] is Padding &&
// // widget.children[1] is ColoredBox &&
// // widget.children[2] is Padding &&
// // widget.children[3] is Expanded &&
// // widget.children[4] is SizedBox &&
// // widget.children[5] is Column,
// // ),
// // findsOneWidget,
// // );
//
// // expect(
// // find.byWidgetPredicate(
// // (widget) =>
// // widget is Column &&
// // widget.children[0] is RaisedRoundedButton &&
// // (widget.children[0] as RaisedRoundedButton).buttonLabel ==
// // "Join selected organisation" &&
// // widget.children[1] is SizedBox,
// // ),
// // findsOneWidget,
// // );
// },
// );
testWidgets(
"Check if children show up correctly",
(tester) async {
await tester.pumpWidget(createJoinOrgAfterAuth());
await tester.pumpAndSettle(const Duration(seconds: 6));

expect(
find.byWidgetPredicate(
(widget) => widget is Scaffold && widget.body is Column,
),
findsOneWidget,
);

// expect(
// find.byWidgetPredicate(
// (widget) =>
// widget is Column &&
// widget.children[0] is Padding &&
// widget.children[1] is ColoredBox &&
// widget.children[2] is Padding &&
// widget.children[3] is Expanded &&
// widget.children[4] is SizedBox &&
// widget.children[5] is Column,
// ),
// findsOneWidget,
// );

// expect(
// find.byWidgetPredicate(
// (widget) =>
// widget is Column &&
// widget.children[0] is RaisedRoundedButton &&
// (widget.children[0] as RaisedRoundedButton).buttonLabel ==
// "Join selected organisation" &&
// widget.children[1] is SizedBox,
// ),
// findsOneWidget,
// );
},
);
});

group("Tests for JoinOrganizationAfterAuth - widgets", () {
Expand All @@ -123,67 +128,68 @@ void main() {
// re-register SelectOrganizationViewModel in that test as it will
// be disposed once this test ends, or better, write any new tests
// before this one.

/// Search is No-Longer is a feature, if it gets implemented in future use this test
/// Really good test to learn from so not deleting
// testWidgets("Check if model related functions work", (tester) async {
// // Registers a singleton, which means that every instance of
// // SelectOrganizationViewModel will be the same.
// locator.unregister<SelectOrganizationViewModel>();
// locator.registerSingleton<SelectOrganizationViewModel>(
// SelectOrganizationViewModel(),
// );
//
// final orgOne = OrgInfo(
// name: "org_one",
// creatorInfo: User(
// firstName: "ravidi",
// lastName: "shaikh",
// ),
// isPublic: false,
// );
// final orgTwo = OrgInfo(
// name: "org_two",
// creatorInfo: User(
// firstName: "ravidi",
// lastName: "shaikh",
// ),
// isPublic: false,
// );
//
// final selectOrgInfoVM = locator.get<SelectOrganizationViewModel>();
//
// await tester.pumpWidget(createJoinOrgAfterAuth());
// await tester.pumpAndSettle(const Duration(seconds: 6));
//
// // This button comes from CupertinoSearchTextField
// // await tester.tap(find.byType(CupertinoButton));
// // await tester.pumpAndSettle(const Duration(seconds: 6));
//
// // Checking for text change
// selectOrgInfoVM.setState(ViewState.busy);
// selectOrgInfoVM.searchController.text = "tmmmext";
// await tester.pumpAndSettle(const Duration(seconds: 6));
//
// expect(find.text("tmmmext"), findsOneWidget);
//
// // Checking for Org selection
//
// expect(selectOrgInfoVM.organizations, []);
//
// selectOrgInfoVM.organizations = [
// orgOne,
// orgTwo,
// ];
//
// selectOrgInfoVM.selectedOrganization = orgOne;
//
// selectOrgInfoVM.notifyListeners();
// await tester.pumpAndSettle(const Duration(seconds: 6));
//
// selectOrgInfoVM.searching = true;
// selectOrgInfoVM.notifyListeners();
//
// expect(find.byType(OrganizationSearchList), findsNothing);
// });
testWidgets("Check if model related functions work", (tester) async {
// Registers a singleton, which means that every instance of
// SelectOrganizationViewModel will be the same.
locator.unregister<SelectOrganizationViewModel>();
locator.registerSingleton<SelectOrganizationViewModel>(
SelectOrganizationViewModel(),
);

final orgOne = OrgInfo(
name: "org_one",
creatorInfo: User(
firstName: "ravidi",
lastName: "shaikh",
),
isPublic: false,
);
final orgTwo = OrgInfo(
name: "org_two",
creatorInfo: User(
firstName: "ravidi",
lastName: "shaikh",
),
isPublic: false,
);

final selectOrgInfoVM = locator.get<SelectOrganizationViewModel>();

await tester.pumpWidget(createJoinOrgAfterAuth());
await tester.pumpAndSettle(const Duration(seconds: 6));

// This button comes from CupertinoSearchTextField
// await tester.tap(find.byType(CupertinoButton));
// await tester.pumpAndSettle(const Duration(seconds: 6));

// Checking for text change
selectOrgInfoVM.setState(ViewState.busy);
selectOrgInfoVM.searchController.text = "tmmmext";
await tester.pumpAndSettle(const Duration(seconds: 6));

// expect(find.text("tmmmext"), findsOneWidget);

// Checking for Org selection

expect(selectOrgInfoVM.organizations, []);

selectOrgInfoVM.organizations = [
orgOne,
orgTwo,
];

selectOrgInfoVM.selectedOrganization = orgOne;

selectOrgInfoVM.notifyListeners();
await tester.pumpAndSettle(const Duration(seconds: 6));

selectOrgInfoVM.searching = true;
selectOrgInfoVM.notifyListeners();

expect(find.byType(OrganizationSearchList), findsNothing);
});
});
}

0 comments on commit 6e051cd

Please sign in to comment.