159 lines
3.9 KiB
Dart
159 lines
3.9 KiB
Dart
import 'package:flutter_test/flutter_test.dart';
|
|
|
|
void main() {
|
|
group('Client Data', () {
|
|
test('client name combines first and last', () {
|
|
final client = {
|
|
'firstName': 'John',
|
|
'lastName': 'Doe',
|
|
};
|
|
|
|
final name = '${client['firstName']} ${client['lastName']}';
|
|
expect(name, 'John Doe');
|
|
});
|
|
|
|
test('client initials are extracted correctly', () {
|
|
final client = {
|
|
'firstName': 'John',
|
|
'lastName': 'Doe',
|
|
};
|
|
|
|
final initials = '${client['firstName']![0]}${client['lastName']![0]}';
|
|
expect(initials, 'JD');
|
|
});
|
|
|
|
test('tags default to empty list', () {
|
|
final client = <String, dynamic>{
|
|
'firstName': 'John',
|
|
'lastName': 'Doe',
|
|
'tags': null,
|
|
};
|
|
|
|
final tags = (client['tags'] as List?)?.cast<String>() ?? [];
|
|
expect(tags, isEmpty);
|
|
});
|
|
|
|
test('tags list contains expected items', () {
|
|
final client = {
|
|
'firstName': 'John',
|
|
'lastName': 'Doe',
|
|
'tags': ['vip', 'active'],
|
|
};
|
|
|
|
final tags = (client['tags'] as List?)?.cast<String>() ?? [];
|
|
expect(tags, hasLength(2));
|
|
expect(tags, contains('vip'));
|
|
});
|
|
|
|
test('company can be null', () {
|
|
final client = {
|
|
'firstName': 'John',
|
|
'lastName': 'Doe',
|
|
'company': null,
|
|
};
|
|
|
|
final company = client['company'];
|
|
expect(company, isNull);
|
|
});
|
|
|
|
test('company can be empty string', () {
|
|
final client = {
|
|
'firstName': 'John',
|
|
'lastName': 'Doe',
|
|
'company': '',
|
|
};
|
|
|
|
final company = client['company'];
|
|
final hasCompany = company != null && company.isNotEmpty;
|
|
expect(hasCompany, isFalse);
|
|
});
|
|
});
|
|
|
|
group('Search Functionality', () {
|
|
test('empty search returns null query', () {
|
|
final searchText = '';
|
|
final query = searchText.isEmpty ? null : searchText;
|
|
expect(query, isNull);
|
|
});
|
|
|
|
test('non-empty search returns query', () {
|
|
final searchText = 'John';
|
|
final query = searchText.isEmpty ? null : searchText;
|
|
expect(query, 'John');
|
|
});
|
|
|
|
test('whitespace-only considered non-empty', () {
|
|
final searchText = ' ';
|
|
final query = searchText.isEmpty ? null : searchText;
|
|
expect(query, isNotNull); // Note: might want to trim
|
|
});
|
|
});
|
|
|
|
group('Client List Display', () {
|
|
test('shows maximum 3 tags', () {
|
|
final tags = ['vip', 'active', 'referral', 'premium', 'gold'];
|
|
final displayTags = tags.take(3).toList();
|
|
expect(displayTags, hasLength(3));
|
|
expect(displayTags, ['vip', 'active', 'referral']);
|
|
});
|
|
|
|
test('empty list shows empty message', () {
|
|
final clients = <Map<String, dynamic>>[];
|
|
expect(clients.isEmpty, isTrue);
|
|
});
|
|
});
|
|
|
|
group('Client Form Validation', () {
|
|
test('first name is required', () {
|
|
final firstName = '';
|
|
final isValid = firstName.isNotEmpty;
|
|
expect(isValid, isFalse);
|
|
});
|
|
|
|
test('last name is required', () {
|
|
final lastName = '';
|
|
final isValid = lastName.isNotEmpty;
|
|
expect(isValid, isFalse);
|
|
});
|
|
|
|
test('email format validation', () {
|
|
final validEmails = [
|
|
'test@example.com',
|
|
'user.name@domain.org',
|
|
];
|
|
|
|
final emailRegex = RegExp(r'^[^\s@]+@[^\s@]+\.[^\s@]+$');
|
|
|
|
for (final email in validEmails) {
|
|
expect(emailRegex.hasMatch(email), isTrue);
|
|
}
|
|
});
|
|
|
|
test('invalid email detected', () {
|
|
final invalidEmails = [
|
|
'notanemail',
|
|
'@missing.local',
|
|
'missing@domain',
|
|
];
|
|
|
|
final emailRegex = RegExp(r'^[^\s@]+@[^\s@]+\.[^\s@]+$');
|
|
|
|
for (final email in invalidEmails) {
|
|
expect(emailRegex.hasMatch(email), isFalse);
|
|
}
|
|
});
|
|
|
|
test('phone number can have various formats', () {
|
|
final phones = [
|
|
'+1234567890',
|
|
'(123) 456-7890',
|
|
'123-456-7890',
|
|
];
|
|
|
|
for (final phone in phones) {
|
|
expect(phone.isNotEmpty, isTrue);
|
|
}
|
|
});
|
|
});
|
|
}
|