Skip to content

Commit 7be2ac4

Browse files
committed
compose: Handle hint texts when topic is empty
Signed-off-by: Zixuan James Li <[email protected]>
1 parent 04a8340 commit 7be2ac4

File tree

2 files changed

+42
-7
lines changed

2 files changed

+42
-7
lines changed

lib/widgets/compose_box.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,8 @@ class _StreamContentInputState extends State<_StreamContentInput> {
593593
if (store.realmMandatoryTopics && widget.controller.topic.isTopicVacuous) {
594594
topicDisplayName = null;
595595
} else {
596-
topicDisplayName = topic.displayName;
596+
// ignore: dead_null_aware_expression // null topic names soon to be enabled
597+
topicDisplayName = topic.displayName ?? store.realmEmptyTopicDisplayName;
597598
}
598599

599600
return _ContentInput(
@@ -662,7 +663,8 @@ class _FixedDestinationContentInput extends StatelessWidget {
662663
final streamName = store.streams[streamId]?.name
663664
?? zulipLocalizations.unknownChannelName;
664665
return zulipLocalizations.composeBoxChannelTopicContentHint(
665-
'#$streamName > ${topic.displayName}');
666+
// ignore: dead_null_aware_expression // null topic names soon to be enabled
667+
'#$streamName > ${topic.displayName ?? store.realmEmptyTopicDisplayName}');
666668

667669
case DmNarrow(otherRecipientIds: []): // The self-1:1 thread.
668670
return zulipLocalizations.composeBoxSelfDmContentHint;

test/widgets/compose_box_test.dart

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,18 @@ void main() {
4747
List<User> otherUsers = const [],
4848
List<ZulipStream> streams = const [],
4949
bool? mandatoryTopics,
50+
int? zulipFeatureLevel,
5051
}) async {
5152
if (narrow case ChannelNarrow(:var streamId) || TopicNarrow(: var streamId)) {
5253
assert(streams.any((stream) => stream.streamId == streamId),
5354
'Add a channel with "streamId" the same as of $narrow.streamId to the store.');
5455
}
5556
addTearDown(testBinding.reset);
5657
selfUser ??= eg.selfUser;
57-
final selfAccount = eg.account(user: selfUser);
58+
zulipFeatureLevel ??= eg.futureZulipFeatureLevel;
59+
final selfAccount = eg.account(user: selfUser, zulipFeatureLevel: zulipFeatureLevel);
5860
await testBinding.globalStore.add(selfAccount, eg.initialSnapshot(
61+
zulipFeatureLevel: zulipFeatureLevel,
5962
realmMandatoryTopics: mandatoryTopics,
6063
));
6164

@@ -327,12 +330,14 @@ void main() {
327330
Future<void> prepare(WidgetTester tester, {
328331
required Narrow narrow,
329332
bool? mandatoryTopics,
333+
int? zulipFeatureLevel,
330334
}) async {
331335
await prepareComposeBox(tester,
332336
narrow: narrow,
333337
otherUsers: [eg.otherUser, eg.thirdUser],
334338
streams: [channel],
335-
mandatoryTopics: mandatoryTopics);
339+
mandatoryTopics: mandatoryTopics,
340+
zulipFeatureLevel: zulipFeatureLevel);
336341
}
337342

338343
/// This checks the input's configured hint text without regard to whether
@@ -355,8 +360,18 @@ void main() {
355360

356361
group('to ChannelNarrow, topics not mandatory', () {
357362
testWidgets('with empty topic', (tester) async {
363+
final narrow = ChannelNarrow(channel.streamId);
364+
await prepare(tester, narrow: narrow, mandatoryTopics: false);
365+
await tester.pump();
366+
checkComposeBoxHintTexts(tester,
367+
topicHintText: 'Topic',
368+
contentHintText: 'Message #${channel.name} > ${eg.defaultRealmEmptyTopicDisplayName}');
369+
}, skip: true); // null topic names soon to be enabled
370+
371+
testWidgets('legacy: with empty topic', (tester) async {
358372
await prepare(tester, narrow: ChannelNarrow(channel.streamId),
359-
mandatoryTopics: false);
373+
mandatoryTopics: false,
374+
zulipFeatureLevel: 333);
360375
checkComposeBoxHintTexts(tester,
361376
topicHintText: 'Topic',
362377
contentHintText: 'Message #${channel.name} > (no topic)');
@@ -381,6 +396,15 @@ void main() {
381396
checkComposeBoxHintTexts(tester,
382397
topicHintText: 'Topic',
383398
contentHintText: 'Message #${channel.name}');
399+
}, skip: true); // null topic names soon to be enabled
400+
401+
testWidgets('legacy: with empty topic', (tester) async {
402+
await prepare(tester, narrow: ChannelNarrow(channel.streamId),
403+
mandatoryTopics: true,
404+
zulipFeatureLevel: 333);
405+
checkComposeBoxHintTexts(tester,
406+
topicHintText: 'Topic',
407+
contentHintText: 'Message #${channel.name}');
384408
});
385409

386410
testWidgets('with non-empty topic', (tester) async {
@@ -395,13 +419,22 @@ void main() {
395419
});
396420
});
397421

398-
testWidgets('to TopicNarrow', (tester) async {
422+
testWidgets('to TopicNarrow with non-empty topic', (tester) async {
399423
await prepare(tester,
400-
narrow: TopicNarrow(channel.streamId, TopicName('topic')));
424+
narrow: TopicNarrow(channel.streamId, TopicName('topic')),
425+
mandatoryTopics: false);
401426
checkComposeBoxHintTexts(tester,
402427
contentHintText: 'Message #${channel.name} > topic');
403428
});
404429

430+
testWidgets('to TopicNarrow with empty topic', (tester) async {
431+
await prepare(tester,
432+
narrow: TopicNarrow(channel.streamId, TopicName('')),
433+
mandatoryTopics: false);
434+
checkComposeBoxHintTexts(tester, contentHintText:
435+
'Message #${channel.name} > ${eg.defaultRealmEmptyTopicDisplayName}');
436+
}, skip: true); // null topic names soon to be enabled
437+
405438
testWidgets('to DmNarrow with self', (tester) async {
406439
await prepare(tester, narrow: DmNarrow.withUser(
407440
eg.selfUser.userId, selfUserId: eg.selfUser.userId));

0 commit comments

Comments
 (0)