104 lines
3.4 KiB
Dart
104 lines
3.4 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
|
|
import 'package:pj_supermarket_cloud/sub_screen/page/customer_welcome.dart';
|
|
import 'package:pj_supermarket_cloud/sub_screen/page/customer_welcome_preview.dart';
|
|
|
|
void main() {
|
|
for (final size in [const Size(1920, 1080), const Size(1280, 720)]) {
|
|
testWidgets('${size.width.toInt()}x${size.height.toInt()} 欢迎页无布局异常',
|
|
(tester) async {
|
|
tester.view.physicalSize = size;
|
|
tester.view.devicePixelRatio = 1;
|
|
addTearDown(tester.view.resetPhysicalSize);
|
|
addTearDown(tester.view.resetDevicePixelRatio);
|
|
|
|
await tester.pumpWidget(
|
|
MaterialApp(
|
|
home: CustomerWelcomePage(
|
|
now: () => DateTime(2026, 7, 27, 10, 28),
|
|
),
|
|
),
|
|
);
|
|
await tester.pump();
|
|
|
|
expect(
|
|
find.byKey(const ValueKey('customer-welcome-page')), findsOneWidget);
|
|
expect(
|
|
find.byKey(const ValueKey('customer-welcome-hero')), findsOneWidget);
|
|
expect(
|
|
find.byKey(const ValueKey('customer-welcome-flow')), findsOneWidget);
|
|
expect(
|
|
find.byKey(const ValueKey('customer-welcome-care')), findsOneWidget);
|
|
expect(find.text('终端服务已就绪'), findsOneWidget);
|
|
expect(find.text('正在等待服务开始'), findsOneWidget);
|
|
expect(find.text('内容将自动同步'), findsOneWidget);
|
|
expect(find.text('10:28'), findsOneWidget);
|
|
expect(tester.takeException(), isNull);
|
|
});
|
|
}
|
|
|
|
testWidgets('欢迎页时钟按配置刷新并在页面释放后停止', (tester) async {
|
|
var now = DateTime(2026, 7, 27, 10, 28);
|
|
await tester.pumpWidget(
|
|
MaterialApp(
|
|
home: CustomerWelcomePage(
|
|
now: () => now,
|
|
clockTick: const Duration(seconds: 1),
|
|
),
|
|
),
|
|
);
|
|
expect(find.text('10:28'), findsOneWidget);
|
|
|
|
now = DateTime(2026, 7, 27, 10, 29);
|
|
await tester.pump(const Duration(seconds: 1));
|
|
expect(find.text('10:29'), findsOneWidget);
|
|
|
|
await tester.pumpWidget(const SizedBox.shrink());
|
|
await tester.pump(const Duration(seconds: 2));
|
|
expect(tester.takeException(), isNull);
|
|
});
|
|
|
|
testWidgets('欢迎副屏悬浮按钮和系统返回都能退出预览', (tester) async {
|
|
await tester.pumpWidget(const _WelcomePreviewHarness());
|
|
|
|
await tester.tap(find.text('打开欢迎预览'));
|
|
await tester.pumpAndSettle();
|
|
expect(find.text('退出预览'), findsOneWidget);
|
|
|
|
await tester.tap(find.text('退出预览'));
|
|
await tester.pumpAndSettle();
|
|
expect(find.text('打开欢迎预览'), findsOneWidget);
|
|
|
|
await tester.tap(find.text('打开欢迎预览'));
|
|
await tester.pumpAndSettle();
|
|
await tester.binding.handlePopRoute();
|
|
await tester.pumpAndSettle();
|
|
expect(find.text('打开欢迎预览'), findsOneWidget);
|
|
});
|
|
}
|
|
|
|
class _WelcomePreviewHarness extends StatelessWidget {
|
|
const _WelcomePreviewHarness();
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return MaterialApp(
|
|
home: Builder(
|
|
builder: (context) => Scaffold(
|
|
body: Center(
|
|
child: ElevatedButton(
|
|
onPressed: () => Navigator.of(context).push<void>(
|
|
MaterialPageRoute(
|
|
builder: (_) => const CustomerWelcomePreviewPage(),
|
|
),
|
|
),
|
|
child: const Text('打开欢迎预览'),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|