Unverified Commit 49825559 authored by xubaolin's avatar xubaolin Committed by GitHub

Add more unit test cases for EditableText widget (#66889)

parent 37ebe3d8
......@@ -5076,6 +5076,89 @@ void main() {
)));
});
testWidgets('Repeatedly receiving [TextEditingValue] will not trigger a keyboard request', (WidgetTester tester) async {
// Regression test for https://github.com/flutter/flutter/issues/66036
final List<MethodCall> log = <MethodCall>[];
SystemChannels.textInput.setMockMethodCallHandler((MethodCall methodCall) async {
log.add(methodCall);
});
final TextEditingController controller = TextEditingController();
final FocusNode focusNode = FocusNode(debugLabel: 'EditableText Focus Node');
Widget builder() {
return StatefulBuilder(
builder: (BuildContext context, StateSetter setter) {
return MaterialApp(
home: MediaQuery(
data: const MediaQueryData(devicePixelRatio: 1.0),
child: Directionality(
textDirection: TextDirection.ltr,
child: Center(
child: Material(
child: EditableText(
controller: controller,
focusNode: focusNode,
style: textStyle,
cursorColor: Colors.red,
backgroundCursorColor: Colors.red,
keyboardType: TextInputType.multiline,
onChanged: (String value) { },
),
),
),
),
),
);
},
);
}
await tester.pumpWidget(builder());
await tester.tap(find.byType(EditableText));
await tester.pump();
// The keyboard is shown after tap the EditableText.
expect(focusNode.hasFocus, true);
log.clear();
final EditableTextState state = tester.firstState(find.byType(EditableText));
state.updateEditingValue(const TextEditingValue(
text: 'a',
));
await tester.pump();
// Nothing called when only the remote changes.
expect(log.length, 0);
// Hide the keyboard.
focusNode.unfocus();
await tester.pump();
expect(log.length, 2);
MethodCall methodCall = log[0];
// Close the InputConnection.
expect(methodCall, isMethodCall('TextInput.clearClient', arguments: null),);
methodCall = log[1];
expect(methodCall, isMethodCall('TextInput.hide', arguments: null),);
// The keyboard loses focus.
expect(focusNode.hasFocus, false);
log.clear();
// Send repeat value from the engine.
state.updateEditingValue(const TextEditingValue(
text: 'a',
));
await tester.pump();
// Nothing called when only the remote changes.
expect(log.length, 0);
// The keyboard is not be requested after a repeat value from the engine.
expect(focusNode.hasFocus, false);
});
testWidgets('autofocus:true on first frame does not throw', (WidgetTester tester) async {
final TextEditingController controller = TextEditingController(text: testText);
controller.selection = const TextSelection(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment