flutter-freaccess-hub/integration_test/auth_test.dart

144 lines
4.4 KiB
Dart

part of 'app_test.dart';
class AuthenticationTest {
static Future<void> signIn() async {
patrolWidgetTest(
'Sign-In with erro@exemplo.com',
(PatrolTester tester) async {
$ = tester;
final PatrolFinder throwsException = $(Dialog).$(ThrowExceptionWidget);
final Map<String, String> 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;
final PatrolFinder throwsException = $(Dialog).$(ThrowExceptionWidget);
final Map<String, String> 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<void> signUp() async {
patrolWidgetTest(
'Sign Up - credenciais já registradas',
(PatrolTester tester) async {
$ = tester;
final PatrolFinder throwsException = $(Dialog).$(ThrowExceptionWidget);
final Map<String, String> 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;
final PatrolFinder throwsException = $(Dialog).$(ThrowExceptionWidget);
final name = _generateRandomString(7);
final email = '$name@example.com';
final password = '12345678';
final Map<String, String> 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<void> signOut() async {
patrolWidgetTest(
'Deslogar da Conta',
(PatrolTester tester) async {
$ = tester;
await _logged();
await $.pumpWidgetAndSettle(const App());
await $.waitUntilVisible($(MenuStaggeredView));
await Future.delayed(const Duration(milliseconds: 500));
await $(Icons.menu_rounded).tap();
await $.waitUntilVisible($(MenuListView));
await $(Icons.exit_to_app)
.waitUntilVisible()
.tap(settlePolicy: SettlePolicy.trySettle);
await Future.delayed(const Duration(milliseconds: 500));
},
);
}
static Future<void> recovery() async {}
}
Future<void> _auth(
Map<String, String> credentials,
PatrolTester $,
PatrolFinder throwsException,
) async {
await _enterCredentials(credentials, $);
await _submit('SubmitButtonWidget', $, throwsException);
}
Future<void> _enterCredentials(
Map<String, String> credentials,
PatrolTester $,
) async {
for (var entry in credentials.entries) {
await $(ValueKey(entry.key)).enterText(entry.value);
await $.pumpAndSettle();
}
}
Future<void> _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();
}