81 lines
2.3 KiB
Dart
81 lines
2.3 KiB
Dart
import 'package:bharat_erp/core/utils/validators.dart';
|
||
import 'package:flutter_test/flutter_test.dart';
|
||
|
||
void main() {
|
||
group('email', () {
|
||
test('accepts valid addresses', () {
|
||
expect(Validators.email('user@example.com'), isNull);
|
||
expect(Validators.email('user.name+tag@company.co.in'), isNull);
|
||
});
|
||
|
||
test('rejects invalid addresses', () {
|
||
expect(Validators.email('not-an-email'), isNotNull);
|
||
expect(Validators.email('user@'), isNotNull);
|
||
});
|
||
|
||
test('optional allows empty', () {
|
||
expect(Validators.optionalEmail(''), isNull);
|
||
expect(Validators.optionalEmail('bad'), isNotNull);
|
||
});
|
||
});
|
||
|
||
group('accountNumber', () {
|
||
test('accepts 9–18 digits', () {
|
||
expect(Validators.accountNumber('123456789'), isNull);
|
||
expect(Validators.accountNumber('123456789012345678'), isNull);
|
||
});
|
||
|
||
test('rejects invalid lengths and non-digits', () {
|
||
expect(Validators.accountNumber('12345'), isNotNull);
|
||
expect(Validators.accountNumber('1234567890123456789'), isNotNull);
|
||
expect(Validators.accountNumber('12345ABC'), isNotNull);
|
||
});
|
||
});
|
||
|
||
group('ifsc', () {
|
||
test('accepts valid IFSC', () {
|
||
expect(Validators.ifsc('SBIN0001234'), isNull);
|
||
expect(Validators.ifsc('sbin0001234'), isNull);
|
||
});
|
||
|
||
test('rejects invalid IFSC', () {
|
||
expect(Validators.ifsc('SBIN001234'), isNotNull);
|
||
expect(Validators.ifsc('SBIN00012345'), isNotNull);
|
||
expect(Validators.ifsc('SB1N0001234'), isNotNull);
|
||
});
|
||
});
|
||
|
||
group('pincode', () {
|
||
test('accepts valid 6-digit pincode', () {
|
||
expect(Validators.pincode('560001'), isNull);
|
||
});
|
||
|
||
test('rejects invalid pincode', () {
|
||
expect(Validators.pincode('056001'), isNotNull);
|
||
expect(Validators.pincode('56001'), isNotNull);
|
||
expect(Validators.pincode('5600011'), isNotNull);
|
||
});
|
||
|
||
test('optional allows empty', () {
|
||
expect(Validators.optionalPincode(''), isNull);
|
||
});
|
||
});
|
||
|
||
group('forFieldKey', () {
|
||
test('routes email and pincode keys', () {
|
||
expect(
|
||
Validators.forFieldKey('email', 'a@b.com', required: true),
|
||
isNull,
|
||
);
|
||
expect(
|
||
Validators.forFieldKey('pincode', '560001', required: false),
|
||
isNull,
|
||
);
|
||
expect(
|
||
Validators.forFieldKey('ifsc', 'HDFC0001234', required: true),
|
||
isNull,
|
||
);
|
||
});
|
||
});
|
||
}
|