@@ -13,6 +13,24 @@ import '../model/binding.dart';
13
13
void main () {
14
14
TestZulipBinding .ensureInitialized ();
15
15
16
+ Future <GlobalKey <ComposeBoxController >> prepareComposeBox (WidgetTester tester, Narrow narrow) async {
17
+ addTearDown (testBinding.reset);
18
+ await testBinding.globalStore.add (eg.selfAccount, eg.initialSnapshot ());
19
+
20
+ final controllerKey = GlobalKey <ComposeBoxController >();
21
+ await tester.pumpWidget (
22
+ MaterialApp (
23
+ localizationsDelegates: ZulipLocalizations .localizationsDelegates,
24
+ supportedLocales: ZulipLocalizations .supportedLocales,
25
+ home: GlobalStoreWidget (
26
+ child: PerAccountStoreWidget (
27
+ accountId: eg.selfAccount.id,
28
+ child: ComposeBox (controllerKey: controllerKey, narrow: narrow)))));
29
+ await tester.pumpAndSettle ();
30
+
31
+ return controllerKey;
32
+ }
33
+
16
34
group ('ComposeContentController' , () {
17
35
group ('insertPadded' , () {
18
36
// Like `parseMarkedText` in test/model/autocomplete_test.dart,
@@ -116,25 +134,10 @@ void main() {
116
134
});
117
135
118
136
group ('ComposeBox textCapitalization' , () {
119
- late GlobalKey <ComposeBoxController > controllerKey;
120
-
121
- Future <void > prepareComposeBox (WidgetTester tester, Narrow narrow) async {
122
- addTearDown (testBinding.reset);
123
- await testBinding.globalStore.add (eg.selfAccount, eg.initialSnapshot ());
124
-
125
- controllerKey = GlobalKey ();
126
- await tester.pumpWidget (
127
- MaterialApp (
128
- localizationsDelegates: ZulipLocalizations .localizationsDelegates,
129
- supportedLocales: ZulipLocalizations .supportedLocales,
130
- home: GlobalStoreWidget (
131
- child: PerAccountStoreWidget (
132
- accountId: eg.selfAccount.id,
133
- child: ComposeBox (controllerKey: controllerKey, narrow: narrow)))));
134
- await tester.pumpAndSettle ();
135
- }
136
-
137
- void checkComposeBoxTextFields (WidgetTester tester, {required bool expectTopicTextField}) {
137
+ void checkComposeBoxTextFields (WidgetTester tester, {
138
+ required GlobalKey <ComposeBoxController > controllerKey,
139
+ required bool expectTopicTextField,
140
+ }) {
138
141
final composeBoxController = controllerKey.currentState! ;
139
142
140
143
final topicTextField = tester.widgetList <TextField >(find.byWidgetPredicate (
@@ -155,13 +158,17 @@ void main() {
155
158
}
156
159
157
160
testWidgets ('_StreamComposeBox' , (tester) async {
158
- await prepareComposeBox (tester, StreamNarrow (eg.stream ().streamId));
159
- checkComposeBoxTextFields (tester, expectTopicTextField: true );
161
+ final key = await prepareComposeBox (tester,
162
+ StreamNarrow (eg.stream ().streamId));
163
+ checkComposeBoxTextFields (tester, controllerKey: key,
164
+ expectTopicTextField: true );
160
165
});
161
166
162
167
testWidgets ('_FixedDestinationComposeBox' , (tester) async {
163
- await prepareComposeBox (tester, TopicNarrow .ofMessage (eg.streamMessage ()));
164
- checkComposeBoxTextFields (tester, expectTopicTextField: false );
168
+ final key = await prepareComposeBox (tester,
169
+ TopicNarrow .ofMessage (eg.streamMessage ()));
170
+ checkComposeBoxTextFields (tester, controllerKey: key,
171
+ expectTopicTextField: false );
165
172
});
166
173
});
167
174
}
0 commit comments