@@ -5,6 +5,7 @@ import 'package:flutter/material.dart';
5
5
import 'package:flutter/services.dart' ;
6
6
import 'package:flutter_test/flutter_test.dart' ;
7
7
import 'package:http/http.dart' as http;
8
+ import 'package:zulip/api/model/events.dart' ;
8
9
import 'package:zulip/api/model/model.dart' ;
9
10
import 'package:zulip/api/route/channels.dart' ;
10
11
import 'package:zulip/api/route/messages.dart' ;
@@ -435,6 +436,49 @@ void main() {
435
436
});
436
437
});
437
438
439
+ testWidgets ('on topic move, acts on new topic' , (tester) async {
440
+ final stream = eg.stream ();
441
+ const topic = 'old topic' ;
442
+ final message = eg.streamMessage (flags: [MessageFlag .read],
443
+ stream: stream, topic: topic);
444
+ await setupToMessageActionSheet (tester, message: message,
445
+ narrow: TopicNarrow .ofMessage (message));
446
+
447
+ // Get the action sheet fully deployed while the old narrow applies.
448
+ // (This way we maximize the range of potential bugs this test can catch,
449
+ // by giving the code maximum opportunity to latch onto the old topic.)
450
+ await tester.pumpAndSettle ();
451
+
452
+ final store = await testBinding.globalStore.perAccount (eg.selfAccount.id);
453
+ final newStream = eg.stream ();
454
+ const newTopic = 'other topic' ;
455
+ // This result isn't quite realistic for this request: it should get
456
+ // the updated channel/stream ID and topic, because we don't even
457
+ // start the request until after we get the move event.
458
+ // But constructing the right result is annoying at the moment, and
459
+ // it doesn't matter anyway: [MessageStoreImpl.reconcileMessages] will
460
+ // keep the version updated by the event. If that somehow changes in
461
+ // some future refactor, it'll cause this test to fail.
462
+ connection.prepare (json: newestResult (
463
+ foundOldest: true , messages: [message]).toJson ());
464
+ await store.handleEvent (eg.updateMessageEventMoveFrom (
465
+ newStreamId: newStream.streamId, newTopic: newTopic,
466
+ propagateMode: PropagateMode .changeAll,
467
+ origMessages: [message]));
468
+
469
+ connection.prepare (json: UpdateMessageFlagsForNarrowResult (
470
+ processedCount: 11 , updatedCount: 3 ,
471
+ firstProcessedId: 1 , lastProcessedId: 1980 ,
472
+ foundOldest: true , foundNewest: true ).toJson ());
473
+ await tester.tap (find.byIcon (Icons .mark_chat_unread_outlined, skipOffstage: false ));
474
+ await tester.pumpAndSettle ();
475
+ check (connection.lastRequest).isA< http.Request > ()
476
+ ..method.equals ('POST' )
477
+ ..url.path.equals ('/api/v1/messages/flags/narrow' )
478
+ ..bodyFields['narrow' ].equals (
479
+ jsonEncode (TopicNarrow (newStream.streamId, newTopic).apiEncode ()));
480
+ });
481
+
438
482
testWidgets ('shows error when fails' , (tester) async {
439
483
final message = eg.streamMessage (flags: [MessageFlag .read]);
440
484
await setupToMessageActionSheet (tester, message: message, narrow: TopicNarrow .ofMessage (message));
0 commit comments