fix: 使用点击序号防止双击误暂停
This commit is contained in:
1 parent
9ddd7fc833
commit
bbc759473c
7 files changed
+113
-61
No files matched your search
@@ -12,43 +12,67 @@ import '../support/fake_haptics.dart';
|
||||
import '../support/fake_interaction_repositories.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('quick double tap likes without pausing', (tester) async {
|
||||
final repository = FakeInteractionRepository();
|
||||
final haptics = FakeHaptics();
|
||||
final key = GlobalKey<_HarnessState>();
|
||||
await _pumpHarness(tester, repository, haptics, key);
|
||||
testWidgets('double tap within 320ms never pauses', (tester) async {
|
||||
for (final delay in [120, 250, 300]) {
|
||||
final repository = FakeInteractionRepository();
|
||||
final haptics = FakeHaptics();
|
||||
final key = GlobalKey<_HarnessState>();
|
||||
final clock = _TestClock();
|
||||
await _pumpHarness(tester, repository, haptics, key, clock);
|
||||
|
||||
final gesture = find.byKey(const Key('home-feed-gesture'));
|
||||
final center = tester.getCenter(gesture);
|
||||
final center = tester.getCenter(
|
||||
find.byKey(const Key('home-feed-gesture')),
|
||||
);
|
||||
await tester.tapAt(center);
|
||||
clock.advance(Duration(milliseconds: delay));
|
||||
await tester.pump(Duration(milliseconds: delay));
|
||||
await tester.tapAt(center);
|
||||
await tester.pump();
|
||||
clock.advance(const Duration(milliseconds: 500));
|
||||
await tester.pump(const Duration(milliseconds: 500));
|
||||
|
||||
await tester.tapAt(center);
|
||||
await tester.pump(const Duration(milliseconds: 100));
|
||||
await tester.tapAt(center);
|
||||
await tester.pump();
|
||||
await tester.pump(const Duration(milliseconds: 400));
|
||||
|
||||
expect(key.currentState!.pauseToggles, 0);
|
||||
expect(repository.likeTargets, hasLength(1));
|
||||
expect(haptics.lightImpacts, 1);
|
||||
expect(
|
||||
find.descendant(
|
||||
of: find.byKey(const Key('rail-like')),
|
||||
matching: find.byIcon(Icons.favorite_rounded),
|
||||
),
|
||||
findsOneWidget,
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(
|
||||
key.currentState!.pauseToggles,
|
||||
0,
|
||||
reason: 'double tap with $delay ms gap paused playback',
|
||||
);
|
||||
expect(repository.likeTargets, hasLength(1));
|
||||
expect(haptics.lightImpacts, 1);
|
||||
expect(
|
||||
find.descendant(
|
||||
of: find.byKey(const Key('rail-like')),
|
||||
matching: find.byIcon(Icons.favorite_rounded),
|
||||
),
|
||||
findsOneWidget,
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
});
|
||||
|
||||
testWidgets('single tap toggles playback after 300ms', (tester) async {
|
||||
testWidgets('taps 500ms apart toggle playback twice', (tester) async {
|
||||
final key = GlobalKey<_HarnessState>();
|
||||
await _pumpHarness(tester, FakeInteractionRepository(), FakeHaptics(), key);
|
||||
final clock = _TestClock();
|
||||
await _pumpHarness(
|
||||
tester,
|
||||
FakeInteractionRepository(),
|
||||
FakeHaptics(),
|
||||
key,
|
||||
clock,
|
||||
);
|
||||
|
||||
await tester.tapAt(
|
||||
tester.getCenter(find.byKey(const Key('home-feed-gesture'))),
|
||||
);
|
||||
await tester.pump(const Duration(milliseconds: 400));
|
||||
clock.advance(const Duration(milliseconds: 500));
|
||||
await tester.pump(const Duration(milliseconds: 500));
|
||||
expect(key.currentState!.pauseToggles, 1);
|
||||
|
||||
await tester.tapAt(
|
||||
tester.getCenter(find.byKey(const Key('home-feed-gesture'))),
|
||||
);
|
||||
clock.advance(const Duration(milliseconds: 500));
|
||||
await tester.pump(const Duration(milliseconds: 500));
|
||||
expect(key.currentState!.pauseToggles, 2);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -57,6 +81,7 @@ Future<void> _pumpHarness(
|
||||
FakeInteractionRepository repository,
|
||||
FakeHaptics haptics,
|
||||
GlobalKey<_HarnessState> key,
|
||||
_TestClock clock,
|
||||
) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
@@ -64,17 +89,28 @@ Future<void> _pumpHarness(
|
||||
locale: const Locale('en'),
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
home: _Harness(key: key, repository: repository, haptics: haptics),
|
||||
home: _Harness(
|
||||
key: key,
|
||||
repository: repository,
|
||||
haptics: haptics,
|
||||
clock: clock,
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
|
||||
class _Harness extends StatefulWidget {
|
||||
const _Harness({super.key, required this.repository, required this.haptics});
|
||||
const _Harness({
|
||||
super.key,
|
||||
required this.repository,
|
||||
required this.haptics,
|
||||
required this.clock,
|
||||
});
|
||||
|
||||
final FakeInteractionRepository repository;
|
||||
final FakeHaptics haptics;
|
||||
final _TestClock clock;
|
||||
|
||||
@override
|
||||
State<_Harness> createState() => _HarnessState();
|
||||
@@ -124,6 +160,7 @@ class _HarnessState extends State<_Harness> {
|
||||
boosting: false,
|
||||
onLike: () => _like(),
|
||||
onDoubleTapLike: (_) => _like(likeOnly: true),
|
||||
now: widget.clock.now,
|
||||
onSave: () {},
|
||||
onComments: () {},
|
||||
onShare: () {},
|
||||
@@ -139,3 +176,13 @@ class _HarnessState extends State<_Harness> {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _TestClock {
|
||||
DateTime _now = DateTime(2026, 10, 22, 12);
|
||||
|
||||
DateTime now() => _now;
|
||||
|
||||
void advance(Duration duration) {
|
||||
_now = _now.add(duration);
|
||||
}
|
||||
}
|
||||
@@ -1326,7 +1326,6 @@ class _SessionVideoSurface extends StatelessWidget {
|
||||
controller: video?.controller,
|
||||
videoUrl: video?.controller.dataSource ?? '',
|
||||
theater: false,
|
||||
onTap: () {},
|
||||
),
|
||||
);
|
||||
},
|
||||
|
||||
@@ -87,7 +87,6 @@ Future<VideoPlayerController> _pumpSurface(
|
||||
controller: controller,
|
||||
videoUrl: controller.dataSource,
|
||||
theater: false,
|
||||
onTap: () {},
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
Reference in new issue
Block a user