[Tests] Add simple signUp test and try to make non named routes detectable (not working)

Took 55 minutes
This commit is contained in:
Marcel 2020-02-20 22:54:21 +01:00
parent 7a3ef82546
commit 22f1f7a0c3
4 changed files with 63 additions and 0 deletions

View File

@ -94,6 +94,7 @@ class _SignUpState extends State<SignUp> {
return Scaffold( return Scaffold(
appBar: AppBar( appBar: AppBar(
title: TextField( title: TextField(
key: Key("serverField"),
autocorrect: false, autocorrect: false,
controller: serverController, controller: serverController,
decoration: InputDecoration( decoration: InputDecoration(
@ -149,6 +150,7 @@ class _SignUpState extends State<SignUp> {
), ),
), ),
title: TextField( title: TextField(
key: Key("usernameField"),
autocorrect: false, autocorrect: false,
controller: usernameController, controller: usernameController,
onSubmitted: (s) => signUpAction(context), onSubmitted: (s) => signUpAction(context),
@ -163,6 +165,7 @@ class _SignUpState extends State<SignUp> {
height: 50, height: 50,
padding: EdgeInsets.symmetric(horizontal: 12), padding: EdgeInsets.symmetric(horizontal: 12),
child: RaisedButton( child: RaisedButton(
key: Key("signUpButton"),
elevation: 7, elevation: 7,
color: Theme.of(context).primaryColor, color: Theme.of(context).primaryColor,
shape: RoundedRectangleBorder( shape: RoundedRectangleBorder(
@ -179,6 +182,7 @@ class _SignUpState extends State<SignUp> {
), ),
Center( Center(
child: FlatButton( child: FlatButton(
key: Key("alreadyHaveAnAccountButton"),
child: Text( child: Text(
I18n.tr(context).alreadyHaveAnAccount, I18n.tr(context).alreadyHaveAnAccount,
style: TextStyle( style: TextStyle(

View File

@ -1,3 +1,5 @@
import 'package:fluffychat/utils/app_route.dart';
import 'package:fluffychat/views/chat_list.dart';
import 'package:fluffychat/views/login.dart'; import 'package:fluffychat/views/login.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
@ -29,6 +31,11 @@ void main() {
expect( expect(
find.byKey(Key("passwordField")), findsOneWidget); // Password Input find.byKey(Key("passwordField")), findsOneWidget); // Password Input
expect(find.byKey(Key("loginButton")), findsOneWidget); // Login Button expect(find.byKey(Key("loginButton")), findsOneWidget); // Login Button
/*await Utils.tapItem(tester, Key("loginButton"));
// FIXME Use better way
await tester.pump(Duration(seconds: 5));
expect(isPushed, isTrue);*/
}); });
}); });
}); });

40
test/sign_up_test.dart Normal file
View File

@ -0,0 +1,40 @@
import 'package:fluffychat/views/sign_up.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'utils.dart';
void main() {
/// All Tests related to the Login
group("SignUpPage", () {
/// Check if all Elements get created
testWidgets('should get created', (WidgetTester tester) async {
await tester.runAsync(() async {
final TestObserver observer = TestObserver()
..onPushed = (Route<dynamic> route, Route<dynamic> previousRoute) {}
..onPopped = (Route<dynamic> route, Route<dynamic> previousRoute) {};
await tester.pumpWidget(
Utils.getWidgetWrapper(
SignUp(),
observer,
),
);
await tester.pump(Duration.zero);
expect(find.byKey(Key("serverField")), findsOneWidget); // Server field
expect(
find.byKey(Key("usernameField")), findsOneWidget); // Username Input
expect(find.byKey(Key("signUpButton")), findsOneWidget); // Login Button
expect(find.byKey(Key("alreadyHaveAnAccountButton")),
findsOneWidget); // alreadyHaveAnAccount Button
/*await Utils.tapItem(tester, Key("loginButton"));
// FIXME Use better way
await tester.pump(Duration(seconds: 5));
expect(isPushed, isTrue);*/
});
});
});
}

View File

@ -11,6 +11,18 @@ class Utils {
debugPrint(tester.allWidgets.toList().join("\n").toString()); debugPrint(tester.allWidgets.toList().join("\n").toString());
} }
static bool isWidgetInWidgets(WidgetTester tester, Type widget) {
debugPrint(tester.allWidgets
.toList()
.map((e) => e.runtimeType)
.join("\n")
.toString());
return tester.allWidgets
.toList()
.map((e) => e.runtimeType)
.contains(widget);
}
static Client get defaultClient { static Client get defaultClient {
Client client = Client("testclient", debug: true); Client client = Client("testclient", debug: true);
client.httpClient = FakeMatrixApi(); client.httpClient = FakeMatrixApi();