优化录制页面功能,修正剪贴板信息提示,新增停止录制后的结果提示,改进触摸锁定解锁逻辑,提升用户交互体验。
This commit is contained in:
@@ -0,0 +1,126 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:recording_tool/features/recording/widgets/widget_recording_touch_lock_overlay.dart';
|
||||
|
||||
void main() {
|
||||
group('resolveRecordingTouchLockUnlockIntent', () {
|
||||
test('returns stopRecording for portrait bottom 30 percent', () {
|
||||
final intent = resolveRecordingTouchLockUnlockIntent(
|
||||
position: const Offset(120, 466.9),
|
||||
size: const Size(375, 667),
|
||||
);
|
||||
|
||||
expect(intent, RecordingTouchLockUnlockIntent.stopRecording);
|
||||
});
|
||||
|
||||
test('returns unlockOnly for portrait area outside bottom 30 percent', () {
|
||||
final intent = resolveRecordingTouchLockUnlockIntent(
|
||||
position: const Offset(120, 320),
|
||||
size: const Size(375, 667),
|
||||
);
|
||||
|
||||
expect(intent, RecordingTouchLockUnlockIntent.unlockOnly);
|
||||
});
|
||||
|
||||
test('returns stopRecording for landscape right 30 percent', () {
|
||||
final intent = resolveRecordingTouchLockUnlockIntent(
|
||||
position: const Offset(466.9, 120),
|
||||
size: const Size(667, 375),
|
||||
);
|
||||
|
||||
expect(intent, RecordingTouchLockUnlockIntent.stopRecording);
|
||||
});
|
||||
|
||||
test('returns unlockOnly for landscape area outside right 30 percent', () {
|
||||
final intent = resolveRecordingTouchLockUnlockIntent(
|
||||
position: const Offset(320, 120),
|
||||
size: const Size(667, 375),
|
||||
);
|
||||
|
||||
expect(intent, RecordingTouchLockUnlockIntent.unlockOnly);
|
||||
});
|
||||
});
|
||||
|
||||
group('RecordingTouchLockOverlayWidget', () {
|
||||
Future<void> pumpOverlay(
|
||||
WidgetTester tester, {
|
||||
required Size surfaceSize,
|
||||
required ValueChanged<RecordingTouchLockUnlockIntent> onUnlocked,
|
||||
}) async {
|
||||
await tester.binding.setSurfaceSize(surfaceSize);
|
||||
addTearDown(() => tester.binding.setSurfaceSize(null));
|
||||
|
||||
await tester.pumpWidget(
|
||||
ScreenUtilInit(
|
||||
designSize: const Size(375, 812),
|
||||
builder: (context, _) {
|
||||
return MaterialApp(
|
||||
home: Scaffold(
|
||||
body: Stack(
|
||||
children: [
|
||||
RecordingTouchLockOverlayWidget(
|
||||
enabled: true,
|
||||
unlockHoldDuration: const Duration(seconds: 2),
|
||||
onUnlocked: onUnlocked,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
testWidgets('long press in portrait bottom 30 percent stops recording', (
|
||||
tester,
|
||||
) async {
|
||||
RecordingTouchLockUnlockIntent? receivedIntent;
|
||||
await pumpOverlay(
|
||||
tester,
|
||||
surfaceSize: const Size(375, 667),
|
||||
onUnlocked: (intent) => receivedIntent = intent,
|
||||
);
|
||||
|
||||
final gesture = await tester.startGesture(const Offset(120, 600));
|
||||
await tester.pump(const Duration(seconds: 2));
|
||||
await gesture.up();
|
||||
|
||||
expect(receivedIntent, RecordingTouchLockUnlockIntent.stopRecording);
|
||||
});
|
||||
|
||||
testWidgets('long press outside stop area only unlocks', (tester) async {
|
||||
RecordingTouchLockUnlockIntent? receivedIntent;
|
||||
await pumpOverlay(
|
||||
tester,
|
||||
surfaceSize: const Size(375, 667),
|
||||
onUnlocked: (intent) => receivedIntent = intent,
|
||||
);
|
||||
|
||||
final gesture = await tester.startGesture(const Offset(120, 320));
|
||||
await tester.pump(const Duration(seconds: 2));
|
||||
await gesture.up();
|
||||
|
||||
expect(receivedIntent, RecordingTouchLockUnlockIntent.unlockOnly);
|
||||
});
|
||||
|
||||
testWidgets('releasing before hold duration does not unlock', (
|
||||
tester,
|
||||
) async {
|
||||
RecordingTouchLockUnlockIntent? receivedIntent;
|
||||
await pumpOverlay(
|
||||
tester,
|
||||
surfaceSize: const Size(375, 667),
|
||||
onUnlocked: (intent) => receivedIntent = intent,
|
||||
);
|
||||
|
||||
final gesture = await tester.startGesture(const Offset(120, 600));
|
||||
await tester.pump(const Duration(milliseconds: 1500));
|
||||
await gesture.up();
|
||||
await tester.pump(const Duration(seconds: 1));
|
||||
|
||||
expect(receivedIntent, isNull);
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -3,6 +3,7 @@ import 'package:flutter/services.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:recording_tool/app/app.dart';
|
||||
import 'package:recording_tool/features/recording/widgets/widget_recording_button.dart';
|
||||
|
||||
void main() {
|
||||
TestWidgetsFlutterBinding.ensureInitialized();
|
||||
@@ -40,11 +41,11 @@ void main() {
|
||||
testWidgets('recording app renders recording page', (tester) async {
|
||||
await pumpRecordingApp(tester);
|
||||
|
||||
final recordIcon = find.byIcon(Icons.fiber_manual_record);
|
||||
final recordButton = find.byType(RecordingControlButton);
|
||||
|
||||
expect(recordIcon, findsOneWidget);
|
||||
expect(recordButton, findsOneWidget);
|
||||
expect(
|
||||
tester.getCenter(recordIcon).dx,
|
||||
tester.getCenter(recordButton).dx,
|
||||
closeTo(tester.getCenter(find.byType(Scaffold)).dx, 0.5),
|
||||
);
|
||||
});
|
||||
@@ -56,7 +57,7 @@ void main() {
|
||||
|
||||
await pumpRecordingApp(tester);
|
||||
|
||||
expect(find.text('粘贴赛事信息'), findsOneWidget);
|
||||
expect(find.text('粘贴选手信息'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('pastes valid event info from clipboard', (tester) async {
|
||||
@@ -65,11 +66,10 @@ void main() {
|
||||
await pumpRecordingApp(tester);
|
||||
|
||||
clipboardText = validClipboardText;
|
||||
await tester.tap(find.text('粘贴赛事信息'));
|
||||
await tester.pump(const Duration(milliseconds: 500));
|
||||
await tester.tap(find.text('粘贴选手信息'));
|
||||
await tester.pump(const Duration(milliseconds: 700));
|
||||
|
||||
expect(find.text('王东方 丨李想 空中格斗赛'), findsOneWidget);
|
||||
expect(find.text('粘贴赛事信息'), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('shows no event info toast when pasted clipboard is invalid', (
|
||||
@@ -80,7 +80,7 @@ void main() {
|
||||
await pumpRecordingApp(tester);
|
||||
|
||||
clipboardText = 'hello';
|
||||
await tester.tap(find.text('粘贴赛事信息'));
|
||||
await tester.tap(find.text('粘贴选手信息'));
|
||||
await tester.pump();
|
||||
|
||||
expect(find.text('王东方 丨李想 空中格斗赛'), findsNothing);
|
||||
|
||||
Reference in New Issue
Block a user