mirror of
https://github.com/wger-project/flutter.git
synced 2026-02-18 00:17:48 +01:00
Add auth screen widget test
This commit is contained in:
@@ -62,7 +62,7 @@ class AuthScreen extends StatelessWidget {
|
||||
),
|
||||
),
|
||||
Flexible(
|
||||
flex: deviceSize.width > 600 ? 2 : 1,
|
||||
//flex: deviceSize.width > 600 ? 2 : 1,
|
||||
child: AuthCard(),
|
||||
),
|
||||
],
|
||||
@@ -195,6 +195,7 @@ class _AuthCardState extends State<AuthCard> {
|
||||
child: Column(
|
||||
children: <Widget>[
|
||||
TextFormField(
|
||||
key: Key('inputUsername'),
|
||||
decoration: InputDecoration(labelText: 'Username'),
|
||||
controller: _usernameController,
|
||||
textInputAction: TextInputAction.next,
|
||||
@@ -211,6 +212,7 @@ class _AuthCardState extends State<AuthCard> {
|
||||
),
|
||||
if (_authMode == AuthMode.Signup)
|
||||
TextFormField(
|
||||
key: Key('inputEmail'),
|
||||
decoration: InputDecoration(labelText: 'E-Mail'),
|
||||
controller: _emailController,
|
||||
keyboardType: TextInputType.emailAddress,
|
||||
@@ -226,6 +228,7 @@ class _AuthCardState extends State<AuthCard> {
|
||||
},
|
||||
),
|
||||
TextFormField(
|
||||
key: Key('inputPassword'),
|
||||
decoration: InputDecoration(labelText: 'Password'),
|
||||
obscureText: true,
|
||||
controller: _passwordController,
|
||||
@@ -244,6 +247,7 @@ class _AuthCardState extends State<AuthCard> {
|
||||
),
|
||||
if (_authMode == AuthMode.Signup)
|
||||
TextFormField(
|
||||
key: Key('inputPassword2'),
|
||||
decoration: InputDecoration(labelText: 'Confirm Password'),
|
||||
controller: _password2Controller,
|
||||
enabled: _authMode == AuthMode.Signup,
|
||||
@@ -258,6 +262,7 @@ class _AuthCardState extends State<AuthCard> {
|
||||
: null,
|
||||
),
|
||||
TextFormField(
|
||||
key: Key('inputServer'),
|
||||
decoration: InputDecoration(labelText: 'Server URL'),
|
||||
controller: _serverUrlController,
|
||||
validator: (value) {
|
||||
@@ -277,11 +282,13 @@ class _AuthCardState extends State<AuthCard> {
|
||||
CircularProgressIndicator()
|
||||
else
|
||||
ElevatedButton(
|
||||
child: Text(_authMode == AuthMode.Login ? 'LOGIN' : 'SIGN UP'),
|
||||
key: Key('actionButton'),
|
||||
child: Text(_authMode == AuthMode.Login ? 'LOGIN' : 'REGISTER'),
|
||||
onPressed: _submit,
|
||||
),
|
||||
TextButton(
|
||||
child: Text('${_authMode == AuthMode.Login ? 'SIGNUP' : 'LOGIN'} INSTEAD'),
|
||||
key: Key('toggleActionButton'),
|
||||
child: Text('${_authMode == AuthMode.Login ? 'REGISTER' : 'LOGIN'} INSTEAD'),
|
||||
onPressed: _switchAuthMode,
|
||||
),
|
||||
],
|
||||
|
||||
51
test/auth_screen_test.dart
Normal file
51
test/auth_screen_test.dart
Normal file
@@ -0,0 +1,51 @@
|
||||
// This is a basic Flutter widget test.
|
||||
//
|
||||
// To perform an interaction with a widget in your test, use the WidgetTester
|
||||
// utility that Flutter provides. For example, you can send tap and scroll
|
||||
// gestures. You can also use WidgetTester to find child widgets in the widget
|
||||
// tree, read text, and verify that the values of widget properties are correct.
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:wger/screens/auth_screen.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('Test the widgets on the auth screen, login mode', (WidgetTester tester) async {
|
||||
// Wrap screen in material app so that the media query gets a context
|
||||
await tester.pumpWidget(MaterialApp(home: AuthScreen()));
|
||||
expect(find.text('WGER'), findsOneWidget);
|
||||
|
||||
// Verify that the correct buttons and input fields are shown: login
|
||||
expect(find.text('REGISTER INSTEAD'), findsOneWidget);
|
||||
expect(find.text('LOGIN INSTEAD'), findsNothing);
|
||||
|
||||
// Check that the correct widgets are shown
|
||||
expect(find.byKey(Key('inputUsername')), findsOneWidget);
|
||||
expect(find.byKey(Key('inputEmail')), findsNothing);
|
||||
expect(find.byKey(Key('inputPassword')), findsOneWidget);
|
||||
expect(find.byKey(Key('inputServer')), findsOneWidget);
|
||||
expect(find.byKey(Key('inputPassword2')), findsNothing);
|
||||
expect(find.byKey(Key('actionButton')), findsOneWidget);
|
||||
expect(find.byKey(Key('toggleActionButton')), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('Test the widgets on the auth screen, registration', (WidgetTester tester) async {
|
||||
// Wrap screen in material app so that the media query gets a context
|
||||
await tester.pumpWidget(MaterialApp(home: AuthScreen()));
|
||||
await tester.tap(find.byKey(Key('toggleActionButton')));
|
||||
|
||||
// Rebuild the widget after the state has changed.
|
||||
await tester.pump();
|
||||
expect(find.text('REGISTER INSTEAD'), findsNothing);
|
||||
expect(find.text('LOGIN INSTEAD'), findsOneWidget);
|
||||
|
||||
// Check that the correct widgets are shown
|
||||
expect(find.byKey(Key('inputUsername')), findsOneWidget);
|
||||
expect(find.byKey(Key('inputEmail')), findsOneWidget);
|
||||
expect(find.byKey(Key('inputPassword')), findsOneWidget);
|
||||
expect(find.byKey(Key('inputServer')), findsOneWidget);
|
||||
expect(find.byKey(Key('inputPassword2')), findsOneWidget);
|
||||
expect(find.byKey(Key('actionButton')), findsOneWidget);
|
||||
expect(find.byKey(Key('toggleActionButton')), findsOneWidget);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user