@@ -13,6 +13,24 @@ import '../model/binding.dart';
1313void main () {
1414 TestZulipBinding .ensureInitialized ();
1515
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+
1634 group ('ComposeContentController' , () {
1735 group ('insertPadded' , () {
1836 // Like `parseMarkedText` in test/model/autocomplete_test.dart,
@@ -116,25 +134,10 @@ void main() {
116134 });
117135
118136 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+ }) {
138141 final composeBoxController = controllerKey.currentState! ;
139142
140143 final topicTextField = tester.widgetList <TextField >(find.byWidgetPredicate (
@@ -155,13 +158,17 @@ void main() {
155158 }
156159
157160 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 );
160165 });
161166
162167 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 );
165172 });
166173 });
167174}
0 commit comments