fix(player): 修复首次双击点赞状态刷新
This commit is contained in:
1 parent
978c309cd7
commit
1b50a73bfc
3 files changed
+165
-13
No files matched your search
@@ -5,6 +5,7 @@ import 'dart:async';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:shared_preferences_platform_interface/in_memory_shared_preferences_async.dart';
|
||||
import 'package:shared_preferences_platform_interface/shared_preferences_async_platform_interface.dart';
|
||||
|
||||
@@ -16,6 +17,7 @@ import 'package:fruitshorts/core/data/models/player_port.dart';
|
||||
import 'package:fruitshorts/core/data/repositories/favorite_repository.dart';
|
||||
import 'package:fruitshorts/core/data/repositories/playback_repository.dart';
|
||||
import 'package:fruitshorts/core/data/repositories/watch_history_repository.dart';
|
||||
import 'package:fruitshorts/core/data/services/interaction_controller.dart';
|
||||
import 'package:fruitshorts/core/data/services/playback_session.dart';
|
||||
import 'package:fruitshorts/core/data/services/video_player_port.dart';
|
||||
import 'package:fruitshorts/core/theme/app_colors.dart';
|
||||
@@ -655,7 +657,54 @@ void main() {
|
||||
expect(find.byKey(const Key('player-play-toggle')), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('should_double_tap_like_once_without_pausing_full_player', (
|
||||
testWidgets('should_like_once_on_first_home_feed_double_tap', (tester) async {
|
||||
SharedPreferencesAsyncPlatform.instance =
|
||||
InMemorySharedPreferencesAsync.withData({
|
||||
'auth.accessToken': 'test-access',
|
||||
'auth.refreshToken': 'test-refresh',
|
||||
'auth.user': '{"uid":"9","nickname":"Me","avatarUrl":""}',
|
||||
});
|
||||
final interactions = FakeInteractionRepository(
|
||||
nextLikeResult: const LikeToggleResult(liked: true, count: 23001),
|
||||
);
|
||||
await _pumpApp(tester, interactions: interactions);
|
||||
await tester.tap(find.byKey(const Key('tab-recommend')));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
final page = find.byKey(const Key('recommend-feed-player'));
|
||||
final logic = _pageLogic(tester, page);
|
||||
final episode = logic.queue.entryAt(logic.session.currentIndex).episode;
|
||||
final gesture = find.byKey(const Key('home-feed-gesture')).hitTestable();
|
||||
final position = tester.getCenter(gesture);
|
||||
final interactionController = Provider.of<InteractionController>(
|
||||
tester.element(gesture),
|
||||
listen: false,
|
||||
);
|
||||
|
||||
await tester.tapAt(position);
|
||||
await tester.tapAt(position);
|
||||
await tester.pump();
|
||||
await tester.pump();
|
||||
|
||||
expect(interactionController.isEpisodeLiked(episode.id), isTrue);
|
||||
expect(interactionController.episodeLikeCount(episode.id), 23001);
|
||||
expect(_railLabel(tester, const Key('rail-like')), '2.3万');
|
||||
expect(logic.session.userWantsPlay, isTrue);
|
||||
expect(interactions.likeTargets, ['EPISODE:${episode.id}']);
|
||||
|
||||
await _waitForDoubleTapWindow(tester);
|
||||
await tester.tapAt(position);
|
||||
await tester.tapAt(position);
|
||||
await tester.pump();
|
||||
await tester.pump();
|
||||
|
||||
expect(interactions.likeTargets, hasLength(1));
|
||||
expect(interactionController.episodeLikeCount(episode.id), 23001);
|
||||
expect(logic.session.userWantsPlay, isTrue);
|
||||
await _waitForHeartCompletion(tester);
|
||||
});
|
||||
|
||||
testWidgets('should_like_once_on_first_double_tap_without_pausing', (
|
||||
tester,
|
||||
) async {
|
||||
SharedPreferencesAsyncPlatform.instance =
|
||||
@@ -665,7 +714,7 @@ void main() {
|
||||
'auth.user': '{"uid":"9","nickname":"Me","avatarUrl":""}',
|
||||
});
|
||||
final interactions = FakeInteractionRepository(
|
||||
nextLikeResult: const LikeToggleResult(liked: true, count: 23000),
|
||||
nextLikeResult: const LikeToggleResult(liked: true, count: 23001),
|
||||
);
|
||||
await _pumpApp(tester, interactions: interactions);
|
||||
await _openSeriesPlayer(tester);
|
||||
@@ -673,18 +722,24 @@ void main() {
|
||||
final logic = _pageLogic(tester, find.byType(PlayerPage).last);
|
||||
final gesture = find.byKey(const Key('player-video-tap')).hitTestable();
|
||||
final position = tester.getCenter(gesture);
|
||||
final interactionController = Provider.of<InteractionController>(
|
||||
tester.element(gesture),
|
||||
listen: false,
|
||||
);
|
||||
expect(logic.session.userWantsPlay, isTrue);
|
||||
|
||||
for (var index = 0; index < 4; index++) {
|
||||
await tester.tapAt(position);
|
||||
}
|
||||
await tester.tapAt(position);
|
||||
await tester.tapAt(position);
|
||||
await tester.pump();
|
||||
await tester.pump();
|
||||
await tester.pump(const Duration(milliseconds: 300));
|
||||
await _waitForBufferedHeartFrames(tester);
|
||||
|
||||
expect(logic.session.userWantsPlay, isTrue);
|
||||
expect(find.byKey(const Key('player-play-toggle')), findsNothing);
|
||||
expect(interactions.likeTargets, ['EPISODE:city-lights-demo-1']);
|
||||
expect(interactionController.isEpisodeLiked('city-lights-demo-1'), isTrue);
|
||||
expect(interactionController.episodeLikeCount('city-lights-demo-1'), 23001);
|
||||
expect(_railLabel(tester, const Key('player-rail-like')), '2.3万');
|
||||
await _waitForBufferedHeartFrames(tester);
|
||||
for (var index = 0; index < 3; index++) {
|
||||
expect(find.byKey(Key('double-tap-heart-$index')), findsOneWidget);
|
||||
}
|
||||
@@ -700,6 +755,15 @@ void main() {
|
||||
AppColors.doubleTapHeartRed,
|
||||
);
|
||||
|
||||
await _waitForDoubleTapWindow(tester);
|
||||
await tester.tapAt(position);
|
||||
await tester.tapAt(position);
|
||||
await tester.pump();
|
||||
await tester.pump();
|
||||
|
||||
expect(interactions.likeTargets, hasLength(1));
|
||||
expect(interactionController.episodeLikeCount('city-lights-demo-1'), 23001);
|
||||
expect(logic.session.userWantsPlay, isTrue);
|
||||
await _waitForHeartCompletion(tester);
|
||||
expect(find.byKey(const Key('double-tap-heart-0')), findsNothing);
|
||||
expect(logic.session.userWantsPlay, isTrue);
|
||||
@@ -1827,6 +1891,13 @@ Future<void> _waitForBufferedHeartFrames(WidgetTester tester) async {
|
||||
await tester.pump(const Duration(milliseconds: 120));
|
||||
}
|
||||
|
||||
Future<void> _waitForDoubleTapWindow(WidgetTester tester) async {
|
||||
await tester.runAsync(
|
||||
() => Future<void>.delayed(const Duration(milliseconds: 360)),
|
||||
);
|
||||
await tester.pump();
|
||||
}
|
||||
|
||||
Future<void> _waitForHeartCompletion(WidgetTester tester) async {
|
||||
await tester.runAsync(
|
||||
() => Future<void>.delayed(const Duration(milliseconds: 1700)),
|
||||
@@ -1834,6 +1905,12 @@ Future<void> _waitForHeartCompletion(WidgetTester tester) async {
|
||||
await tester.pump(const Duration(milliseconds: 16));
|
||||
}
|
||||
|
||||
String _railLabel(WidgetTester tester, Key key) => tester
|
||||
.widget<Text>(
|
||||
find.descendant(of: find.byKey(key), matching: find.byType(Text)),
|
||||
)
|
||||
.data!;
|
||||
|
||||
Future<void> _openSeriesPlayer(
|
||||
WidgetTester tester, {
|
||||
Key cardKey = const Key('home-feed-card-city-lights-demo'),
|
||||
|
||||
Reference in new issue
Block a user