feat(app): 展示真实点赞与评论计数
This commit is contained in:
1 parent
7b927c794e
commit
dfc650456a
9 files changed
+123
-8
No files matched your search
@@ -42,6 +42,27 @@ void main() {
|
||||
model.dispose();
|
||||
});
|
||||
|
||||
test('should_expose_exact_count_only_when_last_page_is_loaded', () async {
|
||||
final repository = FakeCommentRepository(
|
||||
pages: [
|
||||
CommentPage(
|
||||
comments: [commentFixture(id: '2')],
|
||||
nextCursor: '2',
|
||||
hasMore: true,
|
||||
),
|
||||
CommentPage(comments: [commentFixture(id: '1')]),
|
||||
],
|
||||
);
|
||||
final model = controller(repository);
|
||||
|
||||
await model.load();
|
||||
expect(model.exactCount, isNull);
|
||||
|
||||
await model.loadMore();
|
||||
expect(model.exactCount, 2);
|
||||
model.dispose();
|
||||
});
|
||||
|
||||
test('should_use_server_content_and_pending_status_when_review_is_returned', () async {
|
||||
final repository = FakeCommentRepository(
|
||||
publishResult: commentFixture(
|
||||
|
||||
@@ -62,11 +62,13 @@ void main() {
|
||||
await _pumpSheet(tester, repository: repository);
|
||||
expect(find.text('Great episode'), findsOneWidget);
|
||||
expect(find.byKey(const Key('comment-list-load-more')), findsOneWidget);
|
||||
expect(find.byKey(const Key('comment-count-label')), findsNothing);
|
||||
|
||||
await tester.tap(find.byKey(const Key('comment-list-load-more')));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('Second page'), findsOneWidget);
|
||||
expect(find.text('Comments · 2'), findsOneWidget);
|
||||
expect(repository.pageCalls.last.cursor, '10');
|
||||
});
|
||||
|
||||
|
||||
@@ -147,6 +147,48 @@ void main() {
|
||||
'Fallback Drama',
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('should_show_server_like_count_when_count_is_available', (
|
||||
tester,
|
||||
) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: AppTheme.dark(),
|
||||
locale: const Locale('en'),
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
home: Builder(
|
||||
builder: (context) => Scaffold(
|
||||
body: HomeFeedOverlay(
|
||||
l10n: AppLocalizations.of(context)!,
|
||||
drama: _drama,
|
||||
episode: const Episode(
|
||||
id: 'count-episode',
|
||||
number: 1,
|
||||
title: 'Count Episode',
|
||||
isFree: true,
|
||||
),
|
||||
liked: true,
|
||||
likeCount: 128,
|
||||
saved: false,
|
||||
onLike: () {},
|
||||
onSave: () {},
|
||||
onComments: () {},
|
||||
onShare: () {},
|
||||
onEpisodes: () {},
|
||||
onDownload: () {},
|
||||
onClear: () {},
|
||||
onSearch: () {},
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byKey(const Key('rail-like-count')), findsOneWidget);
|
||||
expect(find.text('128'), findsOneWidget);
|
||||
});
|
||||
}
|
||||
|
||||
const _drama = Drama(
|
||||
|
||||
@@ -26,6 +26,23 @@ void main() {
|
||||
|
||||
expect(result.isSuccess, isTrue);
|
||||
expect(controller.isLiked('5'), isFalse);
|
||||
expect(controller.likeCount('5'), 0);
|
||||
controller.dispose();
|
||||
});
|
||||
|
||||
test('should_expose_latest_server_count_when_two_toggles_succeed', () async {
|
||||
final repository = FakeInteractionRepository(
|
||||
nextLikeResult: const LikeToggleResult(liked: true, count: 12),
|
||||
);
|
||||
final controller = InteractionController(repository);
|
||||
|
||||
await controller.toggleDramaLike('5');
|
||||
expect(controller.likeCount('5'), 12);
|
||||
|
||||
repository.nextLikeResult = const LikeToggleResult(liked: false, count: 11);
|
||||
await controller.toggleDramaLike('5');
|
||||
|
||||
expect(controller.likeCount('5'), 11);
|
||||
controller.dispose();
|
||||
});
|
||||
|
||||
@@ -55,6 +72,7 @@ void main() {
|
||||
controller.clear();
|
||||
|
||||
expect(controller.isLiked('5'), isFalse);
|
||||
expect(controller.likeCount('5'), isNull);
|
||||
controller.dispose();
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user