@@ -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,38 @@ 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
+
299
+ testWidgets ('smoke test' , (tester) async {
300
+ final narrow = TopicNarrow .ofMessage (eg.streamMessage ());
301
+ final apiNarrow = narrow.apiEncode ()..add (ApiNarrowIsUnread ());
302
+ await prepare (tester);
303
+ connection.prepare (json: UpdateMessageFlagsForNarrowResult (
304
+ processedCount: 11 , updatedCount: 3 ,
305
+ firstProcessedId: 1 , lastProcessedId: 1980 ,
306
+ foundOldest: true , foundNewest: true ).toJson ());
307
+ final didPass = updateMessageFlagsStartingFromAnchor (
308
+ context: context, apiNarrow: apiNarrow, op: UpdateMessageFlagsOp .add, flag: MessageFlag .read,
309
+ includeAnchor: false , startingAnchor: AnchorCode .oldest, onCompletedMessage: onCompletedMessage,
310
+ onFailedTitle: onFailedTitle, progressMessage: progressMessage);
311
+ await tester.pump (Duration .zero);
312
+ check (connection.lastRequest).isA< http.Request > ()
313
+ ..method.equals ('POST' )
314
+ ..url.path.equals ('/api/v1/messages/flags/narrow' )
315
+ ..bodyFields.deepEquals ({
316
+ 'anchor' : 'oldest' ,
317
+ 'include_anchor' : 'false' ,
318
+ 'num_before' : '0' ,
319
+ 'num_after' : '1000' ,
320
+ 'narrow' : jsonEncode (apiNarrow),
321
+ 'op' : 'add' ,
322
+ 'flag' : 'read' ,
323
+ });
324
+ check (await didPass).isTrue ();
325
+ });
326
+ });
293
327
}
0 commit comments