fix(player): 评论入口改为假输入框点击唤起

This commit is contained in:
Zhou Weidong committed 2026-10-21 13:12:30 +08:00
1 parent a142a6c318
commit 425ea4c0b7
3 files changed
+236 -176

No files matched your search

+73 -45
View File
@@ -48,12 +48,14 @@ void main() {
final repository = FakeCommentRepository(pages: [const CommentPage()]);
await _pumpSheet(tester, repository: repository);
final input = find.byKey(const Key('comment-input'));
final field = tester.widget<TextField>(input);
final input = find.byKey(const Key('comment-input'), skipOffstage: false);
final placeholder = find.byKey(const Key('comment-input-placeholder'));
expect(field.decoration?.hintText, 'Sign in to comment');
expect(field.focusNode?.hasFocus, isFalse);
await tester.tap(input);
expect(placeholder, findsOneWidget);
expect(find.byKey(const Key('comment-input')), findsNothing);
expect(find.text('Sign in to comment'), findsOneWidget);
expect(tester.widget<TextField>(input).focusNode?.hasFocus, isFalse);
await tester.tap(placeholder);
await tester.pumpAndSettle();
expect(find.text('Sign in to continue'), findsOneWidget);
@@ -71,7 +73,7 @@ void main() {
final repository = FakeCommentRepository(pages: [const CommentPage()]);
final auth = await _pumpSheet(tester, repository: repository);
await tester.tap(find.byKey(const Key('comment-input')));
await tester.tap(find.byKey(const Key('comment-input-placeholder')));
await tester.pump();
await tester.pump(const Duration(milliseconds: 300));
await tester.tap(find.text('Sign In'));
@@ -92,6 +94,23 @@ void main() {
);
});
testWidgets('should_focus_real_input_when_fake_send_is_tapped', (
tester,
) async {
final repository = FakeCommentRepository(pages: [const CommentPage()]);
await _pumpSheet(tester, repository: repository);
expect(find.byKey(const Key('comment-input')), findsNothing);
await tester.tap(find.byKey(const Key('comment-post')));
await tester.pumpAndSettle();
expect(find.byKey(const Key('comment-input-placeholder')), findsNothing);
final input = find.byKey(const Key('comment-input'));
expect(input, findsOneWidget);
expect(tester.widget<TextField>(input).focusNode?.hasFocus, isTrue);
});
testWidgets('should_gate_guest_post_without_creating_comment', (
tester,
) async {
@@ -202,10 +221,13 @@ void main() {
);
await _pumpSheet(tester, repository: repository);
await tester.tap(find.byKey(const Key('comment-input-placeholder')));
await tester.pumpAndSettle();
await tester.enterText(
find.byKey(const Key('comment-input')),
'blocked text',
);
await tester.pump();
await tester.tap(find.byKey(const Key('comment-post')));
await tester.pumpAndSettle();
@@ -232,7 +254,7 @@ void main() {
await _pumpSheet(tester, repository: repository);
final input = find.byKey(const Key('comment-input'));
tester.view.viewInsets = const FakeViewPadding(bottom: 180);
await tester.tap(input);
await tester.tap(find.byKey(const Key('comment-input-placeholder')));
await tester.pumpAndSettle();
expect(tester.widget<TextField>(input).focusNode?.hasFocus, isTrue);
await tester.enterText(input, 'Nice demo');
@@ -278,25 +300,36 @@ void main() {
await _pumpSheet(tester, repository: repository);
expect(find.byKey(const Key('comment-list')), findsOneWidget);
expect(find.byKey(const Key('comment-input')), findsNothing);
expect(find.byKey(const Key('comment-input-placeholder')), findsOneWidget);
final hiddenInput = find.byKey(
const Key('comment-input'),
skipOffstage: false,
);
final editableBefore = tester.state<EditableTextState>(
find.descendant(
of: find.byKey(const Key('comment-input')),
matching: find.byType(EditableText),
of: hiddenInput,
matching: find.byType(EditableText, skipOffstage: false),
skipOffstage: false,
),
);
await tester.tap(find.byKey(const Key('comment-input')));
final sheet = find.byKey(const Key('player-comments-sheet'));
final list = find.byKey(const Key('comment-list'));
final heightBeforeKeyboard = tester.getSize(sheet).height;
tester.view.viewInsets = const FakeViewPadding(bottom: 180);
await tester.tap(find.byKey(const Key('comment-input-placeholder')));
await tester.pumpAndSettle();
expect(find.byKey(const Key('comment-list')), findsOneWidget);
expect(find.byKey(const Key('comment-count-label')), findsOneWidget);
expect(find.byKey(const Key('comment-composer')), findsOneWidget);
expect(find.byKey(const Key('comment-input-surface')), findsOneWidget);
expect(find.byKey(const Key('comment-input-placeholder')), findsNothing);
expect(
tester.widget<TextField>(find.byKey(const Key('comment-input'))).maxLines,
1,
4,
);
expect(tester.getSize(find.byKey(const Key('comment-input'))).height, 44);
final editableAfter = tester.state<EditableTextState>(
find.descendant(
of: find.byKey(const Key('comment-input')),
@@ -305,13 +338,6 @@ void main() {
);
expect(identical(editableBefore, editableAfter), isTrue);
final sheet = find.byKey(const Key('player-comments-sheet'));
final list = find.byKey(const Key('comment-list'));
final heightBeforeKeyboard = tester.getSize(sheet).height;
tester.view.viewInsets = const FakeViewPadding(bottom: 180);
await tester.pump();
await tester.pump(const Duration(milliseconds: 200));
expect(sheet, findsOneWidget);
expect(list, findsOneWidget);
expect(tester.getSize(sheet).height, closeTo(heightBeforeKeyboard, 0.1));
@@ -370,39 +396,28 @@ void main() {
isTrue,
);
await tester.tapAt(const Offset(20, 20));
await tester.pump();
expect(tester.widget<TextField>(hiddenInput).focusNode?.hasFocus, isFalse);
tester.view.viewInsets = const FakeViewPadding();
await tester.pumpAndSettle();
expect(list, findsOneWidget);
expect(find.byKey(const Key('comment-count-label')), findsOneWidget);
expect(find.byKey(const Key('comment-composer')), findsOneWidget);
final collapsedField = tester.widget<TextField>(
find.byKey(const Key('comment-input')),
);
expect(collapsedField.maxLines, 1);
expect(tester.getSize(find.byKey(const Key('comment-input'))).height, 44);
expect(find.byKey(const Key('comment-input-placeholder')), findsOneWidget);
expect(find.byKey(const Key('comment-input')), findsNothing);
expect(tester.getSize(sheet).height, closeTo(heightBeforeKeyboard, 0.1));
expect(tester.getSize(sheet).height, lessThan(520));
final editableAfterKeyboard = tester.state<EditableTextState>(
find.descendant(
of: find.byKey(const Key('comment-input')),
matching: find.byType(EditableText),
of: hiddenInput,
matching: find.byType(EditableText, skipOffstage: false),
skipOffstage: false,
),
);
expect(identical(editableAfter, editableAfterKeyboard), isTrue);
expect(
tester
.widget<TextField>(find.byKey(const Key('comment-input')))
.controller
?.text,
'Nice',
);
expect(
tester
.widget<TextField>(find.byKey(const Key('comment-input')))
.focusNode
?.hasFocus,
isTrue,
);
expect(tester.widget<TextField>(hiddenInput).controller?.text, 'Nice');
expect(tester.widget<TextField>(hiddenInput).focusNode?.hasFocus, isFalse);
});
testWidgets('should_dismiss_from_outside_in_two_steps', (tester) async {
@@ -422,15 +437,20 @@ void main() {
await _pumpSheet(tester, repository: repository);
final sheet = find.byKey(const Key('player-comments-sheet'));
final input = find.byKey(const Key('comment-input'));
final hiddenInput = find.byKey(
const Key('comment-input'),
skipOffstage: false,
);
expect(
find.byKey(const Key('player-comments-dismiss-layer')),
findsOneWidget,
);
tester.view.viewInsets = const FakeViewPadding(bottom: 180);
await tester.tap(input);
await tester.tap(find.byKey(const Key('comment-input-placeholder')));
await tester.pumpAndSettle();
expect(sheet, findsOneWidget);
expect(input, findsOneWidget);
expect(tester.widget<TextField>(input).focusNode?.hasFocus, isTrue);
await tester.tap(find.byKey(const Key('comment-list')));
@@ -440,7 +460,9 @@ void main() {
await tester.tapAt(const Offset(20, 20));
await tester.pump();
expect(sheet, findsOneWidget);
expect(tester.widget<TextField>(input).focusNode?.hasFocus, isFalse);
expect(tester.widget<TextField>(hiddenInput).focusNode?.hasFocus, isFalse);
expect(find.byKey(const Key('comment-input-placeholder')), findsOneWidget);
expect(input, findsNothing);
tester.view.viewInsets = const FakeViewPadding();
await tester.pumpAndSettle();
@@ -466,7 +488,10 @@ void main() {
tester.getSize(find.byKey(const Key('comment-post'))),
const Size(38, 38),
);
expect(tester.getSize(find.byKey(const Key('comment-input'))).height, 44);
expect(
tester.getSize(find.byKey(const Key('comment-input-placeholder'))).height,
44,
);
expect(find.byKey(const Key('player-comments-drag-handle')), findsNothing);
expect(
tester.getSize(find.byKey(const Key('player-comments-close'))),
@@ -502,7 +527,7 @@ void main() {
expect(body.style?.fontSize, 16);
expect(body.style?.height, 1.4);
final composer = tester.widget<Container>(
find.byKey(const Key('comment-composer')),
find.byKey(const Key('comment-input-placeholder')),
);
final decoration = composer.decoration! as BoxDecoration;
expect(decoration.color, AppColors.commentInput);
@@ -655,10 +680,13 @@ void main() {
final haptics = FakeHaptics();
await _pumpSheet(tester, repository: repository, haptics: haptics);
await tester.tap(find.byKey(const Key('comment-input-placeholder')));
await tester.pumpAndSettle();
await tester.enterText(
find.byKey(const Key('comment-input')),
'hello badword',
);
await tester.pump();
await tester.tap(find.byKey(const Key('comment-post')));
await tester.pumpAndSettle();
@@ -668,7 +696,7 @@ void main() {
expect(find.text('Under review'), findsOneWidget);
expect(haptics.lightImpacts, 1);
final field = tester.widget<TextField>(
find.byKey(const Key('comment-input')),
find.byKey(const Key('comment-input'), skipOffstage: false),
);
expect(field.controller?.text, isEmpty);
});
+2
View File
@@ -248,6 +248,8 @@ void main() {
await tester.tap(find.byKey(const Key('player-rail-comments')));
await tester.pumpAndSettle();
expect(find.text('No comments yet.'), findsOneWidget);
await tester.tap(find.byKey(const Key('comment-input-placeholder')));
await tester.pumpAndSettle();
await tester.enterText(find.byKey(const Key('comment-input')), 'Nice demo');
await tester.pump();
await tester.tap(find.byKey(const Key('comment-post')));