2022-10-19 11:52:57 +02:00
|
|
|
import 'package:flutter/material.dart';
|
2022-10-14 10:36:34 +02:00
|
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
|
|
|
|
|
|
import 'package:flutter_address_form/flutter_address_form.dart';
|
|
|
|
|
|
|
|
void main() {
|
2022-10-25 15:43:08 +02:00
|
|
|
late RegExp zipcodeRegExp;
|
|
|
|
|
|
|
|
setUp(() {
|
|
|
|
// Testing with Dutch ZipCode
|
|
|
|
zipcodeRegExp = RegExp(r'^[1-9][0-9]{3}\s?[a-zA-Z]{2}$');
|
|
|
|
});
|
2022-10-19 11:52:57 +02:00
|
|
|
testWidgets('Render App with AddressForm Widget', (tester) async {
|
|
|
|
await tester.pumpWidget(
|
|
|
|
MaterialApp(
|
|
|
|
home: Scaffold(
|
|
|
|
appBar: AppBar(),
|
|
|
|
body: AddressForm(
|
2022-10-25 08:36:32 +02:00
|
|
|
onSubmit: (value) => value,
|
|
|
|
controller: AddressController(
|
|
|
|
zipCodeValidator: (text) {
|
2022-10-25 15:43:08 +02:00
|
|
|
if (text != null) {
|
|
|
|
if (text.isEmpty) {
|
|
|
|
return 'Can\'t be empty';
|
|
|
|
}
|
|
|
|
if (!zipcodeRegExp.hasMatch(text)) {
|
|
|
|
return 'Invalid zipcode';
|
|
|
|
}
|
2022-10-25 08:36:32 +02:00
|
|
|
}
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
housenumberValidator: (text) {
|
2022-10-25 15:43:08 +02:00
|
|
|
if (text != null) {
|
|
|
|
if (text.isEmpty) {
|
|
|
|
return 'Can\'t be empty';
|
|
|
|
}
|
|
|
|
if (text.length >= 3 || int.tryParse(text) == null) {
|
|
|
|
return 'Invalid number';
|
|
|
|
}
|
2022-10-25 08:36:32 +02:00
|
|
|
}
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
suffixValidator: (text) {
|
2022-10-25 15:43:08 +02:00
|
|
|
if (text != null) {
|
|
|
|
if (text.isNotEmpty && RegExp(r'/^[a-z]*$/').hasMatch(text)) {
|
|
|
|
return 'Invalid prefix';
|
|
|
|
}
|
2022-10-25 08:36:32 +02:00
|
|
|
}
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
streetValidator: (text) {
|
2022-10-25 15:43:08 +02:00
|
|
|
if (text != null) {
|
|
|
|
if (text.isEmpty) {
|
|
|
|
return 'Can\'t be empty';
|
|
|
|
}
|
2022-10-25 08:36:32 +02:00
|
|
|
}
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
cityValidator: (text) {
|
2022-10-25 15:43:08 +02:00
|
|
|
if (text != null) {
|
|
|
|
if (text.isEmpty) {
|
|
|
|
return 'Can\'t be empty';
|
|
|
|
}
|
2022-10-25 08:36:32 +02:00
|
|
|
}
|
|
|
|
return null;
|
|
|
|
},
|
2022-10-25 15:43:08 +02:00
|
|
|
onAutoComplete: (address) {
|
|
|
|
return address;
|
|
|
|
},
|
2022-10-25 08:36:32 +02:00
|
|
|
),
|
2022-10-19 11:52:57 +02:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
await tester.pump();
|
2022-10-14 10:36:34 +02:00
|
|
|
});
|
|
|
|
}
|