1.广角/主摄切换按钮已上移:
2.新增 isSwitchingLens 状态、避免切换镜头 stop 按钮禁用,不会触发 stopRecording 倍距按钮禁用,避免连续切换 ViewModel 层也兜底:isSwitchingLens=true 时直接拒绝 stop 3.合并失败兜底提示
This commit is contained in:
@@ -1,9 +1,12 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:permission_handler/permission_handler.dart';
|
||||
import 'package:recording_tool/features/recording/model/model_recording_session.dart';
|
||||
import 'package:recording_tool/features/recording/platform/recording_channel_names.dart';
|
||||
import 'package:recording_tool/features/recording/platform/recording_platform.dart';
|
||||
import 'package:recording_tool/features/recording/view-model/view_model_recording.dart';
|
||||
|
||||
void main() {
|
||||
@@ -255,6 +258,125 @@ void main() {
|
||||
expect(session.errorMessage, '切换镜头失败,请重试');
|
||||
},
|
||||
);
|
||||
|
||||
test('sets switching lens while native zoom request is pending', () async {
|
||||
final completer = Completer<Map<String, dynamic>>();
|
||||
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
|
||||
.setMockMethodCallHandler(
|
||||
const MethodChannel(RecordingChannelNames.method),
|
||||
(call) => completer.future,
|
||||
);
|
||||
final container = ProviderContainer();
|
||||
addTearDown(container.dispose);
|
||||
final notifier = container.read(recordingViewModelProvider.notifier);
|
||||
|
||||
final future = notifier.setZoomRatio(2);
|
||||
await Future<void>.delayed(Duration.zero);
|
||||
|
||||
expect(
|
||||
container.read(recordingViewModelProvider).session.isSwitchingLens,
|
||||
isTrue,
|
||||
);
|
||||
|
||||
completer.complete(<String, dynamic>{
|
||||
'zoomRatio': 2.0,
|
||||
'minZoomRatio': 1.0,
|
||||
'maxZoomRatio': 3.0,
|
||||
});
|
||||
await future;
|
||||
|
||||
expect(
|
||||
container.read(recordingViewModelProvider).session.isSwitchingLens,
|
||||
isFalse,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
group('RecordingViewModel.stopRecording', () {
|
||||
test('does not call native stop while switching lens', () async {
|
||||
final calls = <MethodCall>[];
|
||||
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
|
||||
.setMockMethodCallHandler(
|
||||
const MethodChannel(RecordingChannelNames.method),
|
||||
(call) async {
|
||||
calls.add(call);
|
||||
return <String, dynamic>{};
|
||||
},
|
||||
);
|
||||
final container = ProviderContainer();
|
||||
addTearDown(container.dispose);
|
||||
final notifier = container.read(recordingViewModelProvider.notifier);
|
||||
// ignore: invalid_use_of_protected_member
|
||||
notifier.state = container
|
||||
.read(recordingViewModelProvider)
|
||||
.copyWith(
|
||||
session: const RecordingSessionState(
|
||||
status: RecordingStatus(state: RecordingState.recording),
|
||||
isSwitchingLens: true,
|
||||
),
|
||||
);
|
||||
|
||||
await notifier.stopRecording();
|
||||
|
||||
expect(calls, isEmpty);
|
||||
});
|
||||
|
||||
test(
|
||||
'stores segment output paths when native save falls back to parts',
|
||||
() async {
|
||||
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
|
||||
.setMockMethodCallHandler(
|
||||
const MethodChannel(RecordingChannelNames.method),
|
||||
(call) async {
|
||||
switch (call.method) {
|
||||
case 'stopRecording':
|
||||
return <String, dynamic>{
|
||||
'outputPath': 'content://recordings/part1',
|
||||
'status': <String, dynamic>{
|
||||
'state': 'error',
|
||||
'message': 'Merge failed',
|
||||
},
|
||||
'fileSaved': false,
|
||||
'fileErrorMessage': 'Merge failed',
|
||||
'segmentOutputPaths': <String>[
|
||||
'content://recordings/part1',
|
||||
'content://recordings/part2',
|
||||
],
|
||||
};
|
||||
case 'initializePreview':
|
||||
return <String, dynamic>{'state': 'previewing'};
|
||||
case 'getZoomCapabilities':
|
||||
return <String, dynamic>{
|
||||
'zoomRatio': 1.0,
|
||||
'minZoomRatio': 1.0,
|
||||
'maxZoomRatio': 3.0,
|
||||
};
|
||||
}
|
||||
return <String, dynamic>{};
|
||||
},
|
||||
);
|
||||
final container = ProviderContainer();
|
||||
addTearDown(container.dispose);
|
||||
final notifier = container.read(recordingViewModelProvider.notifier);
|
||||
// ignore: invalid_use_of_protected_member
|
||||
notifier.state = container
|
||||
.read(recordingViewModelProvider)
|
||||
.copyWith(
|
||||
session: const RecordingSessionState(
|
||||
status: RecordingStatus(state: RecordingState.recording),
|
||||
),
|
||||
);
|
||||
|
||||
await notifier.stopRecording();
|
||||
|
||||
final session = container.read(recordingViewModelProvider).session;
|
||||
expect(session.fileSaveFailed, isTrue);
|
||||
expect(session.segmentOutputPaths, <String>[
|
||||
'content://recordings/part1',
|
||||
'content://recordings/part2',
|
||||
]);
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
group('recordingFileSavePermissionsForHost', () {
|
||||
|
||||
@@ -10,6 +10,8 @@ void main() {
|
||||
double minZoomRatio = 1.0,
|
||||
double maxZoomRatio = 3.0,
|
||||
bool isRecording = false,
|
||||
bool isSwitchingLens = false,
|
||||
Future<void> Function()? onStop,
|
||||
ValueChanged<double>? onZoomSelected,
|
||||
}) async {
|
||||
await tester.pumpWidget(
|
||||
@@ -25,12 +27,13 @@ void main() {
|
||||
notificationsGranted: true,
|
||||
isRecording: isRecording,
|
||||
isStartingRecording: false,
|
||||
isSwitchingLens: isSwitchingLens,
|
||||
isTouchLocked: false,
|
||||
zoomRatio: zoomRatio,
|
||||
minZoomRatio: minZoomRatio,
|
||||
maxZoomRatio: maxZoomRatio,
|
||||
onStart: () async {},
|
||||
onStop: () async {},
|
||||
onStop: onStop ?? () async {},
|
||||
onOpenDnd: () {},
|
||||
onOpenBattery: () {},
|
||||
onToggleTouchLock: () {},
|
||||
@@ -112,7 +115,7 @@ void main() {
|
||||
);
|
||||
|
||||
await tester.tap(find.text('0.5x'));
|
||||
await tester.pump();
|
||||
await tester.pump(const Duration(milliseconds: 350));
|
||||
|
||||
expect(selected, 0.5);
|
||||
});
|
||||
@@ -128,7 +131,7 @@ void main() {
|
||||
);
|
||||
|
||||
await tester.tap(find.text('0.6x'));
|
||||
await tester.pump();
|
||||
await tester.pump(const Duration(milliseconds: 350));
|
||||
|
||||
expect(selected, 0.6);
|
||||
});
|
||||
@@ -155,7 +158,7 @@ void main() {
|
||||
expect(mainButton.enabled, isFalse);
|
||||
|
||||
await tester.tap(find.text('0.6x'));
|
||||
await tester.pump();
|
||||
await tester.pump(const Duration(milliseconds: 350));
|
||||
|
||||
expect(selected, 0.6);
|
||||
});
|
||||
@@ -183,8 +186,45 @@ void main() {
|
||||
expect(mainButton.enabled, isTrue);
|
||||
|
||||
await tester.tap(find.text('1x'));
|
||||
await tester.pump();
|
||||
await tester.pump(const Duration(milliseconds: 350));
|
||||
|
||||
expect(selected, 1.0);
|
||||
});
|
||||
|
||||
testWidgets('disables stop button while switching lens', (tester) async {
|
||||
var stopped = false;
|
||||
await pumpHud(
|
||||
tester,
|
||||
minZoomRatio: 0.6,
|
||||
isRecording: true,
|
||||
isSwitchingLens: true,
|
||||
onStop: () async => stopped = true,
|
||||
);
|
||||
|
||||
await tester.tap(find.byType(GestureDetector).last);
|
||||
await tester.pump();
|
||||
|
||||
expect(stopped, isFalse);
|
||||
});
|
||||
|
||||
testWidgets('disables zoom buttons while switching lens', (tester) async {
|
||||
double? selected;
|
||||
await pumpHud(
|
||||
tester,
|
||||
minZoomRatio: 0.6,
|
||||
isRecording: true,
|
||||
isSwitchingLens: true,
|
||||
onZoomSelected: (ratio) => selected = ratio,
|
||||
);
|
||||
|
||||
final ultraWideButton = tester.widget<TextButton>(
|
||||
find.ancestor(of: find.text('0.6x'), matching: find.byType(TextButton)),
|
||||
);
|
||||
|
||||
expect(ultraWideButton.enabled, isFalse);
|
||||
await tester.tap(find.text('0.6x'));
|
||||
await tester.pump(const Duration(milliseconds: 350));
|
||||
|
||||
expect(selected, isNull);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user