@@ -0,0 +1,67 @@
|
||||
import 'package:jadb/models/kanjivg/kanjivg_path_group.dart';
|
||||
import 'package:jadb/search.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import 'setup_database_connection.dart';
|
||||
|
||||
Iterable<KanjiVGPathGroup> _flattenGroups(
|
||||
Iterable<KanjiVGPathGroup> groups,
|
||||
) sync* {
|
||||
for (final group in groups) {
|
||||
yield group;
|
||||
yield* _flattenGroups(group.children);
|
||||
}
|
||||
}
|
||||
|
||||
void main() {
|
||||
group('KanjiVG search', () {
|
||||
test('returns null when the entry does not exist', () async {
|
||||
final connection = await setupDatabaseConnection();
|
||||
addTearDown(() async => connection.close());
|
||||
|
||||
final result = await connection.jadbSearchKanjiVGGraph('notfound');
|
||||
|
||||
expect(result, isNull);
|
||||
});
|
||||
|
||||
test('returns entry paths without path groups by default', () async {
|
||||
final connection = await setupDatabaseConnection();
|
||||
addTearDown(() async => connection.close());
|
||||
|
||||
final result = await connection.jadbSearchKanjiVGGraph('休');
|
||||
|
||||
expect(result, isNotNull);
|
||||
expect(result!.character, equals('休'));
|
||||
expect(result.paths, isNotEmpty);
|
||||
expect(result.pathGroups, isNull);
|
||||
});
|
||||
|
||||
test('returns the path-group graph when requested', () async {
|
||||
final connection = await setupDatabaseConnection();
|
||||
addTearDown(() async => connection.close());
|
||||
|
||||
final result = await connection.jadbSearchKanjiVGGraph(
|
||||
'休',
|
||||
includePathGroups: true,
|
||||
);
|
||||
|
||||
expect(result, isNotNull);
|
||||
expect(result!.pathGroups, isNotNull);
|
||||
expect(result.pathGroups, isNotEmpty);
|
||||
|
||||
final allGroups = _flattenGroups(result.pathGroups!).toList();
|
||||
final groupedPathIds =
|
||||
allGroups
|
||||
.expand((group) => group.paths)
|
||||
.map((path) => path.pathId)
|
||||
.toList()
|
||||
..sort();
|
||||
final entryPathIds = result.paths.map((path) => path.pathId).toList()
|
||||
..sort();
|
||||
|
||||
expect(allGroups.any((group) => group.groupId == 0), isTrue);
|
||||
expect(allGroups.any((group) => group.paths.isNotEmpty), isTrue);
|
||||
expect(groupedPathIds, equals(entryPathIds));
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user