diff --git a/integration_test/app_test.dart b/integration_test/app_test.dart index 57c1d623..cec0d5f2 100644 --- a/integration_test/app_test.dart +++ b/integration_test/app_test.dart @@ -6,165 +6,151 @@ import 'package:hub/main.dart'; import 'package:hub/shared/utils/storage_util.dart'; import 'package:integration_test/integration_test.dart'; - late WidgetTester widget; void main() { IntegrationTestWidgetsFlutterBinding.ensureInitialized(); + + group('Initialization', () { setUpAll(() async => await initializeApp().then((_) => StorageUtil().isLogged = false)); - testWidgets('Test Welcome', (WidgetTester tester) async { widget = tester; - - await widget.pumpWidget(const App()); - await widget.pumpAndSettle(); - await _navigateToSignIn(); - await _navigateToSignUp(); - await widget.pumpAndSettle(); - await widget.pumpWidget(const App()); - await widget.pumpAndSettle(); - await _navigateToSignUp(); - await _navigateToSignIn(); - await widget.pumpAndSettle(); - - + await _testWelcome(); }); - group('Terms of Use', (){}); - + group('Terms of Use', () { + // Add tests for Terms of Use here + }); }); group('Authentication', () { - group('Sign in', () { - setUpAll(() async => - await initializeApp().then((_) => StorageUtil().isLogged = false)); + group('Sign in', () { + setUpAll(() async => await initializeApp().then((_) => StorageUtil().isLogged = false)); testWidgets('Test Sign In', (WidgetTester tester) async { widget = tester; - - await widget.pumpWidget(const App()); - await _navigateToSignIn(); - - await _auth({'emailTextFormField': 'erro@exemplo.com', 'passwordTextFormField': '12345678'}); - await _auth({'emailTextFormField': 'email_app@exemplo.com','passwordTextFormField': '12345678'}); + await _testSignIn(); }); }); group('Sign up', () { - setUpAll(() async => - await initializeApp().then((_) => StorageUtil().isLogged = false)); - - + setUpAll(() async => await initializeApp().then((_) => StorageUtil().isLogged = false)); testWidgets('Test Sign Up', (WidgetTester tester) async { widget = tester; - await tester.pumpWidget(const App()); - late String name; - late String email; - late String password; - late Map credentials; - - await _navigateToSignUp(); - - name = 'app'; - email = 'email_app@exemplo.com'; - password = '12345678'; - credentials = { - 'nameTextFormField': name, - 'emailTextFormField': email, - 'passwordTextFormField': password - }; - await _auth(credentials); - - - name = randomString(7, 7, true, true, true); - email = '$name@example.com'; - password = '12345678'; - credentials = { - 'nameTextFormField': name, - 'emailTextFormField': email, - 'passwordTextFormField': password - }; - await _navigateToSignUp(); - await _auth(credentials); - credentials = { - 'emailTextFormField': email, - 'passwordTextFormField': password - }; - await _auth(credentials); - + await _testSignUp(); }); }); group('Sign Out', () { - // setUpAll(() async => - // await initializeApp().then((_) => StorageUtil().isLogged = false)); + // Add tests for Sign Out here }); group('Forgot Password', () { setUpAll(() async => await initializeApp().then((_) => StorageUtil().isLogged = false)); - testWidgets('Test Forgot Password', (WidgetTester tester) async { widget = tester; - late final String addr = randomString(5, 5, true, true, true); - late Map credentials; - - await tester.pumpWidget(const App()); - - await _navigateToSignIn(); - - await _recoveryPassword(); - credentials = {'recoveryTextFormField': '$addr@exemple.com'}; - await _send(credentials); - - await Future.delayed(const Duration(seconds: 2)); - - await _recoveryPassword(); - credentials = {'recoveryTextFormField': 'email_app@exemple.com'}; - await _send(credentials); - - + await _testForgotPassword(); }); }); }); - - - - group('Localization', (){ - + group('Localization', () { + // Add tests for Localization here }); - group('Networking', (){ - + group('Networking', () { + // Add tests for Networking here }); - group('Functionality', (){ - + group('Functionality', () { + // Add tests for Functionality here }); - group('Usability', (){ - + group('Usability', () { + // Add tests for Usability here }); - group('Performance', (){ - + group('Performance', () { + // Add tests for Performance here }); - group('Security', (){ - + group('Security', () { + // Add tests for Security here }); - group('Accessibility', (){ - + group('Accessibility', () { + // Add tests for Accessibility here }); - group('Compatibility', (){ - + group('Compatibility', () { + // Add tests for Compatibility here }); - group('Internationalization', (){ - + group('Internationalization', () { + // Add tests for Internationalization here }); - - } +Future _testWelcome() async { + await widget.pumpWidget(const App()); + await widget.pumpAndSettle(); + await _navigateToSignIn(); + await _navigateToSignUp(); + await widget.pumpAndSettle(); + await widget.pumpWidget(const App()); + await widget.pumpAndSettle(); + await _navigateToSignUp(); + await _navigateToSignIn(); + await widget.pumpAndSettle(); +} +Future _testSignIn() async { + await widget.pumpWidget(const App()); + await _navigateToSignIn(); + await _auth({'emailTextFormField': 'erro@exemplo.com', 'passwordTextFormField': '12345678'}); + await _auth({'emailTextFormField': 'email_app@exemplo.com', 'passwordTextFormField': '12345678'}); +} +Future _testSignUp() async { + await widget.pumpWidget(const App()); + await _navigateToSignUp(); + var credentials = { + 'nameTextFormField': 'app', + 'emailTextFormField': 'email_app@exemplo.com', + 'passwordTextFormField': '12345678' + }; + await _auth(credentials); + + var name = randomString(7, 7, true, true, true); + var email = '$name@example.com'; + var password = '12345678'; + credentials = { + 'nameTextFormField': name, + 'emailTextFormField': email, + 'passwordTextFormField': password + }; + await _navigateToSignUp(); + await _auth(credentials); + credentials = { + 'emailTextFormField': email, + 'passwordTextFormField': password + }; + await _auth(credentials); +} +Future _testForgotPassword() async { + await widget.pumpWidget(const App()); + await _navigateToSignIn(); + await _recoveryPassword(); + + var addr = randomString(5, 5, true, true, true); + var credentials = {'recoveryTextFormField': '$addr@exemple.com'}; + await _send(credentials); + + await Future.delayed(const Duration(seconds: 2)); + + await _recoveryPassword(); + credentials = {'recoveryTextFormField': 'email_app@exemple.com'}; + await _send(credentials); +} +Future _recoveryPassword() async { + await widget.pumpAndSettle(); + final Finder forgotPassword = find.byKey(const ValueKey('ForgotPassword')); + if (forgotPassword.evaluate().isNotEmpty) await widget.tap(forgotPassword); + await widget.ensureVisible(forgotPassword); + await widget.pumpAndSettle(); +} Future _navigateBackUsingSystemGesture() async => IntegrationTestWidgetsFlutterBinding.instance.keyboard.isLogicalKeyPressed(LogicalKeyboardKey.escape); - - Future _navigateToSignUp() async { await widget.pumpAndSettle(); final Finder navToSignUp = find.byKey(const ValueKey('toggleSignUpPage')); @@ -173,7 +159,6 @@ Future _navigateToSignUp() async { await widget.pumpAndSettle(); } } - Future _navigateToSignIn() async { await widget.pumpAndSettle(); final Finder navToSignIn = find.byKey(const ValueKey('toggleSignInPage')); @@ -184,32 +169,16 @@ Future _navigateToSignIn() async { } } -Future _recoveryPassword() async { - await widget.pumpAndSettle(); - final Finder forgotPassword = find.byKey(const ValueKey('ForgotPassword')); - if (forgotPassword.evaluate().isNotEmpty) await widget.tap(forgotPassword); - await widget.ensureVisible(forgotPassword); - await widget.pumpAndSettle(); - -} - - - Future _auth(Map credentials) async { await _enterCredentials(credentials); await _submit('SubmitButtonWidget'); } - Future _send(Map credentials) async { await _enterCredentials(credentials); await _submit('SendButtonWidget'); } - - - Future _enterCredentials(Map credentials) async { await widget.pumpAndSettle(); - for (var entry in credentials.entries) { final Finder field = find.byKey(ValueKey(entry.key)); await widget.pumpAndSettle(); @@ -217,10 +186,8 @@ Future _enterCredentials(Map credentials) async { await widget.enterText(field, entry.value); await widget.pumpAndSettle(); } - await widget.pumpAndSettle(); } - Future _submit(String key) async { await widget.pumpAndSettle(); final Finder submitButton = find.byKey(ValueKey(key)); @@ -230,19 +197,13 @@ Future _submit(String key) async { await widget.pumpAndSettle(); } - - final Finder ThrowExceptionWidget = find.byKey(const ValueKey('ThrowExceptionWidget')); + final Finder throwExceptionWidget = find.byKey(const ValueKey('ThrowExceptionWidget')); await widget.pumpAndSettle(); - if (ThrowExceptionWidget.evaluate().isNotEmpty) { - await widget.ensureVisible(ThrowExceptionWidget); - await widget.tap(ThrowExceptionWidget); + if (throwExceptionWidget.evaluate().isNotEmpty) { + await widget.ensureVisible(throwExceptionWidget); + await widget.tap(throwExceptionWidget); await widget.pumpAndSettle(); } else { await _navigateBackUsingSystemGesture(); } - - } - - -