Files
EasyDesignCollection/test/home_test.dart
T
admin 0a3f2c5cc6 v1.3.13: 模块化注册架构 + PDS流程设计套件更名 + 依赖/圆周交互修复
- 模块化:EdcModule 契约 + registry + 模块独立目录;发布包增加 modules/registry.json
- 更名:PDS流程设计套件 / ProcessDesignSuite;同步构建、发布脚本与文档
- 时序图:依赖偏移以时间显示/编辑;紧贴依赖隐藏箭头并在接缝显示标签;动作条磁吸
- 圆周:依赖标签沿圆弧方向、环间空隙;动作旋转磁吸增强;短弧标签优先动作名
- 清理:release 移至源码同级(本地不入库);tool 合并到 tools;发布说明迁移 docs/release-notes
2026-11-22 10:02:54 +08:00

115 lines
5.0 KiB
Dart

// 首页(空白启动)与模块注册表测试:
// 注册表唯一性 / 模块 id 映射;首页新建文档、未开放模块、品牌菜单回首页。
import 'package:flutter/material.dart' hide Action;
import 'package:flutter_test/flutter_test.dart';
import 'package:sequence_diagram/model/models.dart';
import 'package:sequence_diagram/modules/registry.dart';
import 'package:sequence_diagram/state/app_controller.dart';
import 'package:sequence_diagram/theme/tokens.dart';
import 'package:sequence_diagram/ui/app_shell.dart';
void main() {
group('模块注册表', () {
test('id / 后缀唯一;时序与架构已开放,其余未开放', () {
final Set<String> ids = kModules.map((EdcModule m) => m.id).toSet();
expect(ids.length, kModules.length);
final Set<String> suffixes =
kModules.map((EdcModule m) => m.suffix).toSet();
expect(suffixes.length, kModules.length);
expect(moduleById('sequence')!.available, isTrue);
expect(moduleById('architecture')!.available, isTrue);
expect(moduleById('elec')!.available, isFalse);
expect(moduleById('unknown-id'), isNull);
});
test('模块 id 映射与标题文案', () {
expect(moduleById(null), isNull);
expect(moduleById('sequence')!.name, '时序图');
expect(moduleById('architecture')!.suffix, '.arch.json');
expect(moduleTitle(null), 'PDS流程设计套件');
expect(moduleTitle('sequence'), contains('时序图'));
expect(moduleTitle('unknown-id'), 'PDS流程设计套件');
});
});
group('首页(空白启动)', () {
Future<AppController> pumpHome(WidgetTester tester) async {
tester.view.physicalSize = const Size(1280, 800);
tester.view.devicePixelRatio = 1.0;
addTearDown(tester.view.reset);
final AppController c = AppController(project: Project.demo());
addTearDown(c.dispose);
await tester.pumpWidget(MaterialApp(
theme: buildTheme(Tokens.light),
home: AppShell(controller: c),
));
c.goHome();
await tester.pump();
return c;
}
testWidgets('空白启动:新建文档网格 + 未开放标注,不渲染工作区', (WidgetTester tester) async {
final AppController c = await pumpHome(tester);
expect(c.activeModuleId, isNull);
expect(find.text('新建文档'), findsOneWidget);
expect(find.text('时序图'), findsOneWidget);
expect(find.text('架构图'), findsOneWidget);
expect(find.text('电器原理图'), findsOneWidget);
expect(find.text('未开放'), findsNWidgets(4));
expect(find.text('打开文档…'), findsOneWidget);
// 首页不显示工作区工具栏。
expect(find.text('导出'), findsNothing);
});
testWidgets('新建时序图:进入工作区并可操作', (WidgetTester tester) async {
final AppController c = await pumpHome(tester);
await tester.tap(find.text('时序图'));
await tester.pumpAndSettle();
expect(c.activeModuleId, 'sequence');
expect(find.text('导出'), findsOneWidget);
expect(c.currentFilePath, isNull);
});
testWidgets('未开放模块:点按无效', (WidgetTester tester) async {
final AppController c = await pumpHome(tester);
await tester.tap(find.text('电器原理图'));
await tester.pump();
expect(c.activeModuleId, isNull);
});
testWidgets('品牌菜单:已进入模块后返回首页(未保存修改先确认)', (WidgetTester tester) async {
final AppController c = await pumpHome(tester);
await tester.tap(find.text('时序图'));
await tester.pumpAndSettle();
expect(c.activeModuleId, 'sequence');
// 打开品牌菜单(按钮显示当前模块名 + 设计;状态栏也有同名文案,取第一个)。
await tester.tap(find.text('时序图设计').first);
await tester.pumpAndSettle();
await tester.tap(find.text('首页'));
await tester.pumpAndSettle();
// 新文档未保存 → 弹出放弃确认。
expect(find.text('放弃未保存的修改?'), findsOneWidget);
await tester.tap(find.text('继续'));
await tester.pumpAndSettle();
expect(c.activeModuleId, isNull);
expect(find.text('新建文档'), findsOneWidget);
});
testWidgets('品牌菜单:从时序图切到架构图(确认丢弃后)', (WidgetTester tester) async {
final AppController c = await pumpHome(tester);
await tester.tap(find.text('时序图'));
await tester.pumpAndSettle();
// 打开品牌菜单(按钮显示当前模块名 + 设计;状态栏也有同名文案,取第一个)。
await tester.tap(find.text('时序图设计').first);
await tester.pumpAndSettle();
await tester.tap(find.text('架构图设计'));
await tester.pumpAndSettle();
expect(find.text('放弃未保存的修改?'), findsOneWidget);
await tester.tap(find.text('继续'));
await tester.pumpAndSettle();
expect(c.activeModuleId, 'architecture');
expect(find.text('导出'), findsOneWidget);
});
});
}