Files
EasyDesignCollection/test/tablet_screenshots_test.dart
T

93 lines
3.7 KiB
Dart
Raw Normal View History

// 平板版演示截图生成:把整个应用外壳在 1280×800(平板横屏基准)下渲染为 PNG。
// 运行方式:flutter test --update-goldens test\tablet_screenshots_test.dart
// 输出:demo/tablet-*.png
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:sequence_diagram/model/models.dart';
import 'package:sequence_diagram/state/app_controller.dart';
import 'package:sequence_diagram/theme/tokens.dart';
import 'package:sequence_diagram/ui/app_shell.dart';
import 'helpers.dart';
void main() {
testWidgets('generate tablet demo screenshots', (WidgetTester tester) async {
await tester.runAsync(() => loadZhFonts());
await tester.runAsync(() => loadMaterialIcons());
tester.view.physicalSize = const Size(1280, 800);
tester.view.devicePixelRatio = 1.0;
addTearDown(tester.view.reset);
final AppController c = AppController(project: demoTiming());
addTearDown(c.dispose);
Widget shell(Tokens t) => RepaintBoundary(
key: const ValueKey<String>('shot'),
child: MaterialApp(
theme: buildTheme(t),
debugShowCheckedModeBanner: false,
home: AppShell(controller: c),
),
);
Future<void> shot(String path) async {
await tester.pump();
await expectLater(find.byKey(const ValueKey<String>('shot')), matchesGoldenFile(path));
}
await tester.pumpWidget(shell(Tokens.light));
await shot('../demo/tablet-bar-light.png');
// 展开左右侧栏(浮层)并钉住,展示停靠布局。
// 注意:不能用 find.byIcon(Icons.chevron_right)——画布右下角的预览卡里
// 也有同类图标且更早出现在组件树中,会误触「切换视图」;改为按坐标点贴边轨道。
await tester.tapAt(const Offset(10, 300));
await tester.pump();
if (tester.any(find.byIcon(Icons.push_pin_outlined))) {
await tester.tap(find.byIcon(Icons.push_pin_outlined).first);
await tester.pump();
}
await tester.tapAt(const Offset(1270, 300));
await tester.pump();
if (tester.any(find.byIcon(Icons.push_pin_outlined))) {
await tester.tap(find.byIcon(Icons.push_pin_outlined).first);
await tester.pump();
}
await shot('../demo/tablet-bar-light-panels.png');
// 圆周视图(浅色,含停靠侧栏)。
c.setViewMode(ViewMode.circular);
await shot('../demo/tablet-circular-light.png');
// 流程图视图(浅色):由时序图自动生成(泳道 = 轨道,只读)。
c.setViewMode(ViewMode.flow);
await shot('../demo/tablet-flow-light.png');
// 流程图导出菜单:SVG / PNG 之外额外提供 drawio 入口(仅流程图)。
await tester.tap(find.text('导出'));
await tester.pumpAndSettle();
await shot('../demo/tablet-flow-export-menu-light.png');
await tester.tapAt(const Offset(5, 5));
await tester.pumpAndSettle();
// 选中动作:右侧属性面板进入只读态(滑块 / 依赖编辑置灰)。
c.select('A2');
await shot('../demo/tablet-flow-selected-light.png');
c.select(null);
// 深色主题:条形、圆周与流程图。
// 注意:MaterialApp 的主题切换带 200ms 过渡动画,必须等动画结束再截图,
// 否则截到的是过渡起点(仍然是浅色)。
c.toggleTheme();
await tester.pumpWidget(shell(Tokens.dark));
await tester.pump(const Duration(milliseconds: 400));
c.setViewMode(ViewMode.bar);
await shot('../demo/tablet-bar-dark.png');
c.setViewMode(ViewMode.circular);
await shot('../demo/tablet-circular-dark.png');
c.setViewMode(ViewMode.flow);
await shot('../demo/tablet-flow-dark.png');
});
}