@@ -6,7 +6,7 @@ import 'package:flutter_test/flutter_test.dart';
6
6
7
7
void main () {
8
8
group ('Suggestions - Welcome message overlap tests' , () {
9
- Widget materialApp (int suggestionsCount) => MaterialApp (
9
+ Widget materialApp (int suggestionsCount, { bool ? autofocus} ) => MaterialApp (
10
10
home: Scaffold (
11
11
appBar: AppBar (title: const Text ('Title' )),
12
12
body: LlmChatView (
@@ -17,6 +17,7 @@ void main() {
17
17
(index) => 'Suggestion sample ${index + 1 }' ,
18
18
),
19
19
provider: EchoProvider (),
20
+ autofocus: autofocus,
20
21
),
21
22
),
22
23
);
@@ -69,6 +70,32 @@ void main() {
69
70
// TextField must be focused now
70
71
expect ((tester.widget <TextField >(textField)).focusNode? .hasFocus, true );
71
72
});
73
+ testWidgets ('force autofocus false even if no suggestions provided' , (
74
+ tester,
75
+ ) async {
76
+ // No suggestions provided, but autofocus is set to false
77
+ await tester.pumpWidget (materialApp (0 , autofocus: false ));
78
+
79
+ // ChatTextField must be autofocus false and TextField must not be focused
80
+ // because parameter is set to false
81
+ final chatTextField = find.byType (ChatTextField );
82
+ final textField = find.byType (TextField );
83
+ expect ((tester.widget <ChatTextField >(chatTextField)).autofocus, false );
84
+ expect ((tester.widget <TextField >(textField)).focusNode? .hasFocus, false );
85
+ });
86
+ testWidgets ('force autofocus true even if suggestions provided' , (
87
+ tester,
88
+ ) async {
89
+ // Suggestions provided, but autofocus is set to true
90
+ await tester.pumpWidget (materialApp (40 , autofocus: true ));
91
+
92
+ // ChatTextField must be autofocus true and TextField must be focused
93
+ // because parameter is set to true
94
+ final chatTextField = find.byType (ChatTextField );
95
+ final textField = find.byType (TextField );
96
+ expect ((tester.widget <ChatTextField >(chatTextField)).autofocus, true );
97
+ expect ((tester.widget <TextField >(textField)).focusNode? .hasFocus, true );
98
+ });
72
99
testWidgets ('Welcome message with a lot of suggestions allowing scroll' , (
73
100
tester,
74
101
) async {
0 commit comments