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,97 @@ void main() {
169
171
check (ZulipApp .scaffoldMessenger).isNotNull ();
170
172
check (ZulipApp .ready).value.isTrue ();
171
173
});
174
+
175
+ const message = 'test error message' ;
176
+ const details = 'error details' ;
177
+
178
+ Finder findSnackBarByText (String text) => find.descendant (
179
+ of: find.byType (SnackBar ),
180
+ matching: find.text (text));
181
+
182
+ testWidgets ('reportErrorToUserBriefly with details' , (tester) async {
183
+ addTearDown (testBinding.reset);
184
+ await tester.pumpWidget (const ZulipApp ());
185
+
186
+ // Prior to app startup, reportErrorToUserBriefly only logs.
187
+ reportErrorToUserBriefly (message, details: details);
188
+ check (ZulipApp .ready).value.isFalse ();
189
+ await tester.pump ();
190
+ check (findSnackBarByText (message).evaluate ()).isEmpty ();
191
+ check (find.byType (AlertDialog ).evaluate ()).isEmpty ();
192
+
193
+ check (ZulipApp .ready).value.isTrue ();
194
+ // After app startup, reportErrorToUserBriefly displays a SnackBar.
195
+ reportErrorToUserBriefly (message, details: details);
196
+ await tester.pumpAndSettle ();
197
+ check (findSnackBarByText (message).evaluate ()).single;
198
+ check (find.byType (AlertDialog ).evaluate ()).isEmpty ();
199
+
200
+ // Open the error details dialog.
201
+ await tester.tap (find.text ('Details' ));
202
+ await tester.pumpAndSettle ();
203
+ check (findSnackBarByText (message).evaluate ()).isEmpty ();
204
+ checkErrorDialog (tester, expectedTitle: 'Error' , expectedMessage: details);
205
+ });
206
+
207
+ Future <void > prepareSnackBarWithDetails (WidgetTester tester) async {
208
+ addTearDown (testBinding.reset);
209
+ await tester.pumpWidget (const ZulipApp ());
210
+ await tester.pump ();
211
+ check (ZulipApp .ready).value.isTrue ();
212
+
213
+ reportErrorToUserBriefly (message, details: details);
214
+ await tester.pumpAndSettle ();
215
+ check (findSnackBarByText (message).evaluate ()).single;
216
+ }
217
+
218
+ testWidgets ('reportErrorToUser dismissing SnackBar' , (tester) async {
219
+ await prepareSnackBarWithDetails (tester);
220
+
221
+ // Dismissing the SnackBar.
222
+ reportErrorToUserBriefly (null );
223
+ await tester.pumpAndSettle ();
224
+ check (findSnackBarByText (message).evaluate ()).isEmpty ();
225
+
226
+ // Verify that the SnackBar would otherwise stay when not dismissed.
227
+ reportErrorToUserBriefly (message, details: details);
228
+ await tester.pumpAndSettle ();
229
+ check (findSnackBarByText (message).evaluate ()).single;
230
+ await tester.pumpAndSettle ();
231
+ check (findSnackBarByText (message).evaluate ()).single;
232
+ });
233
+
234
+ testWidgets ('reportErrorToUserBriefly(null) does not dismiss dialog' , (tester) async {
235
+ await prepareSnackBarWithDetails (tester);
236
+
237
+ // Open the error details dialog.
238
+ await tester.tap (find.text ('Details' ));
239
+ await tester.pumpAndSettle ();
240
+ check (findSnackBarByText (message).evaluate ()).isEmpty ();
241
+ checkErrorDialog (tester, expectedTitle: 'Error' , expectedMessage: details);
242
+
243
+ // The dialog should not get dismissed.
244
+ reportErrorToUserBriefly (null );
245
+ await tester.pumpAndSettle ();
246
+ checkErrorDialog (tester, expectedTitle: 'Error' , expectedMessage: details);
247
+ });
248
+
249
+ testWidgets ('reportErrorToUserBriefly(null) does not dismiss unrelated SnackBar' , (tester) async {
250
+ await prepareSnackBarWithDetails (tester);
251
+
252
+ // Dismissing the SnackBar.
253
+ reportErrorToUserBriefly (null );
254
+ await tester.pumpAndSettle ();
255
+ check (findSnackBarByText (message).evaluate ()).isEmpty ();
256
+
257
+ // Unrelated SnackBars should not be dismissed.
258
+ ZulipApp .scaffoldMessenger! .showSnackBar (
259
+ const SnackBar (content: Text ('unrelated' )));
260
+ await tester.pumpAndSettle ();
261
+ check (findSnackBarByText ('unrelated' ).evaluate ()).single;
262
+ reportErrorToUserBriefly (null );
263
+ await tester.pumpAndSettle ();
264
+ check (findSnackBarByText ('unrelated' ).evaluate ()).single;
265
+ });
172
266
});
173
267
}
0 commit comments