You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
94 lines
3.7 KiB
94 lines
3.7 KiB
import 'package:eaimar/core/translations/language/en_us.dart';
|
|
import 'package:eaimar/core/translations/language/zh_cn.dart';
|
|
import 'package:eaimar/data/models/agent_module.dart';
|
|
import 'package:eaimar/data/models/device_category.dart';
|
|
import 'package:eaimar/modules/module_registry.dart';
|
|
import 'package:eaimar/routes/app_pages.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
|
|
/// Agent 模块注册表卫生:新增模块只动 `lib/modules/<name>/` + 注册表一行,
|
|
/// 这里守住每条描述符都接完了线。
|
|
void main() {
|
|
TestWidgetsFlutterBinding.ensureInitialized();
|
|
|
|
test('模块 id 唯一', () {
|
|
final ids = ModuleRegistry.all.map((m) => m.id).toList();
|
|
expect(ids.toSet().length, ids.length, reason: '重复 id: $ids');
|
|
});
|
|
|
|
test('已实现的模块都有跳转方式;占位模块可以没有', () {
|
|
final broken = ModuleRegistry.all
|
|
.where((m) => !m.comingSoon && m.entryRoute == null && m.onLaunch == null)
|
|
.map((m) => m.id)
|
|
.toList();
|
|
expect(broken, isEmpty, reason: '这些模块点了没反应: $broken');
|
|
});
|
|
|
|
test('entryRoute 指向的页面已注册', () {
|
|
final registered = AppPages.pages.map((p) => p.name).toSet();
|
|
final missing = ModuleRegistry.all
|
|
.where((m) => m.entryRoute != null && !registered.contains(m.entryRoute))
|
|
.map((m) => '${m.id} -> ${m.entryRoute}')
|
|
.toList();
|
|
expect(missing, isEmpty, reason: missing.join('\n'));
|
|
});
|
|
|
|
test('模块页面都进了总路由表,且 name 不与核心页面撞车', () {
|
|
final all = AppPages.pages.map((p) => p.name).toList();
|
|
for (final p in ModuleRegistry.pages) {
|
|
expect(all.where((n) => n == p.name).length, 1,
|
|
reason: '${p.name} 注册了 ${all.where((n) => n == p.name).length} 次');
|
|
}
|
|
});
|
|
|
|
test('标题/副标题的 i18n key 在 en_US 与 zh_CN 里有落点(或模块自带)', () {
|
|
final merged = ModuleRegistry.mergeTranslations({'en_US': enUS, 'zh_CN': zhCN});
|
|
final missing = <String>[];
|
|
for (final m in ModuleRegistry.all) {
|
|
for (final loc in ['en_US', 'zh_CN']) {
|
|
final table = merged[loc]!;
|
|
if (!table.containsKey(m.title)) missing.add('$loc:${m.title}');
|
|
final sub = m.subtitle;
|
|
if (sub != null && !table.containsKey(sub)) missing.add('$loc:$sub');
|
|
}
|
|
}
|
|
expect(missing, isEmpty, reason: '缺文案: $missing');
|
|
});
|
|
|
|
test('注册表注入后 AgentModules.all 与 ModuleRegistry.all 同一份', () {
|
|
ModuleRegistry.install();
|
|
expect(identical(AgentModules.all, ModuleRegistry.all), isTrue);
|
|
expect(AgentModules.byId('meeting'), isNotNull);
|
|
});
|
|
|
|
test('指令处理器同名不重复注册', () {
|
|
final names = <String>[];
|
|
for (final m in ModuleRegistry.all) {
|
|
names.addAll(m.directives.keys);
|
|
}
|
|
expect(names.toSet().length, names.length, reason: '重复指令: $names');
|
|
});
|
|
|
|
group('设备品类默认编排', () {
|
|
test('车载香薰连上后铺 EaiCar / 现场录音 / 语音纪要(按这个顺序)', () {
|
|
expect(
|
|
AgentModules.defaultsForCategory(DeviceCategories.carAroma),
|
|
[
|
|
AgentModules.eaicarChat,
|
|
AgentModules.fieldRecording,
|
|
AgentModules.meeting,
|
|
],
|
|
);
|
|
});
|
|
|
|
test('这三个都不依赖设备能力,所以连上香薰不会灰', () {
|
|
ModuleRegistry.install();
|
|
for (final id in AgentModules.defaultsForCategory(DeviceCategories.carAroma)) {
|
|
final m = ModuleRegistry.byId(id);
|
|
expect(m, isNotNull, reason: '$id 不在注册表里');
|
|
expect(m!.requiredCapabilities, isEmpty,
|
|
reason: '$id 声明了 requiredCapabilities,车载香薰没有这些能力时会被置灰');
|
|
}
|
|
});
|
|
});
|
|
}
|
|
|