fix(player): 收藏与评论数实时刷新

This commit is contained in:
Zhou Weidong committed 2026-10-21 11:39:58 +08:00
1 parent 97bbced02c
commit 5e2b8d9e4d
11 files changed
+275 -29

No files matched your search

+85 -1
View File
@@ -175,6 +175,68 @@ void main() {
expect(find.byKey(const Key('player-comments-sheet')), findsOneWidget);
});
testWidgets('should_refresh_comment_count_after_comment_sheet_closes', (
tester,
) async {
SharedPreferencesAsyncPlatform.instance =
InMemorySharedPreferencesAsync.withData({
'auth.accessToken': 'access',
'auth.refreshToken': 'refresh',
'auth.user': '{"uid":"9","nickname":"Viewer","avatarUrl":""}',
});
final comments = FakeCommentRepository(countResult: 97);
await _pumpApp(tester, commentRepository: comments);
await _openSeriesPlayer(tester);
expect(
tester
.widget<Text>(find.byKey(const Key('player-rail-comments-count')))
.data,
'96',
);
await tester.tap(find.byKey(const Key('player-rail-comments')));
await tester.pumpAndSettle();
expect(find.byKey(const Key('player-comments-sheet')), findsOneWidget);
await tester.binding.handlePopRoute();
await tester.pumpAndSettle();
expect(comments.countCalls, ['city-lights-demo']);
expect(
tester
.widget<Text>(find.byKey(const Key('player-rail-comments-count')))
.data,
'97',
);
});
testWidgets('should_update_home_feed_favorite_count_after_toggle', (
tester,
) async {
SharedPreferencesAsyncPlatform.instance =
InMemorySharedPreferencesAsync.withData({
'auth.accessToken': 'access',
'auth.refreshToken': 'refresh',
'auth.user': '{"uid":"9","nickname":"Viewer","avatarUrl":""}',
});
final catalog = FakeCatalogRepository(dramas: [_countingDrama]);
await _pumpApp(tester, catalog: catalog);
expect(
tester.widget<Text>(find.byKey(const Key('rail-save-count'))).data,
'2',
);
await tester.tap(find.byKey(const Key('rail-save')));
await tester.pumpAndSettle();
expect(
tester.widget<Text>(find.byKey(const Key('rail-save-count'))).data,
'3',
);
});
testWidgets('should_show_center_toggle_only_when_paused', (tester) async {
await _pumpApp(tester);
await _openSeriesPlayer(tester);
@@ -1211,6 +1273,7 @@ Future<void> _pumpApp(
FakeCatalogRepository? catalog,
FakePlaybackRepository? playback,
FakeInteractionRepository? interactions,
FakeCommentRepository? commentRepository,
PlayerFactory? playerFactory,
}) async {
tester.view.physicalSize = size;
@@ -1226,7 +1289,7 @@ Future<void> _pumpApp(
watchHistoryRepository: InMemoryWatchHistoryRepository(),
favoriteRepository: InMemoryFavoriteRepository(cards: repository.dramas),
playbackRepository: playback ?? FakePlaybackRepository(),
commentRepository: FakeCommentRepository(),
commentRepository: commentRepository ?? FakeCommentRepository(),
interactionRepository: interactions ?? FakeInteractionRepository(),
noticeRepository: FakeNoticeRepository(),
haptics: FakeHaptics(),
@@ -1235,6 +1298,27 @@ Future<void> _pumpApp(
await tester.pumpAndSettle();
}
const _countingDrama = Drama(
id: 'counting-demo',
title: 'Counting Demo',
synopsis: 'Counting interaction totals',
posterUrl: '/files/counting-demo.png',
genre: 'Romance',
detailLoaded: true,
favoriteCount: 2,
commentCount: 3,
likeCount: 4,
episodes: [
Episode(
id: 'counting-demo-1',
number: 1,
title: 'Episode 1',
isFree: true,
videoUrl: 'https://example.test/counting-1.mp4',
),
],
);
class _RecordingPlayer implements PlayerPort {
bool playing = false;