71 lines
2.4 KiB
Dart
71 lines
2.4 KiB
Dart
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:stream_chat_flutter/src/extension.dart';
|
|
import 'package:stream_chat_flutter/stream_chat_flutter.dart';
|
|
|
|
void main() {
|
|
group('List<User>.search', () {
|
|
test('should work fine', () {
|
|
final tommaso = User(id: 'tommaso', name: 'Tommaso');
|
|
final thierry = User(id: 'thierry', name: 'Thierry');
|
|
final users = [tommaso, thierry];
|
|
|
|
expect(users.search('Tom'), [tommaso]);
|
|
expect(users.search('Thier'), [thierry]);
|
|
});
|
|
|
|
test('should search using UpperCased', () {
|
|
final tommaso = User(id: 'tommaso', name: 'Tommaso');
|
|
final thierry = User(id: 'thierry', name: 'Thierry');
|
|
final users = [tommaso, thierry];
|
|
|
|
expect(users.search('tom'), [tommaso]);
|
|
expect(users.search('thier'), [thierry]);
|
|
});
|
|
|
|
test('should search by .id or .name', () {
|
|
final user1 = User(id: 'searchingThis');
|
|
final user2 = User(id: 'x', name: 'searchingThis');
|
|
|
|
expect([user1].search('sear'), [user1]);
|
|
expect([user2].search('sear'), [user2]);
|
|
});
|
|
|
|
test('should search transliterated', () {
|
|
final tommaso = User(id: 'tommaso', name: 'Tommaso');
|
|
final thierry = User(id: 'thierry', name: 'Thierry');
|
|
final users = [tommaso, thierry];
|
|
|
|
expect(users.search('tóm'), [tommaso]);
|
|
expect(users.search('thíer'), [thierry]);
|
|
});
|
|
|
|
test('search and sorted by distance', () {
|
|
final tommaso = User(id: 'tommaso', name: 'Tommaso');
|
|
final tomas = User(id: 'tomas', name: 'Tomas');
|
|
final users = [tommaso, tomas];
|
|
|
|
expect(users.search('tom'), [tomas, tommaso]);
|
|
});
|
|
|
|
test('should work fine with cyrillic diacritics', () {
|
|
final petyo = User(id: '42', name: 'Петьо');
|
|
final anastasia = User(id: '13', name: 'Анастасiя');
|
|
final dmitriy = User(id: '99', name: 'Дмитрий');
|
|
final users = [petyo, anastasia, dmitriy];
|
|
|
|
expect(users.search('petyo'), []);
|
|
expect(users.search('Пе'), [petyo]);
|
|
expect(users.search('Ана'), [anastasia]);
|
|
expect(users.search('Дмитри'), [dmitriy]);
|
|
expect(users.search('Дмитрии'), [dmitriy]);
|
|
});
|
|
|
|
test('should work fine with french diacritics', () {
|
|
final user = User(id: 'fra', name: 'françois');
|
|
|
|
expect([user].search('françois'), [user]);
|
|
expect([user].search('franc'), [user]);
|
|
});
|
|
});
|
|
}
|