From 22100ac12c2cf79a4101c81d4d284f86864e98cd Mon Sep 17 00:00:00 2001 From: Shaik Azad <120930148+Azad99-9@users.noreply.github.com> Date: Sat, 27 Apr 2024 21:43:16 +0530 Subject: [PATCH] Made custom_drawer.dart coverage 100% (#2490) * made custom_drawer.dart coverage 100% * minor change * minor change --- lib/services/navigation_service.dart | 1 - .../custom_drawer_view_model.dart | 18 +++++++++ lib/widgets/custom_drawer.dart | 26 +----------- pubspec.lock | 4 +- pubspec.yaml | 2 +- .../widgets/custom_drawer_test.dart | 40 +++++++++++-------- 6 files changed, 46 insertions(+), 45 deletions(-) diff --git a/lib/services/navigation_service.dart b/lib/services/navigation_service.dart index 909a91a2d..baecf3dc5 100644 --- a/lib/services/navigation_service.dart +++ b/lib/services/navigation_service.dart @@ -96,7 +96,6 @@ class NavigationService { /// **returns**: /// None void pushDialog(Widget dialog) { - print('came'); showDialog( context: navigatorKey.currentContext!, barrierColor: Colors.transparent, diff --git a/lib/view_model/widgets_view_models/custom_drawer_view_model.dart b/lib/view_model/widgets_view_models/custom_drawer_view_model.dart index 1daab37b2..564ef0f39 100644 --- a/lib/view_model/widgets_view_models/custom_drawer_view_model.dart +++ b/lib/view_model/widgets_view_models/custom_drawer_view_model.dart @@ -6,6 +6,7 @@ import 'package:talawa/models/organization/org_info.dart'; import 'package:talawa/models/user/user_info.dart'; import 'package:talawa/view_model/base_view_model.dart'; import 'package:talawa/view_model/main_screen_view_model.dart'; +import 'package:talawa/widgets/custom_alert_dialog.dart'; import 'package:tutorial_coach_mark/tutorial_coach_mark.dart'; /// CustomDrawerViewModel class helps to serve the data and to react to user's input for Custom Dialog Widget. @@ -117,6 +118,23 @@ class CustomDrawerViewModel extends BaseModel { } } + /// returns an exit alert dialog. + /// + /// **params**: + /// None + /// + /// **returns**: + /// * `CustomAlertDialog`: returns customAlertDialogBox. + CustomAlertDialog exitAlertDialog() { + return CustomAlertDialog( + key: const Key("Exit?"), + reverse: true, + dialogSubTitle: 'Are you sure you want to exit this organization?', + successText: 'Exit', + success: () {}, + ); + } + /// This function switches the current organization to new organization. /// /// **params**: diff --git a/lib/widgets/custom_drawer.dart b/lib/widgets/custom_drawer.dart index 10e1ebd71..0ebe1f0b7 100644 --- a/lib/widgets/custom_drawer.dart +++ b/lib/widgets/custom_drawer.dart @@ -6,7 +6,6 @@ import 'package:talawa/utils/app_localization.dart'; import 'package:talawa/view_model/main_screen_view_model.dart'; import 'package:talawa/view_model/widgets_view_models/custom_drawer_view_model.dart'; import 'package:talawa/views/base_view.dart'; -import 'package:talawa/widgets/custom_alert_dialog.dart'; import 'package:talawa/widgets/custom_avatar.dart'; import 'package:talawa/widgets/from_palisadoes.dart'; @@ -154,7 +153,8 @@ class CustomDrawer extends StatelessWidget { ? ListTile( key: MainScreenViewModel .keyDrawerLeaveCurrentOrg, - onTap: () => exitButton(), + onTap: () => navigationService + .pushDialog(model.exitAlertDialog()), leading: const Icon(Icons.logout, size: 30), title: Text( AppLocalizations.of(context)! @@ -185,26 +185,4 @@ class CustomDrawer extends StatelessWidget { }, ); } - - /// Button to exit the organization. - /// - /// **params**: - /// None - /// - /// **returns**: - /// None - - void exitButton() { - return navigationService.pushDialog( - CustomAlertDialog( - key: const Key("Exit?"), - reverse: true, - dialogSubTitle: 'Are you sure you want to exit this organization?', - successText: 'Exit', - success: () { - //Exit org - }, - ), - ); - } } diff --git a/pubspec.lock b/pubspec.lock index 99e4dcfc7..93c585333 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -641,10 +641,10 @@ packages: dependency: transitive description: name: hotreloader - sha256: "94ee21a60ea2836500799f3af035dc3212b1562027f1e0031c14e087f0231449" + sha256: ed56fdc1f3a8ac924e717257621d09e9ec20e308ab6352a73a50a1d7a4d9158e url: "https://pub.dev" source: hosted - version: "4.1.0" + version: "4.2.0" html: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index f0bb1a231..fcdf5540d 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -50,7 +50,7 @@ dependencies: http: ^1.2.1 image_cropper: ^5.0.1 image_picker: ^1.0.6 - intl: ^0.18.0 + intl: ^0.18.1 json_annotation: ^4.7.0 mockito: ^5.4.4 network_image_mock: ^2.1.1 diff --git a/test/widget_tests/widgets/custom_drawer_test.dart b/test/widget_tests/widgets/custom_drawer_test.dart index 850a49985..08e6f9e11 100644 --- a/test/widget_tests/widgets/custom_drawer_test.dart +++ b/test/widget_tests/widgets/custom_drawer_test.dart @@ -100,23 +100,29 @@ void main() async { await Hive.openBox('url'); group('Exit Button', () { - /* testWidgets("Tapping Tests for Exit", (tester) async { - await tester.pumpWidget(createHomePageScreen()); - await tester.pumpAndSettle(); - tester.binding.window.physicalSizeTestValue = const Size(4000, 4000); - MainScreenViewModel.scaffoldKey.currentState?.openDrawer(); - await tester.pumpAndSettle(); - final leaveOrg = find.byKey(MainScreenViewModel.keyDrawerLeaveCurrentOrg); - await tester.tap(leaveOrg); - await tester.pumpAndSettle(); - final dialogPopUP = verify( - (locator() as MockNavigationService) - .pushDialog(captureAny)) - .captured; - expect(dialogPopUP[0], isA()); - // calling success() to have complete code coverage. - dialogPopUP[0].success(); - });*/ + testWidgets("Tapping Tests for Exit", (tester) async { + final customDrawerViewModel = CustomDrawerViewModel(); + + final Widget buildAlertDialog = MaterialApp( + locale: const Locale('en'), + localizationsDelegates: [ + const AppLocalizationsDelegate(isTest: true), + GlobalMaterialLocalizations.delegate, + GlobalWidgetsLocalizations.delegate, + ], + themeMode: ThemeMode.light, + theme: TalawaTheme.lightTheme, + home: customDrawerViewModel.exitAlertDialog(), + ); + + await tester.pumpWidget(buildAlertDialog); + await tester.pumpAndSettle(const Duration(seconds: 1)); + + final exitDialog = find.byKey(const Key("Exit?")); + await tester.tap(find.text('Exit')); + + expect(exitDialog, findsOneWidget); + }); }); group('Test Organization action Buttons', () {