Skip to content

Commit

Permalink
Test for join_organisation_after_auth.dart (PalisadoesFoundation#2260)
Browse files Browse the repository at this point in the history
* Test for join_organisation_after_auth.dart

* modify

* adding more tests for complete coverage
  • Loading branch information
Dante291 authored and palisadian committed Jan 10, 2024
1 parent 41edc64 commit 77cd662
Showing 1 changed file with 103 additions and 12 deletions.
115 changes: 103 additions & 12 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,26 +4,31 @@
import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:mockito/mockito.dart';
import 'package:qr_code_scanner/qr_code_scanner.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_helpers.mocks.dart';
import '../../helpers/test_locator.dart';

Widget createJoinOrgAfterAuth({String orgId = "fake_id"}) {
return BaseView<AppLanguage>(
onModelReady: (model) => model.initialize(),
builder: (context, langModel, child) {
Widget createJoinOrgAfterAuth({
String orgId = "fake_id",
}) {
return BaseView<SelectOrganizationViewModel>(
onModelReady: (model) => model.initialise(orgId),
builder: (context, model, child) {
return MaterialApp(
navigatorKey: navigationService.navigatorKey,
locale: const Locale('en'),
localizationsDelegates: const [
AppLocalizationsDelegate(isTest: true),
Expand Down Expand Up @@ -53,6 +58,99 @@ void main() {
});

group("Tests for JoinOrganizationAfterAuth - widgets", () {
testWidgets('QR Scan Test', (WidgetTester tester) async {
final controller = MockQRViewController();
when(controller.scannedDataStream).thenAnswer((_) async* {
yield Barcode(
' ' + '?orgid=6737904485008f171cf29924',
BarcodeFormat.qrcode,
null,
);
});
when(controller.stopCamera())
.thenAnswer((realInvocation) => Future.value());

await tester.pumpWidget(
createJoinOrgAfterAuth(),
);

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

await tester.tap(find.byIcon(Icons.qr_code_scanner));
await tester.pumpAndSettle();

expect(
find.byWidgetPredicate(
(widget) =>
widget is ClipRRect &&
widget.child is Container &&
(widget.child! as Container).child is Column,
),
findsOneWidget,
);
(tester.widget(find.byType(QRView)) as QRView)
.onQRViewCreated(controller);
});
testWidgets('QR Scan Test when url != GraphqlConfig.orgURI',
(WidgetTester tester) async {
final controller = MockQRViewController();
when(controller.scannedDataStream).thenAnswer((_) async* {
yield Barcode(
'1' + '?orgid=6737904485008f171cf29924',
BarcodeFormat.qrcode,
null,
);
});
when(controller.stopCamera())
.thenAnswer((realInvocation) => Future.value());

await tester.pumpWidget(
createJoinOrgAfterAuth(),
);

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

await tester.tap(find.byIcon(Icons.qr_code_scanner));
await tester.pumpAndSettle();

expect(
find.byWidgetPredicate(
(widget) =>
widget is ClipRRect &&
widget.child is Container &&
(widget.child! as Container).child is Column,
),
findsOneWidget,
);
(tester.widget(find.byType(QRView)) as QRView)
.onQRViewCreated(controller);
});
testWidgets('Test _onQRViewCreated when throwing exception',
(WidgetTester tester) async {
final controller = MockQRViewController();
when(controller.scannedDataStream).thenAnswer((_) async* {
yield Barcode(
' ' + '?orgid=6737904485008f171cf29924',
BarcodeFormat.qrcode,
null,
);
});
when(controller.stopCamera())
.thenAnswer((realInvocation) => Future.value());

await tester.pumpWidget(
createJoinOrgAfterAuth(),
);
when(controller.stopCamera()).thenThrow(Exception("exception"));

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

await tester.tap(find.byIcon(Icons.qr_code_scanner));
await tester.pumpAndSettle();

(tester.widget(find.byType(QRView)) as QRView)
.onQRViewCreated(controller);
});
testWidgets(
"Check if JoinOrganizationsAfterAuth shows up",
(tester) async {
Expand Down Expand Up @@ -132,13 +230,6 @@ void main() {
/// 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(
Expand Down

0 comments on commit 77cd662

Please sign in to comment.