Add login screen integration test

This commit is contained in:
Anmol Gupta 2018-06-21 15:04:48 +05:30
parent 28ffc8c357
commit 6643f4ad1c
4 changed files with 100 additions and 9 deletions

View File

@ -2,8 +2,9 @@ import 'package:flutter/material.dart';
import 'package:invoiceninja/redux/auth/auth_state.dart'; import 'package:invoiceninja/redux/auth/auth_state.dart';
import 'package:invoiceninja/ui/app/progress_button.dart'; import 'package:invoiceninja/ui/app/progress_button.dart';
import 'package:invoiceninja/utils/localization.dart'; import 'package:invoiceninja/utils/localization.dart';
import 'package:invoiceninja/ui/app/form_card.dart';
import '../app/form_card.dart'; import 'package:invoiceninja/utils/keys.dart';
class Login extends StatelessWidget { class Login extends StatelessWidget {
final bool isLoading; final bool isLoading;
@ -21,6 +22,19 @@ class Login extends StatelessWidget {
static final GlobalKey<FormState> _formKey = GlobalKey<FormState>(); static final GlobalKey<FormState> _formKey = GlobalKey<FormState>();
// add controllers
final _emailController = TextEditingController()..text = '';
final _passwordController = TextEditingController() ..text = '';
final _urlController = TextEditingController()..text = '';
final _secretController = TextEditingController()..text = '';
// keys
static final ValueKey _emailKey = new Key(LoginKeys.emailKeyString);
static final ValueKey _passwordKey = new Key(LoginKeys.passwordKeyString);
static final ValueKey _urlKey = new Key(LoginKeys.urlKeyString);
static final ValueKey _secretKey = new Key(LoginKeys.secretKeyString);
/*
static final GlobalKey<FormFieldState<String>> _emailKey = static final GlobalKey<FormFieldState<String>> _emailKey =
GlobalKey<FormFieldState<String>>(debugLabel: 'email'); GlobalKey<FormFieldState<String>>(debugLabel: 'email');
static final GlobalKey<FormFieldState<String>> _passwordKey = static final GlobalKey<FormFieldState<String>> _passwordKey =
@ -29,6 +43,7 @@ class Login extends StatelessWidget {
GlobalKey<FormFieldState<String>>(); GlobalKey<FormFieldState<String>>();
static final GlobalKey<FormFieldState<String>> _secretKey = static final GlobalKey<FormFieldState<String>> _secretKey =
GlobalKey<FormFieldState<String>>(); GlobalKey<FormFieldState<String>>();
*/
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@ -49,8 +64,9 @@ class Login extends StatelessWidget {
child: FormCard( child: FormCard(
children: <Widget>[ children: <Widget>[
TextFormField( TextFormField(
controller: _emailController,
key: _emailKey, key: _emailKey,
initialValue: authState.email, //initialValue: authState.email,
autocorrect: false, autocorrect: false,
decoration: InputDecoration( decoration: InputDecoration(
labelText: AppLocalization.of(context).email), labelText: AppLocalization.of(context).email),
@ -60,8 +76,9 @@ class Login extends StatelessWidget {
: null, : null,
), ),
TextFormField( TextFormField(
controller: _passwordController,
key: _passwordKey, key: _passwordKey,
initialValue: authState.password, //initialValue: authState.password,
autocorrect: false, autocorrect: false,
decoration: InputDecoration( decoration: InputDecoration(
labelText: AppLocalization.of(context).password), labelText: AppLocalization.of(context).password),
@ -71,8 +88,9 @@ class Login extends StatelessWidget {
obscureText: true, obscureText: true,
), ),
TextFormField( TextFormField(
controller: _urlController,
key: _urlKey, key: _urlKey,
initialValue: authState.url, //initialValue: authState.url,
autocorrect: false, autocorrect: false,
decoration: decoration:
InputDecoration(labelText: AppLocalization.of(context).url), InputDecoration(labelText: AppLocalization.of(context).url),
@ -82,8 +100,9 @@ class Login extends StatelessWidget {
keyboardType: TextInputType.url, keyboardType: TextInputType.url,
), ),
TextFormField( TextFormField(
controller: _secretController,
key: _secretKey, key: _secretKey,
initialValue: authState.secret, //initialValue: authState.secret,
autocorrect: false, autocorrect: false,
decoration: InputDecoration( decoration: InputDecoration(
labelText: AppLocalization.of(context).secret), labelText: AppLocalization.of(context).secret),
@ -122,10 +141,10 @@ class Login extends StatelessWidget {
this.onLoginPressed( this.onLoginPressed(
context, context,
_emailKey.currentState.value, _emailController.text,//_emailKey.currentState.value,
_passwordKey.currentState.value, _passwordController.text,//_passwordKey.currentState.value,
_urlKey.currentState.value, _urlController.text,//_urlKey.currentState.value,
_secretKey.currentState.value); _secretController.text);//_secretKey.currentState.value);
}, },
), ),
], ],

7
lib/utils/keys.dart Normal file
View File

@ -0,0 +1,7 @@
// Keys for Login Screen
class LoginKeys {
static final String emailKeyString = 'loginEmail';
static final String passwordKeyString = 'loginPassword';
static final String urlKeyString = 'loginUrl';
static final String secretKeyString = 'loginSecret';
}

10
test_driver/login_it.dart Normal file
View File

@ -0,0 +1,10 @@
// This is the instrumented flutter app!
import 'package:flutter_driver/driver_extension.dart';
import 'package:invoiceninja/main.dart' as app;
void main() {
// This line enables the extension
enableFlutterDriverExtension();
app.main();
}

View File

@ -0,0 +1,55 @@
// This is our test!
// Import Flutter Driver API
import 'package:flutter_driver/flutter_driver.dart';
import 'package:test/test.dart';
import 'package:invoiceninja/utils/keys.dart';
void main() {
group('LOGIN TEST', () {
FlutterDriver driver;
setUp(() async {
driver = await FlutterDriver.connect();
});
tearDown(() async {
if(driver!=null) {
driver.close();
}
});
test('No input provided by user test', () async {
await driver.tap(find.text('LOGIN'));
await driver.waitFor(find.text('Please enter your email'));
await driver.waitFor(find.text('Please enter your password'));
});
test('Details filled by user and login', () async {
// details for sever running laravel
String email = 'sanghapal.ahankare@gmail.com';
String password = '12345qazdr';
String url = 'http://192.168.1.74';
String secret = 'asdf';
await driver.tap(find.byValueKey(LoginKeys.emailKeyString), timeout: new Duration(seconds: 60));
await driver.enterText(email);
await driver.tap(find.byValueKey(LoginKeys.passwordKeyString));
await driver.enterText(password);
await driver.tap(find.byValueKey(LoginKeys.urlKeyString));
await driver.enterText(url);
await driver.tap(find.byValueKey(LoginKeys.secretKeyString));
await driver.enterText(secret);
await driver.tap(find.text('LOGIN'));
await driver.waitFor(find.byType('DashboardScreen'));
});
});
}