feat(flutter): 增加关键操作震动反馈

This commit is contained in:
Zhou Weidong committed 2026-10-17 16:15:46 +08:00
1 parent e609e3ad8d
commit 8a481d5c62
20 files changed
+308 -72

No files matched your search

+41 -34
View File
@@ -11,6 +11,7 @@ import 'package:fruitshorts/core/data/repositories/comment_repository.dart';
import 'package:fruitshorts/core/data/repositories/interaction_repository.dart';
import 'package:fruitshorts/core/data/services/auth_controller.dart';
import 'package:fruitshorts/core/data/services/auth_session_store.dart';
import 'package:fruitshorts/core/platform/haptics.dart';
import 'package:fruitshorts/l10n/app_localizations.dart';
import 'package:fruitshorts/pages/player/widgets/drama_comments_sheet.dart';
import 'package:provider/provider.dart';
@@ -18,6 +19,7 @@ import 'package:shared_preferences_platform_interface/in_memory_shared_preferenc
import 'package:shared_preferences_platform_interface/shared_preferences_async_platform_interface.dart';
import '../support/fake_http_adapter.dart';
import '../support/fake_haptics.dart';
import '../support/fake_interaction_repositories.dart';
const _drama = Drama(
@@ -66,28 +68,29 @@ void main() {
expect(repository.pageCalls.last.cursor, '10');
});
testWidgets('should_keep_input_and_show_backend_message_when_comment_is_blocked', (
tester,
) async {
final repository = FakeCommentRepository(
pages: [const CommentPage()],
publishError: const ApiException(400, '评论包含敏感词'),
);
testWidgets(
'should_keep_input_and_show_backend_message_when_comment_is_blocked',
(tester) async {
final repository = FakeCommentRepository(
pages: [const CommentPage()],
publishError: const ApiException(400, '评论包含敏感词'),
);
await _pumpSheet(tester, repository: repository);
await tester.enterText(
find.byKey(const Key('comment-input')),
'blocked text',
);
await tester.tap(find.byKey(const Key('comment-post')));
await tester.pumpAndSettle();
await _pumpSheet(tester, repository: repository);
await tester.enterText(
find.byKey(const Key('comment-input')),
'blocked text',
);
await tester.tap(find.byKey(const Key('comment-post')));
await tester.pumpAndSettle();
expect(find.text('评论包含敏感词'), findsOneWidget);
final field = tester.widget<TextField>(
find.byKey(const Key('comment-input')),
);
expect(field.controller?.text, 'blocked text');
});
expect(find.text('评论包含敏感词'), findsOneWidget);
final field = tester.widget<TextField>(
find.byKey(const Key('comment-input')),
);
expect(field.controller?.text, 'blocked text');
},
);
testWidgets('should_show_review_badge_and_server_replaced_content', (
tester,
@@ -101,8 +104,9 @@ void main() {
mine: true,
),
);
final haptics = FakeHaptics();
await _pumpSheet(tester, repository: repository);
await _pumpSheet(tester, repository: repository, haptics: haptics);
await tester.enterText(
find.byKey(const Key('comment-input')),
'hello badword',
@@ -112,6 +116,7 @@ void main() {
expect(find.text('hello ***'), findsOneWidget);
expect(find.text('Under review'), findsOneWidget);
expect(haptics.lightImpacts, 1);
final field = tester.widget<TextField>(
find.byKey(const Key('comment-input')),
);
@@ -139,10 +144,7 @@ void main() {
await tester.tap(find.byKey(const Key('comment-reply-10')));
await tester.pump();
expect(find.textContaining('Replying to'), findsOneWidget);
await tester.enterText(
find.byKey(const Key('comment-input')),
'My reply',
);
await tester.enterText(find.byKey(const Key('comment-input')), 'My reply');
await tester.tap(find.byKey(const Key('comment-post')));
await tester.pumpAndSettle();
@@ -153,9 +155,7 @@ void main() {
testWidgets('should_show_error_and_retry_when_comment_page_fails', (
tester,
) async {
final repository = FakeCommentRepository(
pageError: StateError('offline'),
);
final repository = FakeCommentRepository(pageError: StateError('offline'));
await _pumpSheet(tester, repository: repository);
@@ -175,16 +175,19 @@ void main() {
);
final interactions = FakeInteractionRepository()
..nextLikeResult = const LikeToggleResult(liked: true, count: 7);
final haptics = FakeHaptics();
await _pumpSheet(
tester,
repository: repository,
interactions: interactions,
haptics: haptics,
);
await tester.tap(find.byKey(const Key('comment-like-10')));
await tester.pumpAndSettle();
expect(interactions.likeTargets, ['COMMENT:10']);
expect(haptics.lightImpacts, 1);
expect(find.text('7'), findsOneWidget);
});
@@ -199,11 +202,13 @@ void main() {
],
);
final interactions = FakeInteractionRepository();
final haptics = FakeHaptics();
await _pumpSheet(
tester,
repository: repository,
interactions: interactions,
haptics: haptics,
);
await tester.tap(find.byKey(const Key('comment-menu-10')));
await tester.pumpAndSettle();
@@ -212,9 +217,13 @@ void main() {
await tester.tap(find.byKey(const Key('report-submit')));
await tester.pumpAndSettle();
expect(interactions.reports.single.targetType, InteractionTargetType.comment);
expect(
interactions.reports.single.targetType,
InteractionTargetType.comment,
);
expect(interactions.reports.single.targetId, '10');
expect(interactions.reports.single.reasonCode, 'SPAM');
expect(haptics.lightImpacts, 1);
expect(find.text('Report submitted. Thank you.'), findsOneWidget);
});
@@ -281,11 +290,7 @@ void main() {
pages: [
CommentPage(
comments: [
commentFixture(
id: '10',
content: 'My comment',
mine: true,
),
commentFixture(id: '10', content: 'My comment', mine: true),
],
),
],
@@ -315,6 +320,7 @@ Future<void> _pumpSheet(
WidgetTester tester, {
required FakeCommentRepository repository,
FakeInteractionRepository? interactions,
FakeHaptics? haptics,
}) async {
final auth = await _auth();
await tester.pumpWidget(
@@ -325,6 +331,7 @@ Future<void> _pumpSheet(
value: interactions ?? FakeInteractionRepository(),
),
ChangeNotifierProvider<AuthController>.value(value: auth),
Provider<Haptics>.value(value: haptics ?? FakeHaptics()),
],
child: MaterialApp(
locale: const Locale('en'),