This commit is contained in:
J. A. Messias 2024-10-15 16:19:25 -03:00
parent 148b10b81e
commit 01c38fcdc4
1 changed files with 43 additions and 25 deletions

View File

@ -11,30 +11,30 @@ 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 _testWelcome();
group('Navigation', () {
setUpAll(() async =>
await initializeApp().then((_) => StorageUtil().isLogged = false));
testWidgets('Test Welcome', (WidgetTester tester) async {
widget = tester;
await _testWelcome();
});
});
group('Terms of Use', () {
// Add tests for Terms of Use here
});
group('Terms of Use', () {});
});
group('Authentication', () {
group('Sign in', () {
setUpAll(() async => await initializeApp().then((_) => StorageUtil().isLogged = false));
setUpAll(() async =>
await initializeApp().then((_) => StorageUtil().isLogged = false));
testWidgets('Test Sign In', (WidgetTester tester) async {
widget = tester;
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 _testSignUp();
@ -44,13 +44,12 @@ void main() {
// 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;
await _testForgotPassword();
});
// setUpAll(() async => await initializeApp().then((_) => StorageUtil().isLogged = false));
// testWidgets('Test Forgot Password', (WidgetTester tester) async {
// widget = tester;
// await _testForgotPassword();
// });
});
});
group('Localization', () {
// Add tests for Localization here
@ -93,12 +92,20 @@ Future<void> _testWelcome() async {
await _navigateToSignIn();
await widget.pumpAndSettle();
}
Future<void> _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'});
await _auth({
'emailTextFormField': 'erro@exemplo.com',
'passwordTextFormField': '12345678'
});
await _auth({
'emailTextFormField': 'email_app@exemplo.com',
'passwordTextFormField': '12345678'
});
}
Future<void> _testSignUp() async {
await widget.pumpWidget(const App());
await _navigateToSignUp();
@ -126,6 +133,7 @@ Future<void> _testSignUp() async {
};
await _auth(credentials);
}
Future<void> _testForgotPassword() async {
await widget.pumpWidget(const App());
await _navigateToSignIn();
@ -141,27 +149,33 @@ Future<void> _testForgotPassword() async {
credentials = {'recoveryTextFormField': 'email_app@exemple.com'};
await _send(credentials);
}
Future<void> _recoveryPassword() async {
await widget.pumpAndSettle();
final Finder forgotPassword = find.byKey(const ValueKey<String>('ForgotPassword'));
final Finder forgotPassword =
find.byKey(const ValueKey<String>('ForgotPassword'));
if (forgotPassword.evaluate().isNotEmpty) await widget.tap(forgotPassword);
await widget.ensureVisible(forgotPassword);
await widget.pumpAndSettle();
}
Future<void> _navigateBackUsingSystemGesture() async =>
IntegrationTestWidgetsFlutterBinding.instance.keyboard.isLogicalKeyPressed(LogicalKeyboardKey.escape);
IntegrationTestWidgetsFlutterBinding.instance.keyboard
.isLogicalKeyPressed(LogicalKeyboardKey.escape);
Future<void> _navigateToSignUp() async {
await widget.pumpAndSettle();
final Finder navToSignUp = find.byKey(const ValueKey<String>('toggleSignUpPage'));
final Finder navToSignUp =
find.byKey(const ValueKey<String>('toggleSignUpPage'));
if (navToSignUp.evaluate().isNotEmpty) {
await widget.tap(navToSignUp);
await widget.pumpAndSettle();
}
}
Future<void> _navigateToSignIn() async {
await widget.pumpAndSettle();
final Finder navToSignIn = find.byKey(const ValueKey<String>('toggleSignInPage'));
final Finder navToSignIn =
find.byKey(const ValueKey<String>('toggleSignInPage'));
expect(navToSignIn, findsOneWidget);
if (navToSignIn.evaluate().isNotEmpty) {
await widget.tap(navToSignIn);
@ -173,10 +187,12 @@ Future<void> _auth(Map<String, dynamic> credentials) async {
await _enterCredentials(credentials);
await _submit('SubmitButtonWidget');
}
Future<void> _send(Map<String, dynamic> credentials) async {
await _enterCredentials(credentials);
await _submit('SendButtonWidget');
}
Future<void> _enterCredentials(Map<String, dynamic> credentials) async {
await widget.pumpAndSettle();
for (var entry in credentials.entries) {
@ -188,6 +204,7 @@ Future<void> _enterCredentials(Map<String, dynamic> credentials) async {
}
await widget.pumpAndSettle();
}
Future<void> _submit(String key) async {
await widget.pumpAndSettle();
final Finder submitButton = find.byKey(ValueKey<String>(key));
@ -197,7 +214,8 @@ Future<void> _submit(String key) async {
await widget.pumpAndSettle();
}
final Finder throwExceptionWidget = find.byKey(const ValueKey<String>('ThrowExceptionWidget'));
final Finder throwExceptionWidget =
find.byKey(const ValueKey<String>('ThrowExceptionWidget'));
await widget.pumpAndSettle();
if (throwExceptionWidget.evaluate().isNotEmpty) {
await widget.ensureVisible(throwExceptionWidget);