Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 09a4314

Browse files
committed
Test that both custom & platform input control receive input calls
1 parent 3b9cfc9 commit 09a4314

File tree

1 file changed

+42
-2
lines changed

1 file changed

+42
-2
lines changed

packages/flutter/test/services/text_input_test.dart

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -458,31 +458,62 @@ void main() {
458458
expect(fakeTextChannel.outgoingCalls, isEmpty);
459459
});
460460

461-
test('receives visual input control requests', () async {
461+
test('both input controls receive requests', () async {
462462
final FakeTextInputControl control = FakeTextInputControl();
463463
TextInput.setInputControl(control);
464464

465+
const TextInputConfiguration textConfig = TextInputConfiguration(inputType: TextInputType.text);
466+
const TextInputConfiguration numberConfig = TextInputConfiguration(inputType: TextInputType.number);
467+
const TextInputConfiguration noneConfig = TextInputConfiguration(inputType: TextInputType.none);
468+
465469
final FakeTextInputClient client = FakeTextInputClient(TextEditingValue.empty);
466-
final TextInputConnection connection = TextInput.attach(client, const TextInputConfiguration());
470+
final TextInputConnection connection = TextInput.attach(client, textConfig);
467471

468472
final List<String> expectedMethodCalls = <String>['attach'];
469473
expect(control.methodCalls, expectedMethodCalls);
474+
expect(control.inputType, TextInputType.text);
475+
fakeTextChannel.validateOutgoingMethodCalls(<MethodCall>[
476+
// When there's a custom text input control installed, the platform text
477+
// input control receives TextInputType.none
478+
MethodCall('TextInput.setClient', <dynamic>[1, noneConfig.toJson()]),
479+
]);
470480

471481
connection.show();
472482
expectedMethodCalls.add('show');
473483
expect(control.methodCalls, expectedMethodCalls);
484+
expect(fakeTextChannel.outgoingCalls.length, 2);
485+
expect(fakeTextChannel.outgoingCalls.last.method, 'TextInput.show');
486+
487+
connection.updateConfig(numberConfig);
488+
expectedMethodCalls.add('updateConfig');
489+
expect(control.methodCalls, expectedMethodCalls);
490+
expect(control.inputType, TextInputType.number);
491+
expect(fakeTextChannel.outgoingCalls.length, 3);
492+
fakeTextChannel.validateOutgoingMethodCalls(<MethodCall>[
493+
// When there's a custom text input control installed, the platform text
494+
// input control receives TextInputType.none
495+
MethodCall('TextInput.setClient', <dynamic>[1, noneConfig.toJson()]),
496+
const MethodCall('TextInput.show'),
497+
MethodCall('TextInput.updateConfig', noneConfig.toJson()),
498+
]);
474499

475500
connection.setComposingRect(Rect.zero);
476501
expectedMethodCalls.add('setComposingRect');
477502
expect(control.methodCalls, expectedMethodCalls);
503+
expect(fakeTextChannel.outgoingCalls.length, 4);
504+
expect(fakeTextChannel.outgoingCalls.last.method, 'TextInput.setMarkedTextRect');
478505

479506
connection.setCaretRect(Rect.zero);
480507
expectedMethodCalls.add('setCaretRect');
481508
expect(control.methodCalls, expectedMethodCalls);
509+
expect(fakeTextChannel.outgoingCalls.length, 5);
510+
expect(fakeTextChannel.outgoingCalls.last.method, 'TextInput.setCaretRect');
482511

483512
connection.setEditableSizeAndTransform(Size.zero, Matrix4.identity());
484513
expectedMethodCalls.add('setEditableSizeAndTransform');
485514
expect(control.methodCalls, expectedMethodCalls);
515+
expect(fakeTextChannel.outgoingCalls.length, 6);
516+
expect(fakeTextChannel.outgoingCalls.last.method, 'TextInput.setEditableSizeAndTransform');
486517

487518
connection.setStyle(
488519
fontFamily: null,
@@ -493,15 +524,21 @@ void main() {
493524
);
494525
expectedMethodCalls.add('setStyle');
495526
expect(control.methodCalls, expectedMethodCalls);
527+
expect(fakeTextChannel.outgoingCalls.length, 7);
528+
expect(fakeTextChannel.outgoingCalls.last.method, 'TextInput.setStyle');
496529

497530
connection.close();
498531
expectedMethodCalls.add('detach');
499532
expect(control.methodCalls, expectedMethodCalls);
533+
expect(fakeTextChannel.outgoingCalls.length, 8);
534+
expect(fakeTextChannel.outgoingCalls.last.method, 'TextInput.clearClient');
500535

501536
expectedMethodCalls.add('hide');
502537
final TestWidgetsFlutterBinding binding = TestWidgetsFlutterBinding.ensureInitialized() as TestWidgetsFlutterBinding;
503538
await binding.runAsync(() async {});
504539
await expectLater(control.methodCalls, expectedMethodCalls);
540+
expect(fakeTextChannel.outgoingCalls.length, 9);
541+
expect(fakeTextChannel.outgoingCalls.last.method, 'TextInput.hide');
505542
});
506543

507544
test('notifies changes to the attached client', () async {
@@ -628,10 +665,12 @@ class FakeTextChannel implements MethodChannel {
628665

629666
class FakeTextInputControl extends TextInputControl {
630667
final List<String> methodCalls = <String>[];
668+
late TextInputType inputType;
631669

632670
@override
633671
void attach(TextInputClient client, TextInputConfiguration configuration) {
634672
methodCalls.add('attach');
673+
inputType = configuration.inputType;
635674
}
636675

637676
@override
@@ -647,6 +686,7 @@ class FakeTextInputControl extends TextInputControl {
647686
@override
648687
void updateConfig(TextInputConfiguration configuration) {
649688
methodCalls.add('updateConfig');
689+
inputType = configuration.inputType;
650690
}
651691

652692
@override

0 commit comments

Comments
 (0)