0

I have been working on writing integration tests for my flutter web and I reach to a part where I need to write integration test for typeahead fields. But as soon as the integration test driver types something in typeahead, I can see the UI rendering and filtering the typed suggestion but my test always ends with this:

Warning: A call to tap() with finder "exactly one widget with key [<'Department store manager'>] (ignoring all but first) (ignoring offstage widgets): ListTile-[<'Department store manager'>](title: Text, dependencies: [Directionality, _InheritedTheme, _LocalizationsScope-[GlobalKey#0997f], _ScrollableScope])" derived an Offset (Offset(651.5, 120.0)) that would not hit test on the specified widget.
Maybe the widget is actually off-screen, or another widget is obscuring it, or the widget cannot receive pointer events.

Not sure what I'm doing wrong.

Here is my UI code:

Column(
  children: [
    Container(
      color: Colors.red,
      child: TypeAheadFormField<String>(
        key: Key(WidgetKeys.selectRoleTypeAheadKey),
        suggestionsBoxController: _jobSearchTypeaheadController,
        textFieldConfiguration: TextFieldConfiguration(
          controller: _searchJobNameController,
          decoration: InputDecoration(labelText: 'Job Title'),
        ),
        suggestionsCallback: (String pattern) async {
          return provider.filterJobs(pattern);
        },
        itemBuilder: (context, suggestion) {
          return ListTile(
            key: Key(suggestion),
            title: Text(suggestion),
          );
        },
        transitionBuilder: (context, suggestionsBox, controller) {
          return suggestionsBox;
        },
        onSuggestionSelected: (suggestion) {
          _searchJobNameController.text = suggestion;
        },
        validator: (String value) {
          if (value.isEmpty) {
            return 'Please select a city';
          }
          return null;
        },
      ),
    ),
  ],
)

Here's my test case:

Finder selectRoleTypeAhead = find.byKey(
  ValueKey(WidgetKeys.selectRoleTypeAheadKey),
  skipOffstage: false,
);

await tester.ensureVisible(selectRoleTypeAhead);
await tester.pumpAndSettle();

await tester.enterText(selectRoleTypeAhead, "Department");
await tester.pumpAndSettle(Duration(seconds: 3));

await tester.ensureVisible(
    find.byKey(Key(TestData.roleDepartmentStoreManager)).first);
await tester.pumpAndSettle(Duration(seconds: 3));

await tester.tap(
    find.byKey(Key('Department store manager'), skipOffstage: false).first); //This line fails to tap
await tester.pumpAndSettle();

I've even added additional delays but nothing seems to work

Henna
  • 1

0 Answers0