Skip to content

Commit

Permalink
compose: Handle hint texts when topic is empty
Browse files Browse the repository at this point in the history
Signed-off-by: Zixuan James Li <zixuan@zulip.com>
  • Loading branch information
PIG208 committed Feb 21, 2025
1 parent f3f9712 commit 9cc8112
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 9 deletions.
13 changes: 11 additions & 2 deletions lib/widgets/compose_box.dart
Original file line number Diff line number Diff line change
Expand Up @@ -586,12 +586,20 @@ class _StreamContentInputState extends State<_StreamContentInput> {
final streamName = store.streams[widget.narrow.streamId]?.name
?? zulipLocalizations.unknownChannelName;
final topic = TopicName(widget.controller.topic.textNormalized);
final String? topicDisplayName;
if (store.realmMandatoryTopics && widget.controller.topic.isTopicVacuous) {
topicDisplayName = null;
} else {
// ignore: dead_null_aware_expression // null topic names soon to be enabled
topicDisplayName = topic.displayName ?? store.realmEmptyTopicDisplayName;
}

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

Expand Down Expand Up @@ -650,7 +658,8 @@ class _FixedDestinationContentInput extends StatelessWidget {
final streamName = store.streams[streamId]?.name
?? zulipLocalizations.unknownChannelName;
return zulipLocalizations.composeBoxChannelContentHint(
'#$streamName > ${topic.displayName}');
// ignore: dead_null_aware_expression // null topic names soon to be enabled
'#$streamName > ${topic.displayName ?? store.realmEmptyTopicDisplayName}');

case DmNarrow(otherRecipientIds: []): // The self-1:1 thread.
return zulipLocalizations.composeBoxSelfDmContentHint;
Expand Down
74 changes: 67 additions & 7 deletions test/widgets/compose_box_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,18 @@ void main() {
List<User> otherUsers = const [],
List<ZulipStream> streams = const [],
bool? mandatoryTopics,
int? zulipFeatureLevel,
}) async {
if (narrow case ChannelNarrow(:var streamId) || TopicNarrow(: var streamId)) {
assert(streams.any((stream) => stream.streamId == streamId),
'Add a channel with "streamId" the same as of $narrow.streamId to the store.');
}
addTearDown(testBinding.reset);
selfUser ??= eg.selfUser;
final selfAccount = eg.account(user: selfUser);
zulipFeatureLevel ??= eg.futureZulipFeatureLevel;
final selfAccount = eg.account(user: selfUser, zulipFeatureLevel: zulipFeatureLevel);
await testBinding.globalStore.add(selfAccount, eg.initialSnapshot(
zulipFeatureLevel: zulipFeatureLevel,
realmMandatoryTopics: mandatoryTopics,
));

Expand Down Expand Up @@ -326,11 +329,15 @@ void main() {

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

/// This checks the input's configured hint text without regard to whether
Expand All @@ -351,17 +358,31 @@ 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);
final narrow = ChannelNarrow(channel.streamId);
await prepare(tester, narrow: narrow, mandatoryTopics: false);
await tester.pump();
checkComposeBoxHintTexts(tester,
topicHintText: 'Topic',
contentHintText: 'Message #${channel.name} > ${eg.defaultRealmEmptyTopicDisplayName}');
}, skip: true); // null topic names soon to be enabled

testWidgets('legacy: with empty topic', (tester) async {
await prepare(tester, narrow: ChannelNarrow(channel.streamId),
mandatoryTopics: false,
zulipFeatureLevel: 333);
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,
Expand All @@ -370,13 +391,52 @@ void main() {
});
});

testWidgets('to TopicNarrow', (tester) async {
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}');
}, skip: true); // null topic names soon to be enabled

testWidgets('legacy: with empty topic', (tester) async {
await prepare(tester, narrow: ChannelNarrow(channel.streamId),
mandatoryTopics: true,
zulipFeatureLevel: 333);
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,
topicHintText: 'Topic',
contentHintText: 'Message #${channel.name} > new topic');
});
});

testWidgets('to TopicNarrow with non-empty topic', (tester) async {
await prepare(tester,
narrow: TopicNarrow(channel.streamId, TopicName('topic')));
narrow: TopicNarrow(channel.streamId, TopicName('topic')),
mandatoryTopics: false);
checkComposeBoxHintTexts(tester,
contentHintText: 'Message #${channel.name} > topic');
});

testWidgets('to TopicNarrow with empty topic', (tester) async {
await prepare(tester,
narrow: TopicNarrow(channel.streamId, TopicName('')),
mandatoryTopics: false);
checkComposeBoxHintTexts(tester, contentHintText:
'Message #${channel.name} > ${eg.defaultRealmEmptyTopicDisplayName}');
}, skip: true); // null topic names soon to be enabled

testWidgets('to DmNarrow with self', (tester) async {
await prepare(tester, narrow: DmNarrow.withUser(
eg.selfUser.userId, selfUserId: eg.selfUser.userId));
Expand Down

0 comments on commit 9cc8112

Please sign in to comment.