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