-
-
Notifications
You must be signed in to change notification settings - Fork 504
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test for custom error widget and did err-handling in qrScan
- Loading branch information
1 parent
e4b9b80
commit 01432d1
Showing
4 changed files
with
228 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_localizations/flutter_localizations.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:talawa/services/navigation_service.dart'; | ||
import 'package:talawa/services/size_config.dart'; | ||
import 'package:talawa/utils/app_localization.dart'; | ||
import 'package:talawa/widgets/talawa_error_dialog.dart'; | ||
|
||
import '../../helpers/test_locator.dart'; | ||
import 'custom_alert_dialog_test.dart'; | ||
|
||
Widget createTalawaErrorWidget({ | ||
bool reverse = false, | ||
String? dialogTitle, | ||
bool passSecondaryFunc = true, | ||
}) { | ||
return MaterialApp( | ||
navigatorKey: locator<NavigationService>().navigatorKey, | ||
navigatorObservers: [], | ||
locale: const Locale('en'), | ||
supportedLocales: [ | ||
const Locale('en', 'US'), | ||
const Locale('es', 'ES'), | ||
const Locale('fr', 'FR'), | ||
const Locale('hi', 'IN'), | ||
const Locale('zh', 'CN'), | ||
const Locale('de', 'DE'), | ||
const Locale('ja', 'JP'), | ||
const Locale('pt', 'PT'), | ||
], | ||
localizationsDelegates: [ | ||
const AppLocalizationsDelegate(isTest: true), | ||
GlobalMaterialLocalizations.delegate, | ||
GlobalWidgetsLocalizations.delegate, | ||
], | ||
home: Scaffold( | ||
body: TextButton( | ||
child: const Text('Open'), | ||
onPressed: () { | ||
navigationService.showTalawaErrorDialog("Test Error"); | ||
}, | ||
), | ||
), | ||
); | ||
} | ||
|
||
void main() { | ||
SizeConfig().test(); | ||
testSetupLocator(); | ||
group('Test for TalawaErrorWidget', () { | ||
testWidgets('Check if the Error Widget shows up', (tester) async { | ||
await tester.pumpWidget(createTalawaErrorWidget()); | ||
await tester.pump(); | ||
await tester.tap(find.textContaining('Open')); | ||
await tester.pump(const Duration(seconds: 1)); | ||
|
||
expect(find.byType(TalawaErrorDialog), findsOneWidget); | ||
}); | ||
|
||
testWidgets('Check if the close Button is working', (tester) async { | ||
await tester.pumpWidget(createTalawaErrorWidget()); | ||
await tester.pump(); | ||
|
||
await tester.tap(find.textContaining('Open')); | ||
await tester.pump(const Duration(seconds: 1)); | ||
|
||
await tester.tap(find.textContaining('Close')); | ||
await tester.pump(const Duration(seconds: 1)); | ||
|
||
expect(find.byType(TalawaErrorDialog), findsNothing); | ||
}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_localizations/flutter_localizations.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:talawa/services/navigation_service.dart'; | ||
import 'package:talawa/services/size_config.dart'; | ||
import 'package:talawa/utils/app_localization.dart'; | ||
import 'package:talawa/widgets/talawa_error_widget.dart'; | ||
|
||
import '../../helpers/test_locator.dart'; | ||
|
||
Widget createTalawaErrorWidget({ | ||
bool reverse = false, | ||
String? dialogTitle, | ||
bool passSecondaryFunc = true, | ||
}) { | ||
return MaterialApp( | ||
navigatorKey: locator<NavigationService>().navigatorKey, | ||
navigatorObservers: [], | ||
locale: const Locale('en'), | ||
supportedLocales: [ | ||
const Locale('en', 'US'), | ||
const Locale('es', 'ES'), | ||
const Locale('fr', 'FR'), | ||
const Locale('hi', 'IN'), | ||
const Locale('zh', 'CN'), | ||
const Locale('de', 'DE'), | ||
const Locale('ja', 'JP'), | ||
const Locale('pt', 'PT'), | ||
], | ||
localizationsDelegates: [ | ||
const AppLocalizationsDelegate(isTest: true), | ||
GlobalMaterialLocalizations.delegate, | ||
GlobalWidgetsLocalizations.delegate, | ||
], | ||
home: Scaffold( | ||
body: TextButton( | ||
child: const Text('Open'), | ||
onPressed: () { | ||
navigationService.showTalawaErrorWidget("Test Error"); | ||
}, | ||
), | ||
), | ||
); | ||
} | ||
|
||
void main() { | ||
SizeConfig().test(); | ||
testSetupLocator(); | ||
group('Test for TalawaErrorWidget', () { | ||
testWidgets('Check if the Snackbar shows up', (tester) async { | ||
await tester.pumpWidget(createTalawaErrorWidget()); | ||
await tester.pump(); | ||
await tester.tap(find.textContaining('Open')); | ||
await tester.pump(const Duration(seconds: 1)); | ||
expect(find.byType(TalawaErrorWidget), findsOneWidget); | ||
}); | ||
}); | ||
} |