flutter-freaccess-hub/integration_test/app_test.dart

249 lines
6.4 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:hub/flutter_flow/random_data_util.dart';
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();
});
group('Terms of Use', (){});
});
group('Authentication', () {
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'});
});
});
group('Sign up', () {
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<String, dynamic> 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);
});
});
group('Sign Out', () {
// setUpAll(() async =>
// await initializeApp().then((_) => StorageUtil().isLogged = false));
});
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<String, dynamic> 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);
});
});
});
group('Localization', (){
});
group('Networking', (){
});
group('Functionality', (){
});
group('Usability', (){
});
group('Performance', (){
});
group('Security', (){
});
group('Accessibility', (){
});
group('Compatibility', (){
});
group('Internationalization', (){
});
}
Future<void> _navigateBackUsingSystemGesture() async =>
IntegrationTestWidgetsFlutterBinding.instance.keyboard.isLogicalKeyPressed(LogicalKeyboardKey.escape);
Future<void> _navigateToSignUp() async {
await widget.pumpAndSettle();
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'));
expect(navToSignIn, findsOneWidget);
if (navToSignIn.evaluate().isNotEmpty) {
await widget.tap(navToSignIn);
await widget.pumpAndSettle();
}
}
Future<void> _recoveryPassword() async {
await widget.pumpAndSettle();
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> _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) {
final Finder field = find.byKey(ValueKey<String>(entry.key));
await widget.pumpAndSettle();
expect(field, findsOneWidget);
await widget.enterText(field, entry.value);
await widget.pumpAndSettle();
}
await widget.pumpAndSettle();
}
Future<void> _submit(String key) async {
await widget.pumpAndSettle();
final Finder submitButton = find.byKey(ValueKey<String>(key));
await widget.pumpAndSettle();
if (submitButton.evaluate().isNotEmpty) {
await widget.tap(submitButton);
await widget.pumpAndSettle();
}
final Finder ThrowExceptionWidget = find.byKey(const ValueKey<String>('ThrowExceptionWidget'));
await widget.pumpAndSettle();
if (ThrowExceptionWidget.evaluate().isNotEmpty) {
await widget.ensureVisible(ThrowExceptionWidget);
await widget.tap(ThrowExceptionWidget);
await widget.pumpAndSettle();
} else {
await _navigateBackUsingSystemGesture();
}
}