fix(player): 评论聚焦态改为展开输入面板

This commit is contained in:
Zhou Weidong committed 2026-10-21 12:21:17 +08:00
1 parent 8b51a7c18e
commit 519cab20fe
3 files changed
+225 -6

No files matched your search

+94 -2
View File
@@ -220,7 +220,9 @@ void main() {
},
);
testWidgets('should_unfocus_input_after_successful_post', (tester) async {
testWidgets('should_clear_and_keep_input_focused_after_successful_post', (
tester,
) async {
final repository = FakeCommentRepository(
pages: [const CommentPage()],
publishResult: commentFixture(id: '11', content: 'Nice demo', mine: true),
@@ -233,13 +235,98 @@ void main() {
await tester.pump();
expect(tester.widget<TextField>(input).focusNode?.hasFocus, isTrue);
await tester.enterText(input, 'Nice demo');
await tester.pump();
expect(
tester
.widget<TextButton>(find.byKey(const Key('comment-post')))
.onPressed,
isNotNull,
);
await tester.tap(find.byKey(const Key('comment-post')));
await tester.pumpAndSettle();
expect(tester.widget<TextField>(input).focusNode?.hasFocus, isFalse);
expect(tester.widget<TextField>(input).controller?.text, isEmpty);
expect(tester.widget<TextField>(input).focusNode?.hasFocus, isTrue);
expect(find.byKey(const Key('comment-expanded-composer')), findsOneWidget);
expect(find.byKey(const Key('comment-list')), findsNothing);
expect(
tester
.widget<TextButton>(find.byKey(const Key('comment-post')))
.onPressed,
isNull,
);
expect(repository.countCalls, ['5', '5']);
});
testWidgets('should_expand_composer_only_while_input_is_focused', (
tester,
) async {
tester.view.physicalSize = const Size(390, 844);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.resetPhysicalSize);
addTearDown(tester.view.resetDevicePixelRatio);
addTearDown(tester.view.resetViewInsets);
final repository = FakeCommentRepository(
pages: [
CommentPage(
comments: [commentFixture(id: '10', content: 'A comment')],
),
],
);
await _pumpSheet(tester, repository: repository);
expect(find.byKey(const Key('comment-list')), findsOneWidget);
await tester.tap(find.byKey(const Key('comment-input')));
await tester.pumpAndSettle();
expect(find.byKey(const Key('comment-list')), findsNothing);
expect(find.byKey(const Key('comment-count-label')), findsNothing);
expect(find.byKey(const Key('comment-composer')), findsNothing);
expect(find.byKey(const Key('comment-expanded-composer')), findsOneWidget);
final field = tester.widget<TextField>(
find.byKey(const Key('comment-input')),
);
expect(field.minLines, 1);
expect(field.maxLines, 4);
expect(field.style?.fontSize, 15);
expect(
tester
.widget<TextButton>(find.byKey(const Key('comment-post')))
.onPressed,
isNull,
);
expect(tester.getSize(find.byKey(const Key('comment-post'))).height, 32);
expect(find.byType(IconButton), findsNothing);
expect(find.byIcon(Icons.image_outlined), findsNothing);
expect(find.byIcon(Icons.emoji_emotions_outlined), findsNothing);
expect(find.byIcon(Icons.alternate_email_rounded), findsNothing);
await tester.enterText(find.byKey(const Key('comment-input')), 'Nice');
await tester.pump();
expect(
tester
.widget<TextButton>(find.byKey(const Key('comment-post')))
.onPressed,
isNotNull,
);
tester.view.viewInsets = const FakeViewPadding(bottom: 180);
await tester.pump();
await tester.pump(const Duration(milliseconds: 160));
expect(
tester.getBottomLeft(find.byKey(const Key('player-comments-sheet'))).dy,
closeTo(844 - 180, 0.1),
);
tester.view.viewInsets = const FakeViewPadding();
FocusManager.instance.primaryFocus?.unfocus();
await tester.pumpAndSettle();
expect(find.byKey(const Key('comment-expanded-composer')), findsNothing);
expect(find.byKey(const Key('comment-list')), findsOneWidget);
expect(find.byKey(const Key('comment-composer')), findsOneWidget);
});
testWidgets('should_use_polished_comment_sizes', (tester) async {
final repository = FakeCommentRepository(
pages: [
@@ -457,6 +544,8 @@ void main() {
await tester.tap(find.byKey(const Key('comment-post')));
await tester.pumpAndSettle();
FocusManager.instance.primaryFocus?.unfocus();
await tester.pumpAndSettle();
expect(find.text('hello ***'), findsOneWidget);
expect(find.text('Under review'), findsOneWidget);
expect(haptics.lightImpacts, 1);
@@ -488,10 +577,13 @@ void main() {
await tester.pump();
expect(find.textContaining('Replying to'), findsOneWidget);
await tester.enterText(find.byKey(const Key('comment-input')), 'My reply');
await tester.pump();
await tester.tap(find.byKey(const Key('comment-post')));
await tester.pumpAndSettle();
expect(repository.publishCalls.single.parentId, '10');
FocusManager.instance.primaryFocus?.unfocus();
await tester.pumpAndSettle();
expect(find.text('My reply'), findsOneWidget);
});
+3
View File
@@ -249,8 +249,11 @@ void main() {
await tester.pumpAndSettle();
expect(find.text('No comments yet.'), findsOneWidget);
await tester.enterText(find.byKey(const Key('comment-input')), 'Nice demo');
await tester.pump();
await tester.tap(find.byKey(const Key('comment-post')));
await tester.pumpAndSettle();
FocusManager.instance.primaryFocus?.unfocus();
await tester.pumpAndSettle();
expect(find.text('Nice demo'), findsOneWidget);
await tester.binding.handlePopRoute();
await tester.pumpAndSettle();