70 lines
2.1 KiB
Dart
70 lines
2.1 KiB
Dart
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:ikar/backend/modules/contacts.dart';
|
|
import 'package:ikar/core/contacts/contact_search.dart';
|
|
|
|
void main() {
|
|
test('phonebook includes numbers without ИКАР accounts and sorts by name', () {
|
|
const phonebook = {
|
|
'+79000000002': 'Борис',
|
|
'+79000000001': 'Алёна Тестовая',
|
|
};
|
|
expect(
|
|
ContactSearch.filterPhonebook(phonebook, '').map((entry) => entry.key),
|
|
['+79000000001', '+79000000002'],
|
|
);
|
|
expect(
|
|
ContactSearch.filterPhonebook(phonebook, 'алена').single.value,
|
|
'Алёна Тестовая',
|
|
);
|
|
expect(
|
|
ContactSearch.filterPhonebook(phonebook, '8 (900) 000-00-02').single.key,
|
|
'+79000000002',
|
|
);
|
|
expect(ContactSearch.filterPhonebook(phonebook, 'unknown'), isEmpty);
|
|
});
|
|
|
|
const contacts = [
|
|
CachedContact(
|
|
id: 101,
|
|
accountId: 1,
|
|
firstName: 'Алёна',
|
|
lastName: 'Тестовая',
|
|
phone: 79000000001,
|
|
updateTime: 0,
|
|
),
|
|
CachedContact(
|
|
id: 202,
|
|
accountId: 1,
|
|
firstName: 'Борис',
|
|
phone: 79000000002,
|
|
updateTime: 0,
|
|
),
|
|
];
|
|
|
|
test('empty search preserves every contact and order', () {
|
|
expect(ContactSearch.filter(contacts, ' '), contacts);
|
|
});
|
|
|
|
test('matches name fragments ignoring case, whitespace and yo', () {
|
|
for (final query in ['АЛЕН', 'тест', ' ТЕСТОВАЯ алёна ']) {
|
|
expect(ContactSearch.filter(contacts, query).map((c) => c.id), [101]);
|
|
}
|
|
});
|
|
|
|
test('matches formatted phone, Russian prefix and partial phone', () {
|
|
for (final query in ['+7 (900) 000-00-02', '8 (900) 000-00-02', '00002']) {
|
|
expect(ContactSearch.filter(contacts, query).map((c) => c.id), [202]);
|
|
}
|
|
});
|
|
|
|
test('does not search by contact ID', () {
|
|
expect(ContactSearch.filter(contacts, '101'), isEmpty);
|
|
});
|
|
|
|
test('unmatched text and bare punctuation return empty results', () {
|
|
for (final query in ['Нет такого имени', '+', '---', 'Борис 00001']) {
|
|
expect(ContactSearch.filter(contacts, query), isEmpty);
|
|
}
|
|
});
|
|
}
|