diff --git a/lib/screens/home_page/editor_pane/url_card.dart b/lib/screens/home_page/editor_pane/url_card.dart index 5fa4b404..3d92ba1b 100644 --- a/lib/screens/home_page/editor_pane/url_card.dart +++ b/lib/screens/home_page/editor_pane/url_card.dart @@ -81,6 +81,11 @@ class URLTextField extends ConsumerWidget { .read(collectionStateNotifierProvider.notifier) .update(selectedId, url: value); }, + onFieldSubmitted: (value) { + ref + .read(collectionStateNotifierProvider.notifier) + .sendRequest(selectedId); + }, ); } } diff --git a/lib/widgets/textfields.dart b/lib/widgets/textfields.dart index 12102fc6..da68f9e2 100644 --- a/lib/widgets/textfields.dart +++ b/lib/widgets/textfields.dart @@ -7,11 +7,13 @@ class URLField extends StatelessWidget { required this.selectedId, this.initialValue, this.onChanged, + this.onFieldSubmitted, }); final String selectedId; final String? initialValue; final void Function(String)? onChanged; + final void Function(String)? onFieldSubmitted; @override Widget build(BuildContext context) { @@ -29,6 +31,7 @@ class URLField extends StatelessWidget { border: InputBorder.none, ), onChanged: onChanged, + onFieldSubmitted: onFieldSubmitted, ); } } diff --git a/test/widgets/textfields_test.dart b/test/widgets/textfields_test.dart index 652ec8ec..88aa6392 100644 --- a/test/widgets/textfields_test.dart +++ b/test/widgets/textfields_test.dart @@ -57,4 +57,41 @@ void main() { await tester.pumpAndSettle(); expect(find.text('entering 123 for cell field'), findsOneWidget); }); + + testWidgets('URL Field sends request on enter keystroke', (tester) async { + bool wasSubmitCalled = false; + + void testSubmit(String val) { + wasSubmitCalled = true; + } + + await tester.pumpWidget( + MaterialApp( + title: 'URL Field', + theme: kThemeDataDark, + home: Scaffold( + body: Column(children: [ + URLField( + selectedId: '2', + onFieldSubmitted: testSubmit, + ) + ]), + ), + ), + ); + + // ensure URLField is blank + expect(find.byType(TextFormField), findsOneWidget); + expect(find.textContaining('Enter API endpoint '), findsOneWidget); + expect(wasSubmitCalled, false); + + // modify value and press enter + var txtForm = find.byKey(const Key("url-2")); + await tester.enterText(txtForm, 'entering 123'); + await tester.testTextInput.receiveAction(TextInputAction.done); + await tester.pump(); + + // check if value was updated + expect(wasSubmitCalled, true); + }); }