@@ -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' ;
@@ -32,6 +33,17 @@ import 'compose_box_checks.dart';
32
33
import 'dialog_checks.dart' ;
33
34
import 'test_app.dart' ;
34
35
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
+
35
47
late FakeApiConnection connection;
36
48
37
49
/// Simulates loading a [MessageListPage] and long-pressing on [message] .
@@ -51,16 +63,7 @@ Future<void> setupToMessageActionSheet(WidgetTester tester, {
51
63
}
52
64
connection = store.connection as FakeApiConnection ;
53
65
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 ());
64
67
await tester.pumpWidget (TestZulipApp (accountId: eg.selfAccount.id,
65
68
child: MessageListPage (initNarrow: narrow)));
66
69
@@ -442,6 +445,44 @@ void main() {
442
445
});
443
446
});
444
447
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
+
445
486
testWidgets ('shows error when fails' , (tester) async {
446
487
final message = eg.streamMessage (flags: [MessageFlag .read]);
447
488
await setupToMessageActionSheet (tester, message: message, narrow: TopicNarrow .ofMessage (message));
0 commit comments