part of 'app_test.dart'; class AuthenticationTest { static Future signIn() async { patrolWidgetTest( 'Sign-In with erro@exemplo.com', (PatrolTester tester) async { $ = tester; $.tester.printToConsole( 'Authentication Test - Sign-In with error@exemplo.com'); final PatrolFinder throwsException = $(Dialog).$(ThrowExceptionWidget); final Map credentials = { 'emailTextFormField': 'erro@exemplo.com', 'passwordTextFormField': '12345678', }; await _unlogged(); await $.pumpWidgetAndSettle(const App()); await Future.delayed(const Duration(milliseconds: 500)); await _navigateToSignIn($); await _auth(credentials, $, throwsException); await Future.delayed(const Duration(milliseconds: 500)); }, ); patrolWidgetTest( 'Sign-In with email_app@exemplo.com', (PatrolTester tester) async { $ = tester; $.tester.printToConsole( 'Authentication Test - Sign-In with email_app@exemplo.com'); final PatrolFinder throwsException = $(Dialog).$(ThrowExceptionWidget); final Map credentials = { 'emailTextFormField': 'email_app@exemplo.com', 'passwordTextFormField': '12345678', }; await _unlogged(); await $.pumpWidgetAndSettle(const App()); await _navigateToSignIn($); await _auth(credentials, $, throwsException); await Future.delayed(const Duration(milliseconds: 500)); }, ); } static Future signUp() async { patrolWidgetTest( 'Sign Up - credenciais já registradas', (PatrolTester tester) async { $ = tester; $.tester.printToConsole( 'Authentication Test - Sign-Up: credenciais já registradas'); final PatrolFinder throwsException = $(Dialog).$(ThrowExceptionWidget); final Map credentials = { 'nameTextFormField': 'app', 'emailTextFormField': 'email_app@exemplo.com', 'passwordTextFormField': '12345678', }; await _unlogged(); await $.pumpWidgetAndSettle(const App()); await _navigateToSignUp($); await _auth(credentials, $, throwsException); await Future.delayed(const Duration(milliseconds: 500)); }, ); patrolWidgetTest( 'Sign Up - credenciais novas', (PatrolTester tester) async { $ = tester; $.tester .printToConsole('Authentication Test - Sign-Up: credenciais novas'); final PatrolFinder throwsException = $(Dialog).$(ThrowExceptionWidget); final name = _generateRandomString(7); final email = '$name@example.com'; final password = '12345678'; final Map credentials = { 'nameTextFormField': name, 'emailTextFormField': email, 'passwordTextFormField': password, }; await _unlogged(); await $.pumpWidgetAndSettle(const App()); await _navigateToSignUp($); await _auth(credentials, $, throwsException); await Future.delayed(const Duration(milliseconds: 500)); }, ); } static Future signOut() async { patrolWidgetTest( 'Deslogar da Conta', (PatrolTester tester) async { $ = tester; $.tester.printToConsole( 'Authentication Test - Sign-Out: Deslogar da Conta'); await _logged(); await $.pumpWidget(const App()); await Future.delayed(const Duration(milliseconds: 500)); await $.waitUntilVisible($(MenuStaggeredView)); await $(Icons.menu_rounded) // .waitUntilVisible() .tap(); await $.waitUntilVisible($(MenuListView)); await $(Icons.exit_to_app) .waitUntilVisible() .tap(settlePolicy: SettlePolicy.trySettle); await Future.delayed(const Duration(milliseconds: 500)); }, ); } static Future recovery() async {} } Future _auth( Map credentials, PatrolTester $, PatrolFinder throwsException, ) async { await _enterCredentials(credentials, $); await _submit('SubmitButtonWidget', $, throwsException); } Future _enterCredentials( Map credentials, PatrolTester $, ) async { for (var entry in credentials.entries) { await $(ValueKey(entry.key)).enterText(entry.value); await $.pumpAndSettle(); } } Future _submit( String key, PatrolTester $, PatrolFinder throwsException) async { await $(ValueKey(key)).tap(); if ($(ValueKey('ThrowExceptionWidget')).exists) { // expect(throwsException, findsOneWidget); await $(ValueKey('ThrowExceptionWidget')).tap(); } else { _navigateBackUsingSystemGesture(); } } String _generateRandomString(int length) { const chars = 'abcdefghijklmnopqrstuvwxyz0123456789'; final rand = Random(); return List.generate(length, (index) => chars[rand.nextInt(chars.length)]) .join(); }