146 lines
4.5 KiB
Dart
146 lines
4.5 KiB
Dart
part of 'app_test.dart';
|
|
|
|
class AuthenticationTest {
|
|
static Future signIn() async {
|
|
_setUpUnlogged();
|
|
testWidgets('Sign-In with erro@exemplo.com', //
|
|
(WidgetTester tester) async {
|
|
await tester.pumpWidget(const App());
|
|
tester.printToConsole('AuthenticationTest - Navigate Sign-In');
|
|
await _navigateToSignIn(tester);
|
|
await _auth({
|
|
'emailTextFormField': 'erro@exemplo.com',
|
|
'passwordTextFormField': '12345678'
|
|
}, tester);
|
|
await tester.pumpAndSettle();
|
|
await Future.delayed(const Duration(milliseconds: 500));
|
|
return;
|
|
});
|
|
_tearDown();
|
|
|
|
_setUpUnlogged();
|
|
testWidgets('Sign-In with email_app@exemplo.com',
|
|
(WidgetTester tester) async {
|
|
await tester.pumpWidget(const App());
|
|
tester.printToConsole('AuthenticationTest - Navigate Sign-In');
|
|
await _navigateToSignIn(tester);
|
|
await _auth({
|
|
'emailTextFormField': 'email_app@exemplo.com',
|
|
'passwordTextFormField': '12345678'
|
|
}, tester);
|
|
await Future.delayed(const Duration(milliseconds: 500));
|
|
return;
|
|
});
|
|
_tearDown();
|
|
}
|
|
|
|
static Future signUp() async {
|
|
_setUpUnlogged();
|
|
testWidgets('Sign Up - credenciais já registradas',
|
|
(WidgetTester tester) async {
|
|
var credentials = {
|
|
'nameTextFormField': 'app',
|
|
'emailTextFormField': 'email_app@exemplo.com',
|
|
'passwordTextFormField': '12345678'
|
|
};
|
|
|
|
await tester.pumpWidget(const App());
|
|
tester.printToConsole('AuthenticationTest - Navigate Sign-Up');
|
|
await _navigateToSignUp(tester);
|
|
await _auth(credentials, tester);
|
|
await tester.pumpAndSettle();
|
|
await Future.delayed(const Duration(milliseconds: 500));
|
|
return;
|
|
});
|
|
_tearDown();
|
|
|
|
_setUpUnlogged();
|
|
testWidgets('Sign Up - credenciais novas', //
|
|
(WidgetTester tester) async {
|
|
late Map<String, String> credentials;
|
|
|
|
var name = ff.randomString(7, 7, true, true, true);
|
|
var email = '$name@example.com';
|
|
var password = '12345678';
|
|
credentials = {
|
|
'nameTextFormField': name,
|
|
'emailTextFormField': email,
|
|
'passwordTextFormField': password
|
|
};
|
|
|
|
await tester.pumpWidget(const App());
|
|
tester.printToConsole('AuthenticationTest - Navigate Sign-Up');
|
|
await _navigateToSignUp(tester);
|
|
await _auth(credentials, tester);
|
|
await Future.delayed(const Duration(milliseconds: 500));
|
|
return;
|
|
});
|
|
_tearDown();
|
|
}
|
|
|
|
static Future signOut() async {
|
|
_setUpLogged();
|
|
testWidgets('Deslogar da Conta', (WidgetTester tester) async {
|
|
await tester.pumpWidget(const App());
|
|
final Finder drawerButton = find.byIcon(Icons.menu_rounded);
|
|
await tester.pumpAndSettle();
|
|
await tester.tap(drawerButton);
|
|
await tester.pumpAndSettle();
|
|
final Finder signOutButton = find.byIcon(Icons.exit_to_app);
|
|
await tester.pumpAndSettle();
|
|
await tester.tap(signOutButton);
|
|
await tester.pumpAndSettle();
|
|
await Future.delayed(const Duration(milliseconds: 500));
|
|
return;
|
|
});
|
|
_tearDown();
|
|
}
|
|
|
|
static Future recovery() async {}
|
|
}
|
|
|
|
Future<void> _auth(
|
|
Map<String, dynamic> credentials, WidgetTester tester) async {
|
|
await _enterCredentials(credentials, tester);
|
|
await _submit('SubmitButtonWidget', tester);
|
|
}
|
|
|
|
Future<void> _send(
|
|
Map<String, dynamic> credentials, WidgetTester tester) async {
|
|
await _enterCredentials(credentials, tester);
|
|
await _submit('SendButtonWidget', tester);
|
|
}
|
|
|
|
Future<void> _enterCredentials(
|
|
Map<String, dynamic> credentials, WidgetTester tester) async {
|
|
await tester.pumpAndSettle();
|
|
for (var entry in credentials.entries) {
|
|
final Finder field = find.byKey(ValueKey<String>(entry.key));
|
|
await tester.pumpAndSettle();
|
|
expect(field, findsOneWidget);
|
|
await tester.enterText(field, entry.value);
|
|
await tester.pumpAndSettle();
|
|
}
|
|
await tester.pumpAndSettle();
|
|
}
|
|
|
|
Future<void> _submit(String key, WidgetTester tester) async {
|
|
await tester.pumpAndSettle();
|
|
final Finder submitButton = find.byKey(ValueKey<String>(key));
|
|
await tester.pumpAndSettle();
|
|
if (submitButton.evaluate().isNotEmpty) {
|
|
await tester.tap(submitButton);
|
|
}
|
|
final Finder throwExceptionWidget =
|
|
find.byKey(const ValueKey<String>('ThrowExceptionWidget'));
|
|
|
|
if (throwExceptionWidget.evaluate().isNotEmpty) {
|
|
await tester.pumpAndSettle();
|
|
await tester.ensureVisible(throwExceptionWidget);
|
|
await tester.tap(throwExceptionWidget);
|
|
await tester.pumpAndSettle();
|
|
} else {
|
|
await _navigateBackUsingSystemGesture();
|
|
}
|
|
}
|