Skip to content

Commit

Permalink
Merge pull request #2461 from leancodepl/patch-enter-text-bug
Browse files Browse the repository at this point in the history
Patch enter text bug
  • Loading branch information
pdenert authored Dec 20, 2024
2 parents 5bd576c + 62c0bb5 commit 79b98c6
Show file tree
Hide file tree
Showing 9 changed files with 971 additions and 3 deletions.
2 changes: 1 addition & 1 deletion dev/e2e_app/integration_test/common.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import 'package:patrol/patrol.dart';
export 'package:flutter_test/flutter_test.dart';
export 'package:patrol/patrol.dart';

final _patrolTesterConfig = PatrolTesterConfig();
final _patrolTesterConfig = PatrolTesterConfig(printLogs: true);
final _nativeAutomatorConfig = NativeAutomatorConfig(
findTimeout: Duration(seconds: 20), // 10 seconds is too short for some CIs
);
Expand Down
32 changes: 32 additions & 0 deletions dev/e2e_app/integration_test/text_fields_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import 'package:e2e_app/text_fields_screen.dart';
import 'package:flutter/material.dart';

import 'common.dart';

void main() {
patrol('Can enter text into same field twice', ($) async {
await $.pumpWidgetAndSettle(const TextFieldsScreen());
await $.pumpAndSettle();

// Enter text into the first text field.
await $(const Key('textField1')).enterText('User');
await $(const Key('buttonFocus')).tap();
expect($('User'), findsOneWidget);

// Enter text into the first text field again. After focusing on the button.
await $(const Key('textField1')).enterText('User2');
await $(const Key('buttonUnfocus')).tap();
expect($('User'), findsNothing);
expect($('User2'), findsOneWidget);

// Enter text into the first text field again. After unfocusing the button.
// Then enter text into the second text field and into the first field again.
await $(const Key('textField1')).enterText('User3');
await $(const Key('textField2')).enterText('User4');
await $(const Key('textField1')).enterText('User5');
expect($('User2'), findsNothing);
expect($('User3'), findsNothing);
expect($('User4'), findsOneWidget);
expect($('User5'), findsOneWidget);
});
}
49 changes: 49 additions & 0 deletions dev/e2e_app/lib/text_fields_screen.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import 'package:flutter/material.dart';

class TextFieldsScreen extends StatefulWidget {
const TextFieldsScreen({super.key});

@override
State<TextFieldsScreen> createState() => _TextFieldsScreenState();
}

class _TextFieldsScreenState extends State<TextFieldsScreen> {
FocusNode focusNode = FocusNode();

@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Text Fields'),
),
body: Center(
child: SingleChildScrollView(
child: Column(
children: [
const TextField(
key: Key('textField1'),
),
ElevatedButton.icon(
key: const Key('buttonFocus'),
onPressed: () =>
FocusScope.of(context).requestFocus(focusNode),
label: const Icon(Icons.search),
focusNode: focusNode,
),
const TextField(
key: Key('textField2'),
),
ElevatedButton.icon(
key: const Key('buttonUnfocus'),
onPressed: () => FocusScope.of(context).unfocus(),
label: const Icon(Icons.search),
),
],
),
),
),
),
);
}
}
4 changes: 4 additions & 0 deletions packages/patrol_finders/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## Unreleased

- Patch `enterText` into same field twice. (#2461)

## 2.5.1

- Disable printing logs in nested `waitUntilVisible` and `waitUntilExists` calls.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export '../common.dart';
export 'exceptions.dart';
export 'patrol_finder.dart';
export 'patrol_tester.dart';
export 'widget_tester.dart';
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,10 @@ const defaultScrollMaxIteration = 15;
class PatrolTester {
/// Creates a new [PatrolTester] which wraps [tester].
PatrolTester({
required this.tester,
required WidgetTester tester,
required this.config,
}) : patrolLog = PatrolLogWriter();
}) : patrolLog = PatrolLogWriter(),
tester = PatrolWidgetTester(tester);

/// Global configuration of this tester.
final PatrolTesterConfig config;
Expand Down Expand Up @@ -427,6 +428,7 @@ class PatrolTester {
timeout: visibleTimeout,
enablePatrolLog: false,
);
await tester.tap(resolvedFinder.first);
await tester.enterText(resolvedFinder.first, text);
if (!kIsWeb) {
// When registering `testTextInput`, we have to unregister it
Expand Down
Loading

0 comments on commit 79b98c6

Please sign in to comment.