Skip to content

tester.enterText at specific position of TextInput without reset of previous input value #57792

@bionara

Description

@bionara

Testing's enterText simply sets the text input's input to that passed in:

/// Simulates the user typing the given text.
  void enterText(String text) {
    assert(isRegistered);
    updateEditingValue(TextEditingValue(
      text: text,
    ));
  }
  1. this doesn't simulate a user typing text - more like a "select all, paste to replace" job.

  2. this makes it not possible to test the following cases:

"given I click at a given point in the input text string, I should be able to to add text there and check the value". This isn't possible to test:

final finderTextInput = find.byType(TextInput);
await tester.enterText(finderTextInput, 'helloworld');
// text is 'helloworld'

Then if I wanted to simulate the user clicking at pos 5 to add a space, adding a space, then check the output, I can't:

final finderTextInput = find.byType(TextInput);
controller.selection = TextSelection.collapsed(offset: 5);
await tester.enterText(finderTextInput, ' '); 
// text is ' ' but expected, after second textinput at pos 5, 'hello world'

Any way to achieve this in testing?

Metadata

Metadata

Assignees

No one assigned

    Labels

    a: tests"flutter test", flutter_test, or one of our testsa: text inputEntering text in a text field or keyboard related problemsc: new featureNothing broken; request for a new capabilityframeworkflutter/packages/flutter repository. See also f: labels.r: timeoutIssue is closed due to author not providing the requested details in timet: flutter driver"flutter driver", flutter_drive, or a driver test

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions