1
1
import 'package:checks/checks.dart' ;
2
2
import 'package:flutter/material.dart' ;
3
3
import 'package:flutter_test/flutter_test.dart' ;
4
+ import 'package:zulip/log.dart' ;
4
5
import 'package:zulip/model/database.dart' ;
5
6
import 'package:zulip/widgets/app.dart' ;
6
7
import 'package:zulip/widgets/inbox.dart' ;
@@ -10,6 +11,7 @@ import '../example_data.dart' as eg;
10
11
import '../flutter_checks.dart' ;
11
12
import '../model/binding.dart' ;
12
13
import '../test_navigation.dart' ;
14
+ import 'dialog_checks.dart' ;
13
15
import 'page_checks.dart' ;
14
16
import 'test_app.dart' ;
15
17
@@ -169,5 +171,52 @@ void main() {
169
171
check (ZulipApp .scaffoldMessenger).isNotNull ();
170
172
check (ZulipApp .ready).value.isTrue ();
171
173
});
174
+
175
+ testWidgets ('reportErrorToUserBriefly shows snack bar' , (tester) async {
176
+ addTearDown (testBinding.reset);
177
+ await tester.pumpWidget (const ZulipApp ());
178
+
179
+ final finder = find.descendant (
180
+ of: find.byType (SnackBar ),
181
+ matching: find.text ('test error message' ));
182
+
183
+ // Prior to app startup, reportErrorToUserBriefly only logs.
184
+ reportErrorToUserInSnackBar ('test error message' );
185
+ check (ZulipApp .ready).value.isFalse ();
186
+ await tester.pump ();
187
+ check (debugTakeLastReportedError ()).equals ('test error message' );
188
+ check (finder.evaluate ()).isEmpty ();
189
+
190
+ check (ZulipApp .ready).value.isTrue ();
191
+ // After app startup, reportErrorToUserBriefly displays a snack bar.
192
+ reportErrorToUserInSnackBar ('test error message' );
193
+ await tester.pump ();
194
+ check (finder.evaluate ()).single;
195
+ });
196
+
197
+ testWidgets ('reportErrorToUserInDialog shows dialog' , (tester) async {
198
+ addTearDown (testBinding.reset);
199
+ await tester.pumpWidget (const ZulipApp ());
200
+
201
+ final finder = find.descendant (
202
+ of: find.byType (AlertDialog ),
203
+ matching: find.text ('test error message' ));
204
+
205
+ // Prior to app startup, reportErrorToUserInDialog only logs.
206
+ reportErrorToUserInDialog ('test error message' );
207
+ check (ZulipApp .ready).value.isFalse ();
208
+ await tester.pump ();
209
+ check (debugTakeLastReportedError ()).equals ('test error message' );
210
+ check (finder.evaluate ()).isEmpty ();
211
+
212
+ check (ZulipApp .ready).value.isTrue ();
213
+ // After app startup, reportErrorToUserInDialog displays a dialog.
214
+ reportErrorToUserInDialog ('test error message' );
215
+ await tester.pump ();
216
+ check (finder.evaluate ()).single;
217
+ // Check the title too.
218
+ checkErrorDialog (tester,
219
+ expectedTitle: 'Error' , expectedMessage: 'test error message' );
220
+ });
172
221
});
173
222
}
0 commit comments