Skip to content

Commit

Permalink
compose: Use alternative placeholder if topics are mandatory and missing
Browse files Browse the repository at this point in the history
Previously, the placeholder reads "#channel name > (no topic)" even if
topics are mandatory for the realm.  Later, we will expand this logic
for "general chat" so that the placeholder is chosen depending on
whether topics are mandatory.

Signed-off-by: Zixuan James Li <zixuan@zulip.com>
  • Loading branch information
PIG208 committed Feb 20, 2025
1 parent 152812c commit 1ea0fcd
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 6 deletions.
13 changes: 11 additions & 2 deletions lib/widgets/compose_box.dart
Original file line number Diff line number Diff line change
Expand Up @@ -588,12 +588,21 @@ class _StreamContentInputState extends State<_StreamContentInput> {
final streamName = store.streams[widget.narrow.streamId]?.name
?? zulipLocalizations.unknownChannelName;
final topic = TopicName(_topicTextNormalized);
final String? topicDisplayName;
if (store.realmMandatoryTopics && widget.controller.topic.isTopicVacuous) {
topicDisplayName = null;
} else {
topicDisplayName = topic.displayName;
}

return _ContentInput(
narrow: widget.narrow,
destination: TopicNarrow(widget.narrow.streamId, topic),
controller: widget.controller,
hintText: zulipLocalizations.composeBoxChannelContentHint(
'#$streamName > ${topic.displayName}'));
hintText: topicDisplayName == null
? zulipLocalizations.composeBoxChannelContentHint('#$streamName')
: zulipLocalizations.composeBoxChannelContentHint(
'#$streamName > $topicDisplayName'));
}
}

Expand Down
33 changes: 29 additions & 4 deletions test/widgets/compose_box_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -326,11 +326,13 @@ void main() {

Future<void> prepare(WidgetTester tester, {
required Narrow narrow,
bool? mandatoryTopics,
}) async {
await prepareComposeBox(tester,
narrow: narrow,
otherUsers: [eg.otherUser, eg.thirdUser],
streams: [channel]);
streams: [channel],
mandatoryTopics: mandatoryTopics);
}

/// This checks the input's configured hint text without regard to whether
Expand All @@ -351,17 +353,40 @@ void main() {
.decoration.isNotNull().hintText.equals(contentHintText);
}

group('to ChannelNarrow', () {
group('to ChannelNarrow, topics not mandatory', () {
testWidgets('with empty topic', (tester) async {
await prepare(tester, narrow: ChannelNarrow(channel.streamId));
await prepare(tester, narrow: ChannelNarrow(channel.streamId),
mandatoryTopics: false);
checkComposeBoxHintTexts(tester,
topicHintText: 'Topic',
contentHintText: 'Message #${channel.name} > (no topic)');
});

testWidgets('with non-empty topic', (tester) async {
final narrow = ChannelNarrow(channel.streamId);
await prepare(tester, narrow: narrow);
await prepare(tester, narrow: narrow,
mandatoryTopics: false);
await enterTopic(tester, narrow: narrow, topic: 'new topic');
await tester.pump();
checkComposeBoxHintTexts(tester,
topicHintText: 'Topic',
contentHintText: 'Message #${channel.name} > new topic');
});
});

group('to ChannelNarrow, mandatory topics', () {
testWidgets('with empty topic', (tester) async {
await prepare(tester, narrow: ChannelNarrow(channel.streamId),
mandatoryTopics: true);
checkComposeBoxHintTexts(tester,
topicHintText: 'Topic',
contentHintText: 'Message #${channel.name}');
});

testWidgets('with non-empty topic', (tester) async {
final narrow = ChannelNarrow(channel.streamId);
await prepare(tester, narrow: narrow,
mandatoryTopics: true);
await enterTopic(tester, narrow: narrow, topic: 'new topic');
await tester.pump();
checkComposeBoxHintTexts(tester,
Expand Down

0 comments on commit 1ea0fcd

Please sign in to comment.