Skip to content

Commit 50a1a08

Browse files
chrisbobbegnprice
authored andcommitted
compose: Fix bug where topic input not filled on quote-and-reply
Fixes #1469.
1 parent f5602fe commit 50a1a08

File tree

3 files changed

+32
-4
lines changed

3 files changed

+32
-4
lines changed

lib/widgets/action_sheet.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1409,7 +1409,7 @@ class QuoteAndReplyButton extends MessageActionSheetMenuItemButton {
14091409
composeBoxController!;
14101410
if (
14111411
composeBoxController is StreamComposeBoxController
1412-
&& composeBoxController.topic.textNormalized == kNoTopicTopic
1412+
&& composeBoxController.topic.isTopicVacuous
14131413
&& message is StreamMessage
14141414
) {
14151415
composeBoxController.topic.setTopic(message.topic);

test/model/autocomplete_checks.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ extension ComposeContentControllerChecks on Subject<ComposeContentController> {
1010

1111
extension ComposeTopicControllerChecks on Subject<ComposeTopicController> {
1212
Subject<AutocompleteIntent<TopicAutocompleteQuery>?> get autocompleteIntent => has((c) => c.autocompleteIntent(), 'autocompleteIntent');
13+
Subject<String> get textNormalized => has((c) => c.textNormalized, 'textNormalized');
1314
}
1415

1516
extension AutocompleteIntentChecks on Subject<AutocompleteIntent<AutocompleteQuery>> {

test/widgets/action_sheet_test.dart

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import '../api/fake_api.dart';
4141
import '../api/model/model_checks.dart';
4242
import '../example_data.dart' as eg;
4343
import '../flutter_checks.dart';
44+
import '../model/autocomplete_checks.dart';
4445
import '../model/binding.dart';
4546
import '../model/content_test.dart';
4647
import '../model/test_store.dart';
@@ -1674,8 +1675,33 @@ void main() {
16741675
check(contentController).not((it) => it.validationErrors.contains(ContentValidationError.quoteAndReplyInProgress));
16751676
}
16761677

1677-
testWidgets('in channel narrow', (tester) async {
1678-
final message = eg.streamMessage();
1678+
testWidgets('in channel narrow with different, non-vacuous topic', (tester) async {
1679+
final message = eg.streamMessage(topic: 'some topic');
1680+
await setupToMessageActionSheet(tester, message: message, narrow: ChannelNarrow(message.streamId));
1681+
1682+
final composeBoxController = findComposeBoxController(tester) as StreamComposeBoxController;
1683+
final contentController = composeBoxController.content;
1684+
1685+
// Ensure channel-topics are loaded before testing quote & reply behavior
1686+
connection.prepare(body:
1687+
jsonEncode(GetStreamTopicsResult(topics: [eg.getStreamTopicsEntry()]).toJson()));
1688+
final topicController = composeBoxController.topic;
1689+
topicController.value = TextEditingValue(text: 'other topic');
1690+
1691+
final valueBefore = contentController.value;
1692+
prepareRawContentResponseSuccess(message: message, rawContent: 'Hello world');
1693+
await tapQuoteAndReplyButton(tester);
1694+
checkLoadingState(store, contentController, valueBefore: valueBefore, message: message);
1695+
await tester.pump(Duration.zero); // message is fetched; compose box updates
1696+
check(composeBoxController.contentFocusNode.hasFocus).isTrue();
1697+
checkSuccessState(store, contentController,
1698+
valueBefore: valueBefore, message: message, rawContent: 'Hello world');
1699+
check(topicController).textNormalized.equals('other topic');
1700+
});
1701+
1702+
testWidgets('in channel narrow with empty topic', (tester) async {
1703+
// Regression test for https://github.com/zulip/zulip-flutter/issues/1469
1704+
final message = eg.streamMessage(topic: 'some topic');
16791705
await setupToMessageActionSheet(tester, message: message, narrow: ChannelNarrow(message.streamId));
16801706

16811707
final composeBoxController = findComposeBoxController(tester) as StreamComposeBoxController;
@@ -1685,7 +1711,7 @@ void main() {
16851711
connection.prepare(body:
16861712
jsonEncode(GetStreamTopicsResult(topics: [eg.getStreamTopicsEntry()]).toJson()));
16871713
final topicController = composeBoxController.topic;
1688-
topicController.value = const TextEditingValue(text: kNoTopicTopic);
1714+
topicController.value = const TextEditingValue(text: '');
16891715

16901716
final valueBefore = contentController.value;
16911717
prepareRawContentResponseSuccess(message: message, rawContent: 'Hello world');
@@ -1695,6 +1721,7 @@ void main() {
16951721
check(composeBoxController.contentFocusNode.hasFocus).isTrue();
16961722
checkSuccessState(store, contentController,
16971723
valueBefore: valueBefore, message: message, rawContent: 'Hello world');
1724+
check(topicController).textNormalized.equals('some topic');
16981725
});
16991726

17001727
group('in topic narrow', () {

0 commit comments

Comments
 (0)