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

+57 -2
View File
@@ -9,12 +9,16 @@ import 'package:fruitshorts/pages/drama_detail/drama_detail_logic.dart';
import '../support/fake_watch_history.dart';
/// 详情页逻辑依赖:票据仓库 + 收藏控制器(测试里都是内存实现)。
DramaDetailLogic _logic(Drama drama, FakeWatchHistory history) =>
DramaDetailLogic _logic(
Drama drama,
FakeWatchHistory history, {
FavoriteController? favorites,
}) =>
DramaDetailLogic(
drama: drama,
history: history,
playback: FakePlaybackRepository(),
favorites: FavoriteController(InMemoryFavoriteRepository()),
favorites: favorites ?? FavoriteController(InMemoryFavoriteRepository()),
);
Drama _card(String id) => Drama(
@@ -98,4 +102,55 @@ void main() {
expect(logic.drama.episodes, hasLength(3));
logic.dispose();
});
test('should_adjust_favorite_count_only_after_successful_changes', () async {
final repository = InMemoryFavoriteRepository(cards: [_favoriteDrama]);
final favorites = FavoriteController(repository);
await favorites.load();
final logic = _logic(
_favoriteDrama,
FakeWatchHistory(),
favorites: favorites,
);
expect(logic.adjustedFavoriteCount, 2);
expect(await logic.toggleFavorite(), isTrue);
expect(logic.adjustedFavoriteCount, 3);
repository.failToggle = true;
expect(await logic.toggleFavorite(), isFalse);
expect(logic.adjustedFavoriteCount, 3);
repository.failToggle = false;
expect(await logic.toggleFavorite(), isTrue);
expect(logic.adjustedFavoriteCount, 2);
logic.dispose();
});
test('should_decrement_favorite_count_from_saved_state', () async {
final repository = InMemoryFavoriteRepository(
saved: {'favorite-detail'},
cards: [_favoriteDrama],
);
final favorites = FavoriteController(repository);
await favorites.load();
final logic = _logic(
_favoriteDrama,
FakeWatchHistory(),
favorites: favorites,
);
expect(await logic.toggleFavorite(), isTrue);
expect(logic.adjustedFavoriteCount, 1);
logic.dispose();
});
}
const _favoriteDrama = Drama(
id: 'favorite-detail',
title: 'Favorite detail',
synopsis: 'favorite count',
posterUrl: '/files/favorite-detail.jpg',
favoriteCount: 2,
detailLoaded: true,
);
@@ -140,11 +140,23 @@ void main() {
expect(decoration().color, AppColors.card);
expect((decoration().border! as Border).top.color, AppColors.blue);
expect(
tester
.widget<Text>(find.byKey(const Key('detail-stat-favorite-value')))
.data,
'3200 Favorite',
);
await tester.tap(find.byKey(const Key('detail-favorite')));
await tester.pumpAndSettle();
expect(decoration().color, AppColors.blue);
expect(
tester
.widget<Text>(find.byKey(const Key('detail-stat-favorite-value')))
.data,
'3201 Favorite',
);
expect(
find.descendant(
of: find.byKey(const Key('detail-favorite')),
@@ -152,6 +164,16 @@ void main() {
),
findsOneWidget,
);
await tester.tap(find.byKey(const Key('detail-favorite')));
await tester.pumpAndSettle();
expect(
tester
.widget<Text>(find.byKey(const Key('detail-stat-favorite-value')))
.data,
'3200 Favorite',
);
});
testWidgets('should_expand_synopsis_when_it_exceeds_three_lines', (