Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
maheshj01 committed Mar 17, 2024
1 parent 02b6e68 commit f29c4e4
Showing 1 changed file with 60 additions and 32 deletions.
92 changes: 60 additions & 32 deletions test/searchfield_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -311,37 +311,6 @@ void main() {
expect(find.text(countries[0].name), findsOneWidget);
});

// testWidgets('FocusNode should work with searchfield',
// (WidgetTester tester) async {
// final focus = FocusNode();
// final countries = data.map((e) => Country.fromMap(e)).toList();
// await tester.pumpWidget(_boilerplate(
// child: SearchField(
// key: const Key('searchfield'),
// suggestions:
// countries.map((e) => SearchFieldListItem<Country>(e.name)).toList(),
// focusNode: focus,
// suggestionState: Suggestion.expand,
// onSuggestionTap: (SearchFieldListItem<Country> x) {
// focus.unfocus();
// },
// )));
// final listFinder = find.byType(ListView);
// final textField = find.byType(TextFormField);
// expect(textField, findsOneWidget);
// expect(listFinder, findsNothing);
// await tester.tap(textField);
// expect(focus.hasFocus, true);
// await tester.enterText(textField, '');
// await tester.pumpAndSettle();
// expect(listFinder, findsOneWidget);
// final tapTarget = find.text(countries[0].name);
// expect(tapTarget, findsOneWidget);
// await tester.tap(tapTarget);
// await tester.pumpAndSettle();
// expect(focus.hasFocus, false);
// });

testWidgets('Searchfield should trigger onTap when tapped',
(widgetTester) async {
final controller = TextEditingController();
Expand Down Expand Up @@ -456,6 +425,33 @@ void main() {
expect(find.text('suggestion $counter'), findsOneWidget);
});

testWidgets('Searchfield suggestions should respect width',
(widgetTester) async {
final controller = TextEditingController();
final countries = data.map(Country.fromMap).toList();
final width = 200.0;
await widgetTester.pumpWidget(_boilerplate(
child: SearchField(
controller: controller,
suggestions:
countries.map((e) => SearchFieldListItem<Country>(e.name)).toList(),
suggestionState: Suggestion.expand,
suggestionsDecoration: SuggestionDecoration(
width: width,
),
)));

final textField = find.byType(TextFormField);
expect(textField, findsOneWidget);
await widgetTester.tap(textField);
await widgetTester.pumpAndSettle();
final positioned = find.byType(Positioned);
expect(positioned, findsOneWidget);
final positionedRenderBox =
widgetTester.renderObject(positioned) as RenderBox;
expect(positionedRenderBox.size.width, equals(width));
});

group('Searchfield should respect SuggestionState: ', () {
testWidgets('ListView should be visible when searchfield is tapped',
(WidgetTester tester) async {
Expand Down Expand Up @@ -1014,7 +1010,7 @@ void main() {
expect(textField.textCapitalization, TextCapitalization.none);
});

group('Test Searchfield autofocus', () {
group('Test Searchfield focus', () {
testWidgets('Searchfield should not autofocus by default (hidden keyboard)',
(widgetTester) async {
final focus = FocusNode();
Expand Down Expand Up @@ -1049,6 +1045,38 @@ void main() {
// keyboard should not be visible
expect(widgetTester.testTextInput.isVisible, isTrue);
});

testWidgets('Searchfield should respect FocusNode',
(WidgetTester tester) async {
final focus = FocusNode();
final boilerPlate = _boilerplate(
child: SearchField(
key: const Key('searchfield'),
focusNode: focus,
suggestions: ['ABC', 'DEF', 'GHI', 'JKL']
.map(SearchFieldListItem<String>.new)
.toList(),
));
await tester.pumpWidget(boilerPlate);
await tester.pumpAndSettle();
// keyboard should not be visible
expect(tester.testTextInput.isVisible, isFalse);
focus.requestFocus();
await tester.pumpAndSettle();
expect(tester.testTextInput.isVisible, isTrue);

focus.unfocus();
await tester.pumpAndSettle();
expect(tester.testTextInput.isVisible, isFalse);

focus.requestFocus();
await tester.pumpAndSettle();
expect(tester.testTextInput.isVisible, isTrue);

focus.unfocus();
await tester.pumpAndSettle();
expect(tester.testTextInput.isVisible, isFalse);
});
});

testWidgets("Test onTapOutside", (widgetTester) async {
Expand Down

0 comments on commit f29c4e4

Please sign in to comment.