@@ -5,6 +5,7 @@ import 'package:flutter/material.dart';
55import 'package:flutter/services.dart' ;
66import 'package:flutter_test/flutter_test.dart' ;
77import 'package:http/http.dart' as http;
8+ import 'package:zulip/api/model/events.dart' ;
89import 'package:zulip/api/model/model.dart' ;
910import 'package:zulip/api/route/channels.dart' ;
1011import 'package:zulip/api/route/messages.dart' ;
@@ -32,6 +33,17 @@ import 'compose_box_checks.dart';
3233import 'dialog_checks.dart' ;
3334import 'test_app.dart' ;
3435
36+ GetMessagesResult _getMessagesResult (Message message) {
37+ return GetMessagesResult (
38+ anchor: message.id,
39+ foundNewest: true ,
40+ foundOldest: true ,
41+ foundAnchor: true ,
42+ historyLimited: false ,
43+ messages: [message],
44+ );
45+ }
46+
3547late FakeApiConnection connection;
3648
3749/// Simulates loading a [MessageListPage] and long-pressing on [message] .
@@ -51,16 +63,7 @@ Future<void> setupToMessageActionSheet(WidgetTester tester, {
5163 }
5264 connection = store.connection as FakeApiConnection ;
5365
54- // prepare message list data
55- connection.prepare (json: GetMessagesResult (
56- anchor: message.id,
57- foundNewest: true ,
58- foundOldest: true ,
59- foundAnchor: true ,
60- historyLimited: false ,
61- messages: [message],
62- ).toJson ());
63-
66+ connection.prepare (json: _getMessagesResult (message).toJson ());
6467 await tester.pumpWidget (TestZulipApp (accountId: eg.selfAccount.id,
6568 child: MessageListPage (initNarrow: narrow)));
6669
@@ -442,6 +445,44 @@ void main() {
442445 });
443446 });
444447
448+ testWidgets ('on topic move, acts on new topic' , (tester) async {
449+ final stream = eg.stream ();
450+ const topic = 'old topic' ;
451+ final message = eg.streamMessage (flags: [MessageFlag .read],
452+ stream: stream, topic: topic);
453+ await setupToMessageActionSheet (tester, message: message, narrow: TopicNarrow .ofMessage (message));
454+ // Get the action sheet fully deployed while the old narrow applies.
455+ await tester.pumpAndSettle ();
456+
457+ final store = await testBinding.globalStore.perAccount (eg.selfAccount.id);
458+ final newStream = eg.stream ();
459+ const newTopic = 'other topic' ;
460+ // This result isn't quite realistic for this request: it should get
461+ // the updated channel/stream ID and topic, because we don't even
462+ // start the request until after we get the move event.
463+ // But constructing the right result is annoying at the moment, and
464+ // it doesn't matter anyway: [MessageStoreImpl.reconcileMessages] will
465+ // keep the version updated by the event. If that somehow changes in
466+ // some future refactor, it'll cause this test to fail.
467+ connection.prepare (json: _getMessagesResult (message).toJson ());
468+ await store.handleEvent (eg.updateMessageEventMoveFrom (
469+ newStreamId: newStream.streamId, newTopic: newTopic,
470+ propagateMode: PropagateMode .changeAll,
471+ origMessages: [message]));
472+
473+ connection.prepare (json: UpdateMessageFlagsForNarrowResult (
474+ processedCount: 11 , updatedCount: 3 ,
475+ firstProcessedId: 1 , lastProcessedId: 1980 ,
476+ foundOldest: true , foundNewest: true ).toJson ());
477+ await tester.tap (find.byIcon (Icons .mark_chat_unread_outlined, skipOffstage: false ));
478+ await tester.pumpAndSettle ();
479+ check (connection.lastRequest).isA< http.Request > ()
480+ ..method.equals ('POST' )
481+ ..url.path.equals ('/api/v1/messages/flags/narrow' )
482+ ..bodyFields['narrow' ].equals (
483+ jsonEncode (TopicNarrow (newStream.streamId, newTopic).apiEncode ()));
484+ });
485+
445486 testWidgets ('shows error when fails' , (tester) async {
446487 final message = eg.streamMessage (flags: [MessageFlag .read]);
447488 await setupToMessageActionSheet (tester, message: message, narrow: TopicNarrow .ofMessage (message));
0 commit comments