@@ -24,27 +24,27 @@ import 'test_app.dart';
24
24
void main () {
25
25
TestZulipBinding .ensureInitialized ();
26
26
27
- group ('markNarrowAsRead' , () {
28
- late PerAccountStore store;
29
- late FakeApiConnection connection;
30
- late BuildContext context;
27
+ late PerAccountStore store;
28
+ late FakeApiConnection connection;
29
+ late BuildContext context;
31
30
32
- Future <void > prepare (WidgetTester tester, {
33
- UnreadMessagesSnapshot ? unreadMsgs,
34
- }) async {
35
- addTearDown (testBinding.reset);
36
- await testBinding.globalStore.add (eg.selfAccount, eg.initialSnapshot (
37
- unreadMsgs: unreadMsgs));
38
- store = await testBinding.globalStore.perAccount (eg.selfAccount.id);
39
- connection = store.connection as FakeApiConnection ;
31
+ Future <void > prepare (WidgetTester tester, {
32
+ UnreadMessagesSnapshot ? unreadMsgs,
33
+ }) async {
34
+ addTearDown (testBinding.reset);
35
+ await testBinding.globalStore.add (eg.selfAccount, eg.initialSnapshot (
36
+ unreadMsgs: unreadMsgs));
37
+ store = await testBinding.globalStore.perAccount (eg.selfAccount.id);
38
+ connection = store.connection as FakeApiConnection ;
40
39
41
- await tester.pumpWidget (TestZulipApp (accountId: eg.selfAccount.id,
42
- child: const Scaffold (body: Placeholder ())));
43
- // global store, per-account store get loaded
44
- await tester.pumpAndSettle ();
45
- context = tester.element (find.byType (Placeholder ));
46
- }
40
+ await tester.pumpWidget (TestZulipApp (accountId: eg.selfAccount.id,
41
+ child: const Scaffold (body: Placeholder ())));
42
+ // global store, per-account store get loaded
43
+ await tester.pumpAndSettle ();
44
+ context = tester.element (find.byType (Placeholder ));
45
+ }
47
46
47
+ group ('markNarrowAsRead' , () {
48
48
testWidgets ('smoke test on modern server' , (tester) async {
49
49
final narrow = TopicNarrow .ofMessage (eg.streamMessage ());
50
50
await prepare (tester);
@@ -290,4 +290,47 @@ void main() {
290
290
expectedMessage: 'NetworkException: Oops (ClientException: Oops)' );
291
291
});
292
292
});
293
+
294
+ group ('updateMessageFlagsStartingFromAnchor' , () {
295
+ String onCompletedMessage (int count) => 'onCompletedMessage($count )' ;
296
+ const progressMessage = 'progressMessage' ;
297
+ const onFailedTitle = 'onFailedTitle' ;
298
+ final narrow = TopicNarrow .ofMessage (eg.streamMessage ());
299
+ final apiNarrow = narrow.apiEncode ()..add (ApiNarrowIsUnread ());
300
+
301
+ Future <bool > invokeUpdateMessageFlagsStartingFromAnchor () =>
302
+ updateMessageFlagsStartingFromAnchor (
303
+ context: context,
304
+ apiNarrow: apiNarrow,
305
+ op: UpdateMessageFlagsOp .add,
306
+ flag: MessageFlag .read,
307
+ includeAnchor: false ,
308
+ startingAnchor: AnchorCode .oldest,
309
+ onCompletedMessage: onCompletedMessage,
310
+ onFailedTitle: onFailedTitle,
311
+ progressMessage: progressMessage);
312
+
313
+ testWidgets ('smoke test' , (tester) async {
314
+ await prepare (tester);
315
+ connection.prepare (json: UpdateMessageFlagsForNarrowResult (
316
+ processedCount: 11 , updatedCount: 3 ,
317
+ firstProcessedId: 1 , lastProcessedId: 1980 ,
318
+ foundOldest: true , foundNewest: true ).toJson ());
319
+ final didPass = invokeUpdateMessageFlagsStartingFromAnchor ();
320
+ await tester.pump (Duration .zero);
321
+ check (connection.lastRequest).isA< http.Request > ()
322
+ ..method.equals ('POST' )
323
+ ..url.path.equals ('/api/v1/messages/flags/narrow' )
324
+ ..bodyFields.deepEquals ({
325
+ 'anchor' : 'oldest' ,
326
+ 'include_anchor' : 'false' ,
327
+ 'num_before' : '0' ,
328
+ 'num_after' : '1000' ,
329
+ 'narrow' : jsonEncode (apiNarrow),
330
+ 'op' : 'add' ,
331
+ 'flag' : 'read' ,
332
+ });
333
+ check (await didPass).isTrue ();
334
+ });
335
+ });
293
336
}
0 commit comments