// 首页(空白启动)与模块注册表测试: // 注册表唯一性 / 模块 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 ids = kModules.map((EdcModule m) => m.id).toSet(); expect(ids.length, kModules.length); final Set 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 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); }); }); }