@@ -14,6 +14,7 @@ import 'package:flutter/material.dart';
1414import 'package:image_picker/image_picker.dart' ;
1515import 'package:zulip/api/model/events.dart' ;
1616import 'package:zulip/api/model/model.dart' ;
17+ import 'package:zulip/api/model/narrow.dart' ;
1718import 'package:zulip/api/route/channels.dart' ;
1819import 'package:zulip/api/route/messages.dart' ;
1920import 'package:zulip/model/localizations.dart' ;
@@ -972,6 +973,59 @@ void main() {
972973 'You do not have permission to initiate direct message conversations.' ),
973974 )));
974975 });
976+
977+ testWidgets ('if channel is unsubscribed, refresh on message-send success' , (tester) async {
978+ // Regression test for the "first buggy behavior"
979+ // in https://github.com/zulip/zulip-flutter/issues/1798 .
980+ TypingNotifier .debugEnable = false ;
981+ addTearDown (TypingNotifier .debugReset);
982+ assert (MessageStoreImpl .debugOutboxEnable);
983+
984+ final channel = eg.stream ();
985+ final narrow = eg.topicNarrow (channel.streamId, 'some topic' );
986+ final messages = [eg.streamMessage (stream: channel, topic: 'some topic' )];
987+ final zulipLocalizations = GlobalLocalizations .zulipLocalizations;
988+ await prepareComposeBox (tester,
989+ narrow: narrow,
990+ streams: [channel],
991+ messages: messages);
992+ assert (store.subscriptions[channel.streamId] == null );
993+
994+ await enterContent (tester, 'hello world' );
995+
996+ connection.prepare (
997+ json: SendMessageResult (id: 456 ).toJson (), delay: Duration (seconds: 1 ));
998+ await tester.tap (find.byTooltip (zulipLocalizations.composeBoxSendTooltip));
999+ await tester.pump (Duration (milliseconds: 500 ));
1000+ check (connection.takeRequests ()).single.isA< http.Request > ()
1001+ ..method.equals ('POST' )
1002+ ..url.path.equals ('/api/v1/messages' );
1003+
1004+ final newMessage = eg.streamMessage (
1005+ stream: channel, topic: 'some topic' ,
1006+ content: '<p>hello world</p>' );
1007+ connection.prepare (json: eg.newestGetMessagesResult (
1008+ foundOldest: true , messages: [...messages, newMessage]).toJson ());
1009+ await tester.pump (Duration (milliseconds: 500 ));
1010+ check (connection.lastRequest).isA< http.Request > ()
1011+ ..method.equals ('GET' )
1012+ ..url.path.equals ('/api/v1/messages' )
1013+ ..url.queryParameters.deepEquals ({
1014+ 'narrow' : jsonEncode (resolveApiNarrowForServer (
1015+ narrow.apiEncode (), connection.zulipFeatureLevel! )),
1016+ 'anchor' : 'newest' ,
1017+ 'num_before' : '100' ,
1018+ 'num_after' : '100' ,
1019+ 'allow_empty_topic_name' : 'true' ,
1020+ });
1021+ check (find.descendant (
1022+ of: find.byType (MessageWithPossibleSender ),
1023+ matching: find.text ('hello world' ))
1024+ ).findsOne ();
1025+ // TODO(#1798) There's actually a lingering OutboxMessageWithPossibleSender,
1026+ // too (the "third buggy behavior" in #1798). We'll fix that soon,
1027+ // and it'll be convenient to test that here too.
1028+ });
9751029 });
9761030
9771031 group ('sending to empty topic' , () {
0 commit comments