97 lines
3.0 KiB
Dart
97 lines
3.0 KiB
Dart
import 'dart:async';
|
|
|
|
import 'package:ducafe_ui_core/ducafe_ui_core.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:forui/forui.dart';
|
|
import 'package:get/get.dart';
|
|
|
|
import 'package:pj_supermarket_cloud/common/index.dart';
|
|
|
|
/// 验证睡眠状态只由成功的单次密码校验解除。
|
|
void main() {
|
|
test('取消验证后保持睡眠,验证成功后恢复主屏', () async {
|
|
final control = TerminalSleepControl();
|
|
|
|
control.enterSleep();
|
|
expect(control.isSleeping.value, isTrue);
|
|
expect(await control.requestWake(() async => false), isFalse);
|
|
expect(control.isSleeping.value, isTrue);
|
|
|
|
expect(await control.requestWake(() async => true), isTrue);
|
|
expect(control.isSleeping.value, isFalse);
|
|
});
|
|
|
|
test('并发唤醒只执行首个密码校验', () async {
|
|
final control = TerminalSleepControl()..enterSleep();
|
|
final verification = Completer<bool>();
|
|
var verificationCount = 0;
|
|
|
|
final firstWake = control.requestWake(() {
|
|
verificationCount++;
|
|
return verification.future;
|
|
});
|
|
final duplicateWake = await control.requestWake(() async {
|
|
verificationCount++;
|
|
return true;
|
|
});
|
|
|
|
expect(duplicateWake, isFalse);
|
|
expect(verificationCount, 1);
|
|
expect(control.isSleeping.value, isTrue);
|
|
|
|
verification.complete(true);
|
|
expect(await firstWake, isTrue);
|
|
expect(control.isSleeping.value, isFalse);
|
|
});
|
|
|
|
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);
|
|
Get.testMode = true;
|
|
Get.put(TerminalSleepControl()..enterSleep());
|
|
addTearDown(() {
|
|
Get.reset();
|
|
Get.testMode = false;
|
|
});
|
|
|
|
await tester.pumpWidget(
|
|
ScreenUtilInit(
|
|
designSize: const Size(1920, 1080),
|
|
minTextAdapt: true,
|
|
splitScreenMode: true,
|
|
builder: (_, __) => MaterialApp(
|
|
home: FTheme(
|
|
data: FThemes.zinc.light,
|
|
child: const TerminalSleepOverlay(),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
await tester.pump();
|
|
|
|
expect(find.text('主屏已锁定'), findsOneWidget);
|
|
expect(find.text('终端正在休息'), findsOneWidget);
|
|
expect(find.text('人脸与饭卡服务保持运行'), findsOneWidget);
|
|
expect(
|
|
find.byKey(const ValueKey('terminal-sleep-illustration')),
|
|
findsOneWidget,
|
|
);
|
|
expect(find.text('唤醒终端'), findsOneWidget);
|
|
expect(
|
|
tester
|
|
.getSize(
|
|
find.byKey(const ValueKey('terminal-sleep-wake-button')),
|
|
)
|
|
.height,
|
|
greaterThanOrEqualTo(48),
|
|
);
|
|
expect(tester.takeException(), isNull);
|
|
});
|
|
}
|
|
}
|