Skip to content

Commit

Permalink
Made custom_drawer.dart coverage 100% (PalisadoesFoundation#2490)
Browse files Browse the repository at this point in the history
* made custom_drawer.dart coverage 100%

* minor change

* minor change
  • Loading branch information
Azad99-9 authored Apr 27, 2024
1 parent 5a73f47 commit 22100ac
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 45 deletions.
1 change: 0 additions & 1 deletion lib/services/navigation_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ class NavigationService {
/// **returns**:
/// None
void pushDialog(Widget dialog) {
print('came');
showDialog(
context: navigatorKey.currentContext!,
barrierColor: Colors.transparent,
Expand Down
18 changes: 18 additions & 0 deletions lib/view_model/widgets_view_models/custom_drawer_view_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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**:
Expand Down
26 changes: 2 additions & 24 deletions lib/widgets/custom_drawer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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)!
Expand Down Expand Up @@ -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
},
),
);
}
}
4 changes: 2 additions & 2 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
40 changes: 23 additions & 17 deletions test/widget_tests/widgets/custom_drawer_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<NavigationService>() as MockNavigationService)
.pushDialog(captureAny))
.captured;
expect(dialogPopUP[0], isA<CustomAlertDialog>());
// 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', () {
Expand Down

0 comments on commit 22100ac

Please sign in to comment.