Skip to content

Commit 27bb3d8

Browse files
committed
[tests] add enter key test
1 parent b840358 commit 27bb3d8

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

test/widgets/textfields_test.dart

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,41 @@ void main() {
5757
await tester.pumpAndSettle();
5858
expect(find.text('entering 123 for cell field'), findsOneWidget);
5959
});
60+
61+
testWidgets('URL Field sends request on enter keystroke', (tester) async {
62+
bool wasSubmitCalled = false;
63+
64+
void testSubmit(String val) {
65+
wasSubmitCalled = true;
66+
}
67+
68+
await tester.pumpWidget(
69+
MaterialApp(
70+
title: 'URL Field',
71+
theme: kThemeDataDark,
72+
home: Scaffold(
73+
body: Column(children: [
74+
URLField(
75+
selectedId: '2',
76+
onFieldSubmitted: testSubmit,
77+
)
78+
]),
79+
),
80+
),
81+
);
82+
83+
// ensure URLField is blank
84+
expect(find.byType(TextFormField), findsOneWidget);
85+
expect(find.textContaining('Enter API endpoint '), findsOneWidget);
86+
expect(wasSubmitCalled, false);
87+
88+
// modify value and press enter
89+
var txtForm = find.byKey(const Key("url-2"));
90+
await tester.enterText(txtForm, 'entering 123');
91+
await tester.testTextInput.receiveAction(TextInputAction.done);
92+
await tester.pump();
93+
94+
// check if value was updated
95+
expect(wasSubmitCalled, true);
96+
});
6097
}

0 commit comments

Comments
 (0)