Made the first test and changed some small things

This commit is contained in:
Jacques Doeleman 2022-09-28 17:01:47 +02:00
parent f7f29dbbd3
commit cd483d77d8
5 changed files with 122 additions and 16 deletions

View file

@ -275,18 +275,23 @@ class _FlutterFormState extends ConsumerState<FlutterForm> {
widget.options.nextButton != null widget.options.nextButton != null
? widget.options.nextButton!(_formController.getCurrentStep(), ? widget.options.nextButton!(_formController.getCurrentStep(),
_formController.getCheckpages()) _formController.getCheckpages())
: ElevatedButton( : Align(
style: ElevatedButton.styleFrom( alignment: AlignmentDirectional.bottomCenter,
backgroundColor: Theme.of(context).primaryColor, child: ElevatedButton(
padding: const EdgeInsets.symmetric( style: ElevatedButton.styleFrom(
horizontal: 40, vertical: 15), backgroundColor: Theme.of(context).primaryColor,
textStyle: const TextStyle( padding: const EdgeInsets.symmetric(
fontSize: 20, fontWeight: FontWeight.bold)), horizontal: 40, vertical: 15),
onPressed: () => _formController.autoNextStep(), textStyle: const TextStyle(
child: Text(_formController.getCurrentStep() >= fontSize: 20, fontWeight: FontWeight.bold)),
widget.options.pages.length - 1 onPressed: () async {
? "Finish" await _formController.autoNextStep();
: "Next"), },
child: Text(_formController.getCurrentStep() >=
widget.options.pages.length - 1
? "Finish"
: "Next"),
),
), ),
if (widget.options.backButton != null) if (widget.options.backButton != null)
widget.options.backButton!( widget.options.backButton!(

View file

@ -62,11 +62,11 @@ class FlutterFormInputPasswordController
String Function(String, {List<String>? params}) translator) { String Function(String, {List<String>? params}) translator) {
if (mandatory) { if (mandatory) {
if (value == null || value.isEmpty) { if (value == null || value.isEmpty) {
return translator('Field cannot be empty'); return translator('Field can not be empty');
} }
if (value.length < 6) { if (value.length < 6) {
return translator('Field cannot be empty'); return translator('Field should be atleast 6 characters long');
} }
} }

View file

@ -111,7 +111,7 @@ class FlutterFormInputPlainTextController
String Function(String, {List<String>? params}) translator) { String Function(String, {List<String>? params}) translator) {
if (mandatory) { if (mandatory) {
if (value == null || value.isEmpty) { if (value == null || value.isEmpty) {
return translator('Field cannot be empty'); return translator('Field can not be empty');
} }
} }

102
test/flutter_form_test.dart Normal file
View file

@ -0,0 +1,102 @@
import 'package:flutter/material.dart';
import 'package:flutter_form/flutter_form.dart';
import 'package:flutter_form/next_shell/form.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('Normal walk through with check page', (tester) async {
FlutterFormController formController = FlutterFormController();
var testField1Controller = FlutterFormInputPlainTextController(
id: 'Field1',
);
var testField2Controller = FlutterFormInputPlainTextController(
id: 'Field2',
);
int? onNextPageNumber;
Map<String, dynamic>? onNextResults;
Map<int, Map<String, dynamic>>? onFinishResults;
await tester.pumpWidget(
MaterialApp(
home: Material(
child: FlutterForm(
options: FlutterFormOptions(
checkPage: const CheckPage(),
nextButton: (pageNumber, checkingPages) {
return Align(
alignment: Alignment.bottomCenter,
child: ElevatedButton(
onPressed: () async {
await formController.autoNextStep();
},
child: Text(pageNumber == 0
? 'next1'
: pageNumber == 1
? 'next2'
: 'finish'),
),
);
},
onFinished: (Map<int, Map<String, dynamic>> results) {
print('finished results: $results');
onFinishResults = results;
},
onNext: (int pageNumber, Map<String, dynamic> results) {
print('nextResults: $pageNumber: $results');
onNextPageNumber = pageNumber;
onNextResults = results;
},
pages: [
FlutterFormPage(
child: Center(
child: FlutterFormInputPlainText(
label: const Text('Field1Label'),
controller: testField1Controller,
),
),
),
FlutterFormPage(
child: Center(
child: FlutterFormInputPlainText(
label: const Text('Field2Label'),
controller: testField2Controller,
),
),
),
],
),
formController: formController,
),
),
),
);
await tester.enterText(
find.widgetWithText(TextFormField, 'Field1Label'), 'Field1Input');
await tester.tap(find.widgetWithText(ElevatedButton, 'next1'));
await tester.pumpAndSettle();
expect(0, onNextPageNumber);
expect({'Field1': 'Field1Input'}, onNextResults);
await tester.enterText(
find.widgetWithText(TextFormField, 'Field2Label'), 'Field2Input');
await tester.tap(find.widgetWithText(ElevatedButton, 'next2'));
await tester.pumpAndSettle();
expect(1, onNextPageNumber);
expect({'Field2': 'Field2Input'}, onNextResults);
await tester.tap(find.widgetWithText(ElevatedButton, "finish"));
await tester.pumpAndSettle();
expect({
0: {'Field1': 'Field1Input'},
1: {'Field2': 'Field2Input'}
}, onFinishResults);
});
}

View file

@ -1 +0,0 @@