Files
EasyDesignCollection/test/tablet_screenshots_test.dart
T

68 lines
2.4 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());
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),
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');
// 展开左右侧栏(浮层)并钉住,展示停靠布局。
await tester.tap(find.byIcon(Icons.chevron_right).first);
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.tap(find.byIcon(Icons.chevron_left).first);
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.toggleTheme();
await tester.pumpWidget(shell(Tokens.dark));
c.setViewMode(ViewMode.bar);
await shot('../demo/tablet-bar-dark.png');
c.setViewMode(ViewMode.circular);
await shot('../demo/tablet-circular-dark.png');
});
}