fix(player): 评论总数含回复并改用相对时间
This commit is contained in:
1 parent
22cb74ded4
commit
2659c29501
14 files changed
+212
-9
No files matched your search
@@ -142,6 +142,45 @@ void main() {
|
||||
expect(repository.pageCalls.last.cursor, '10');
|
||||
});
|
||||
|
||||
testWidgets('should_show_server_total_that_includes_replies', (tester) async {
|
||||
final repository = FakeCommentRepository(
|
||||
pages: [
|
||||
CommentPage(
|
||||
comments: [
|
||||
commentFixture(id: '10', content: 'Root one'),
|
||||
commentFixture(id: '11', content: 'Root two'),
|
||||
],
|
||||
),
|
||||
],
|
||||
countResult: 9,
|
||||
);
|
||||
|
||||
await _pumpSheet(tester, repository: repository);
|
||||
|
||||
expect(find.text('9 comments'), findsOneWidget);
|
||||
expect(repository.countCalls, ['5']);
|
||||
});
|
||||
|
||||
testWidgets('should_fall_back_to_exact_count_when_server_total_fails', (
|
||||
tester,
|
||||
) async {
|
||||
final repository = FakeCommentRepository(
|
||||
pages: [
|
||||
CommentPage(
|
||||
comments: [
|
||||
commentFixture(id: '10', content: 'Root one'),
|
||||
commentFixture(id: '11', content: 'Root two'),
|
||||
],
|
||||
),
|
||||
],
|
||||
countError: StateError('offline'),
|
||||
);
|
||||
|
||||
await _pumpSheet(tester, repository: repository);
|
||||
|
||||
expect(find.text('2 comments'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('should_show_compact_empty_state_when_no_comments_exist', (
|
||||
tester,
|
||||
) async {
|
||||
@@ -185,6 +224,7 @@ void main() {
|
||||
final repository = FakeCommentRepository(
|
||||
pages: [const CommentPage()],
|
||||
publishResult: commentFixture(id: '11', content: 'Nice demo', mine: true),
|
||||
countResult: 1,
|
||||
);
|
||||
|
||||
await _pumpSheet(tester, repository: repository);
|
||||
@@ -197,6 +237,7 @@ void main() {
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(tester.widget<TextField>(input).focusNode?.hasFocus, isFalse);
|
||||
expect(repository.countCalls, ['5', '5']);
|
||||
});
|
||||
|
||||
testWidgets('should_use_polished_comment_sizes', (tester) async {
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
// Author: fruit.com.cn
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:fruitshorts/core/formatting/relative_date_time.dart';
|
||||
import 'package:fruitshorts/l10n/app_localizations_en.dart';
|
||||
|
||||
void main() {
|
||||
final l10n = AppLocalizationsEn();
|
||||
final now = DateTime(2026, 10, 21, 12);
|
||||
|
||||
test('should_show_just_now_under_one_minute', () {
|
||||
expect(
|
||||
formatRelativeDateTime(
|
||||
now.subtract(const Duration(seconds: 59)),
|
||||
l10n,
|
||||
now: now,
|
||||
),
|
||||
'Just now',
|
||||
);
|
||||
});
|
||||
|
||||
test('should_use_minutes_below_sixty_minutes', () {
|
||||
expect(
|
||||
formatRelativeDateTime(
|
||||
now.subtract(const Duration(minutes: 59)),
|
||||
l10n,
|
||||
now: now,
|
||||
),
|
||||
'59 min ago',
|
||||
);
|
||||
});
|
||||
|
||||
test('should_use_hours_below_twenty_four_hours', () {
|
||||
expect(
|
||||
formatRelativeDateTime(
|
||||
now.subtract(const Duration(hours: 23)),
|
||||
l10n,
|
||||
now: now,
|
||||
),
|
||||
'23 hours ago',
|
||||
);
|
||||
});
|
||||
|
||||
test('should_use_month_and_day_for_same_year', () {
|
||||
expect(
|
||||
formatRelativeDateTime(DateTime(2026, 9, 3), l10n, now: now),
|
||||
'09-03',
|
||||
);
|
||||
});
|
||||
|
||||
test('should_use_full_date_for_previous_year', () {
|
||||
expect(
|
||||
formatRelativeDateTime(DateTime(2025, 12, 31), l10n, now: now),
|
||||
'2025-12-31',
|
||||
);
|
||||
});
|
||||
}
|
||||
@@ -198,11 +198,12 @@ void main() {
|
||||
await tester.tap(find.byKey(const Key('player-rail-comments')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byKey(const Key('player-comments-sheet')), findsOneWidget);
|
||||
expect(find.text('97 comments'), findsOneWidget);
|
||||
|
||||
await tester.binding.handlePopRoute();
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(comments.countCalls, ['city-lights-demo']);
|
||||
expect(comments.countCalls, ['city-lights-demo', 'city-lights-demo']);
|
||||
expect(
|
||||
tester
|
||||
.widget<Text>(find.byKey(const Key('player-rail-comments-count')))
|
||||
|
||||
@@ -42,7 +42,7 @@ class FakeCommentRepository implements CommentRepository {
|
||||
this.publishError,
|
||||
this.deleteError,
|
||||
this.pageError,
|
||||
this.countResult = 0,
|
||||
this.countResult,
|
||||
this.countError,
|
||||
}) : pages = pages ?? const [];
|
||||
|
||||
@@ -51,7 +51,7 @@ class FakeCommentRepository implements CommentRepository {
|
||||
final Object? publishError;
|
||||
final Object? deleteError;
|
||||
final Object? pageError;
|
||||
final int countResult;
|
||||
final int? countResult;
|
||||
final Object? countError;
|
||||
final List<CommentPageCall> pageCalls = [];
|
||||
final List<PublishCall> publishCalls = [];
|
||||
@@ -85,7 +85,9 @@ class FakeCommentRepository implements CommentRepository {
|
||||
countCalls.add(dramaId);
|
||||
final error = countError;
|
||||
if (error != null) throw error;
|
||||
return countResult;
|
||||
final result = countResult;
|
||||
if (result == null) throw StateError('comment count unavailable');
|
||||
return result;
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
Reference in new issue
Block a user