import 'package:desktop_plugin/agent.dart'; import 'package:desktop_plugin/ui/app_shell.dart'; import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; /// UI 冒烟:真实装配 Agent + AppShell,捕获布局/渲染异常。 /// 注意:Agent 的端口绑定/关停是真实 socket I/O,必须放 tester.runAsync /// 让真实 event loop 驱动(fake async zone 里 await 真实 I/O 会永久挂起)。 void main() { testWidgets('AppShell + 饭卡打印机页布局无异常', (tester) async { final agent = Agent(AgentOptions(mock: true, port: 38295)); await tester.runAsync(() => agent.start()); addTearDown(() => tester.runAsync(() => agent.stop())); await tester.pumpWidget(MaterialApp( theme: ThemeData(brightness: Brightness.dark, useMaterial3: true), home: AppShell(agent: agent), )); // 用显式 pump 推帧(不用 pumpAndSettle:页面含持续动画组件时在 fake clock 下永不能 settle) await tester.pump(const Duration(milliseconds: 100)); await tester.pump(const Duration(milliseconds: 100)); await tester.pump(const Duration(milliseconds: 300)); expect(find.text('饭卡打印机'), findsWidgets); expect(find.text('技术详情'), findsOneWidget); // 展开技术详情,覆盖详情区(Table/日志)布局 await tester.tap(find.text('技术详情')); await tester.pump(const Duration(milliseconds: 400)); await tester.pump(const Duration(milliseconds: 400)); // 显式停掉常驻 Timer(清理定时器),避免测试框架的 pending timer 断言 await tester.runAsync(() => agent.stop()); }); }