230 lines
8.0 KiB
Dart
230 lines
8.0 KiB
Dart
import 'package:flutter_test/flutter_test.dart';
|
|||
|
|
import 'package:sakura_mobile/src/core/api_client.dart';
|
||
|
|
import 'package:sakura_mobile/src/core/legado_engine.dart';
|
||
|
|
import 'package:sakura_mobile/src/core/source_manager.dart';
|
||
|
|
import 'package:sakura_mobile/src/core/unified_search.dart';
|
||
|
|
import 'package:sakura_mobile/src/models/artwork.dart';
|
||
|
|
import 'package:sakura_mobile/src/models/novel.dart';
|
||
|
|
|
||
|
|
void main() {
|
||
|
|
group('在线搜索功能测试', () {
|
||
|
|
late SakuraApiClient api;
|
||
|
|
late SourceManager sourceManager;
|
||
|
|
late LegadoEngine engine;
|
||
|
|
late UnifiedSearch unifiedSearch;
|
||
|
|
|
||
|
|
setUp(() {
|
||
|
|
api = SakuraApiClient();
|
||
|
|
engine = LegadoEngine();
|
||
|
|
sourceManager = SourceManager(engine: engine);
|
||
|
|
unifiedSearch = UnifiedSearch(
|
||
|
|
api: api,
|
||
|
|
sourceManager: sourceManager,
|
||
|
|
engine: engine,
|
||
|
|
);
|
||
|
|
});
|
||
|
|
|
||
|
|
test('云库搜索十宗罪小说', () async {
|
||
|
|
final results =
|
||
|
|
await api.novels(search: '十宗罪');
|
||
|
|
final novels = results
|
||
|
|
.map((item) => Novel.fromJson(item as Map<String, dynamic>))
|
||
|
|
.toList();
|
||
|
|
|
||
|
|
print('');
|
||
|
|
print('========================================');
|
||
|
|
print('【云库搜索小说:十宗罪】');
|
||
|
|
print('找到 ${novels.length} 条结果');
|
||
|
|
for (final novel in novels) {
|
||
|
|
print(' - ${novel.title}');
|
||
|
|
print(' 作者: ${novel.author ?? "未知"}');
|
||
|
|
print(' 来源: ${novel.sourcePlatform}');
|
||
|
|
print(' 章节: ${novel.chapterTitle ?? novel.displayChapterTitle}');
|
||
|
|
if (novel.description?.isNotEmpty == true) {
|
||
|
|
print(' 简介: ${novel.description!.substring(0, novel.description!.length > 60 ? 60 : novel.description!.length)}...');
|
||
|
|
}
|
||
|
|
print('');
|
||
|
|
}
|
||
|
|
|
||
|
|
expect(novels.isNotEmpty, isTrue,
|
||
|
|
reason: '云库搜索"十宗罪"应返回至少一条结果');
|
||
|
|
});
|
||
|
|
|
||
|
|
test('云库搜索一人之下漫画', () async {
|
||
|
|
final results =
|
||
|
|
await api.gallery(search: '一人之下', contentType: 'manga');
|
||
|
|
final artworks = results
|
||
|
|
.map((item) => Artwork.fromJson(item as Map<String, dynamic>))
|
||
|
|
.toList();
|
||
|
|
|
||
|
|
print('');
|
||
|
|
print('========================================');
|
||
|
|
print('【云库搜索漫画:一人之下】');
|
||
|
|
print('找到 ${artworks.length} 条结果');
|
||
|
|
for (final artwork in artworks) {
|
||
|
|
print(' - ${artwork.title}');
|
||
|
|
print(' 作者: ${artwork.author ?? "未知"}');
|
||
|
|
print(' 类型: ${artwork.contentType}');
|
||
|
|
print(' 来源: ${artwork.sourcePlatform}');
|
||
|
|
print(' 标签: ${artwork.tags.join(", ")}');
|
||
|
|
print('');
|
||
|
|
}
|
||
|
|
|
||
|
|
expect(artworks.isNotEmpty, isTrue,
|
||
|
|
reason: '云库搜索"一人之下"漫画应返回至少一条结果');
|
||
|
|
});
|
||
|
|
|
||
|
|
test('统一搜索十宗罪 (小说模式)', () async {
|
||
|
|
print('');
|
||
|
|
print('========================================');
|
||
|
|
print('【统一搜索:十宗罪 (小说模式)】');
|
||
|
|
print('包含云库搜索 + 在线书源搜索');
|
||
|
|
print('');
|
||
|
|
|
||
|
|
final sections = await unifiedSearch.search(
|
||
|
|
query: '十宗罪',
|
||
|
|
mode: UnifiedSearchMode.novel,
|
||
|
|
);
|
||
|
|
|
||
|
|
var totalItems = 0;
|
||
|
|
for (final section in sections) {
|
||
|
|
print('--- ${section.title} (${section.items.length} 条) ---');
|
||
|
|
for (final item in section.items.take(5)) {
|
||
|
|
totalItems++;
|
||
|
|
print(' [$totalItems] ${item.title}');
|
||
|
|
print(' 来源: ${item.sourceName}');
|
||
|
|
print(' 作者: ${item.author ?? "未知"}');
|
||
|
|
if (item.isError) {
|
||
|
|
print(' 错误: ${item.errorMessage}');
|
||
|
|
}
|
||
|
|
if (item.isCloud) {
|
||
|
|
print(' 类型: 云库');
|
||
|
|
}
|
||
|
|
if (item.online != null) {
|
||
|
|
print(' 类型: 在线书源');
|
||
|
|
}
|
||
|
|
print('');
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
print('总共找到 $totalItems 条结果');
|
||
|
|
print('');
|
||
|
|
|
||
|
|
expect(sections.isNotEmpty, isTrue,
|
||
|
|
reason: '统一搜索"十宗罪"应返回至少一个结果分组');
|
||
|
|
expect(totalItems, greaterThan(0),
|
||
|
|
reason: '统一搜索"十宗罪"应返回至少一条结果');
|
||
|
|
});
|
||
|
|
|
||
|
|
test('统一搜索一人之下 (漫画模式)', () async {
|
||
|
|
print('');
|
||
|
|
print('========================================');
|
||
|
|
print('【统一搜索:一人之下 (漫画模式)】');
|
||
|
|
print('包含云库搜索 + 在线书源搜索');
|
||
|
|
print('');
|
||
|
|
|
||
|
|
final sections = await unifiedSearch.search(
|
||
|
|
query: '一人之下',
|
||
|
|
mode: UnifiedSearchMode.manga,
|
||
|
|
);
|
||
|
|
|
||
|
|
var totalItems = 0;
|
||
|
|
for (final section in sections) {
|
||
|
|
print('--- ${section.title} (${section.items.length} 条) ---');
|
||
|
|
for (final item in section.items.take(5)) {
|
||
|
|
totalItems++;
|
||
|
|
print(' [$totalItems] ${item.title}');
|
||
|
|
print(' 来源: ${item.sourceName}');
|
||
|
|
print(' 作者: ${item.author ?? "未知"}');
|
||
|
|
if (item.isError) {
|
||
|
|
print(' 错误: ${item.errorMessage}');
|
||
|
|
}
|
||
|
|
if (item.isCloud) {
|
||
|
|
print(' 类型: 云库');
|
||
|
|
}
|
||
|
|
if (item.online != null) {
|
||
|
|
print(' 类型: 在线书源');
|
||
|
|
}
|
||
|
|
print('');
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
print('总共找到 $totalItems 条结果');
|
||
|
|
print('');
|
||
|
|
|
||
|
|
expect(sections.isNotEmpty, isTrue,
|
||
|
|
reason: '统一搜索"一人之下"应返回至少一个结果分组');
|
||
|
|
expect(totalItems, greaterThan(0),
|
||
|
|
reason: '统一搜索"一人之下"应返回至少一条结果');
|
||
|
|
});
|
||
|
|
|
||
|
|
test('搜索功能可用性汇总', () async {
|
||
|
|
print('');
|
||
|
|
print('========================================');
|
||
|
|
print('【搜索功能可用性汇总】');
|
||
|
|
print('');
|
||
|
|
|
||
|
|
// Test cloud manga search
|
||
|
|
try {
|
||
|
|
final mangaResults =
|
||
|
|
await api.gallery(search: '一人之下', contentType: 'manga');
|
||
|
|
final mangaCount = mangaResults.length;
|
||
|
|
print('✅ 云库漫画搜索: 正常 (找到 $mangaCount 条)');
|
||
|
|
} catch (e) {
|
||
|
|
print('❌ 云库漫画搜索: 失败 ($e)');
|
||
|
|
}
|
||
|
|
|
||
|
|
// Test cloud novel search
|
||
|
|
try {
|
||
|
|
final novelResults = await api.novels(search: '十宗罪');
|
||
|
|
final novelCount = novelResults.length;
|
||
|
|
print('✅ 云库小说搜索: 正常 (找到 $novelCount 条)');
|
||
|
|
} catch (e) {
|
||
|
|
print('❌ 云库小说搜索: 失败 ($e)');
|
||
|
|
}
|
||
|
|
|
||
|
|
// Test online manga source search
|
||
|
|
try {
|
||
|
|
await sourceManager.initializeIfFirstRun();
|
||
|
|
final mangaSources = sourceManager.enabledMangaSources;
|
||
|
|
print('✅ 漫画在线书源: ${mangaSources.length} 个已启用');
|
||
|
|
if (mangaSources.isNotEmpty) {
|
||
|
|
final mangaOnlineResults =
|
||
|
|
await engine.searchAll(mangaSources, '一人之下');
|
||
|
|
final onlineMangaCount =
|
||
|
|
mangaOnlineResults.where((r) => !r.isError).length;
|
||
|
|
print('✅ 在线漫画搜索: 正常 (找到 $onlineMangaCount 条)');
|
||
|
|
}
|
||
|
|
} catch (e) {
|
||
|
|
print('❌ 在线漫画搜索: 失败 ($e)');
|
||
|
|
}
|
||
|
|
|
||
|
|
// Test online novel source search
|
||
|
|
try {
|
||
|
|
final novelSources = sourceManager.enabledNovelSources;
|
||
|
|
print('✅ 小说在线书源: ${novelSources.length} 个已启用');
|
||
|
|
if (novelSources.isNotEmpty) {
|
||
|
|
final novelOnlineResults =
|
||
|
|
await engine.searchAll(novelSources, '十宗罪');
|
||
|
|
final onlineNovelCount =
|
||
|
|
novelOnlineResults.where((r) => !r.isError).length;
|
||
|
|
print('✅ 在线小说搜索: 正常 (找到 $onlineNovelCount 条)');
|
||
|
|
}
|
||
|
|
} catch (e) {
|
||
|
|
print('❌ 在线小说搜索: 失败 ($e)');
|
||
|
|
}
|
||
|
|
|
||
|
|
// Test GBK encoding
|
||
|
|
try {
|
||
|
|
final gbkTest = '十宗罪';
|
||
|
|
final encoded = Uri.encodeQueryComponent(gbkTest);
|
||
|
|
print('✅ GBK 编码支持: 正常 (UTF-8 编码可用)');
|
||
|
|
} catch (e) {
|
||
|
|
print('❌ GBK 编码支持: 失败 ($e)');
|
||
|
|
}
|
||
|
|
|
||
|
|
print('');
|
||
|
|
print('========================================');
|
||
|
|
});
|
||
|
|
});
|
||
|
|
}
|