Skip to content

Commit 51616bd

Browse files
PIG208gnprice
authored andcommitted
action_sheet [nfc]: Hide resolve/unresolve button for empty topic
While this appears to be a user facing change, it's not visible yet, not until TopicName.displayName becomes nullable. This is a part of a series of changes to handle empty topics. Signed-off-by: Zixuan James Li <[email protected]>
1 parent f036308 commit 51616bd

File tree

2 files changed

+27
-8
lines changed

2 files changed

+27
-8
lines changed

lib/widgets/action_sheet.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,11 @@ void showTopicActionSheet(BuildContext context, {
300300
pageContext: pageContext);
301301
}));
302302

303-
if (someMessageIdInTopic != null) {
303+
// TODO: check for other cases that may disallow this action (e.g.: time
304+
// limit for editing topics).
305+
if (someMessageIdInTopic != null
306+
// ignore: unnecessary_null_comparison // null topic names soon to be enabled
307+
&& topic.displayName != null) {
304308
optionButtons.add(ResolveUnresolveButton(pageContext: pageContext,
305309
topic: topic,
306310
someMessageIdInTopic: someMessageIdInTopic));

test/widgets/action_sheet_test.dart

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -353,24 +353,27 @@ void main() {
353353

354354
Future<void> showFromAppBar(WidgetTester tester, {
355355
ZulipStream? channel,
356-
String topic = someTopic,
356+
TopicName? topic,
357357
List<StreamMessage>? messages,
358358
}) async {
359359
final effectiveChannel = channel ?? someChannel;
360+
final effectiveTopic = topic ?? TopicName(someTopic);
360361
final effectiveMessages = messages ?? [someMessage];
361-
assert(effectiveMessages.every((m) => m.topic.apiName == topic));
362+
assert(effectiveMessages.every((m) => m.topic.apiName == effectiveTopic.apiName));
362363

363364
connection.prepare(json: eg.newestGetMessagesResult(
364365
foundOldest: true, messages: effectiveMessages).toJson());
365366
await tester.pumpWidget(TestZulipApp(accountId: eg.selfAccount.id,
366367
child: MessageListPage(
367-
initNarrow: eg.topicNarrow(effectiveChannel.streamId, topic))));
368+
initNarrow: TopicNarrow(effectiveChannel.streamId, effectiveTopic))));
368369
// global store, per-account store, and message list get loaded
369370
await tester.pumpAndSettle();
370371

371372
final topicRow = find.descendant(
372373
of: find.byType(ZulipAppBar),
373-
matching: find.text(topic));
374+
matching: find.text(
375+
// ignore: dead_null_aware_expression // null topic names soon to be enabled
376+
effectiveTopic.displayName ?? eg.defaultRealmEmptyTopicDisplayName));
374377
await tester.longPress(topicRow);
375378
// sheet appears onscreen; default duration of bottom-sheet enter animation
376379
await tester.pump(const Duration(milliseconds: 250));
@@ -446,6 +449,16 @@ void main() {
446449
check(findButtonForLabel('Mark as unresolved')).findsNothing();
447450
});
448451

452+
testWidgets('show from app bar: resolve/unresolve not offered when topic is empty', (tester) async {
453+
await prepare();
454+
final message = eg.streamMessage(stream: someChannel, topic: '');
455+
await showFromAppBar(tester,
456+
topic: TopicName(''),
457+
messages: [message]);
458+
check(findButtonForLabel('Mark as resolved')).findsNothing();
459+
check(findButtonForLabel('Mark as unresolved')).findsNothing();
460+
}, skip: true); // null topic names soon to be enabled
461+
449462
testWidgets('show from recipient header', (tester) async {
450463
await prepare();
451464
await showFromRecipientHeader(tester);
@@ -485,7 +498,7 @@ void main() {
485498
final message = eg.streamMessage(
486499
stream: someChannel, topic: topic, sender: eg.otherUser);
487500
await showFromAppBar(tester,
488-
channel: someChannel, topic: topic, messages: [message]);
501+
channel: someChannel, topic: TopicName(topic), messages: [message]);
489502
}
490503

491504
void checkButtons(List<Finder> expectedButtonFinders) {
@@ -697,7 +710,8 @@ void main() {
697710
testWidgets('unresolve: happy path', (tester) async {
698711
final message = eg.streamMessage(stream: someChannel, topic: '✔ zulip');
699712
await prepare(topic: '✔ zulip');
700-
await showFromAppBar(tester, topic: '✔ zulip', messages: [message]);
713+
await showFromAppBar(tester,
714+
topic: TopicName('✔ zulip'), messages: [message]);
701715
connection.takeRequests();
702716
connection.prepare(json: UpdateMessageResult().toJson());
703717
await tester.tap(findButtonForLabel('Mark as unresolved'));
@@ -710,7 +724,8 @@ void main() {
710724
testWidgets('unresolve: weird prefix', (tester) async {
711725
final message = eg.streamMessage(stream: someChannel, topic: '✔ ✔ zulip');
712726
await prepare(topic: '✔ ✔ zulip');
713-
await showFromAppBar(tester, topic: '✔ ✔ zulip', messages: [message]);
727+
await showFromAppBar(tester,
728+
topic: TopicName('✔ ✔ zulip'), messages: [message]);
714729
connection.takeRequests();
715730
connection.prepare(json: UpdateMessageResult().toJson());
716731
await tester.tap(findButtonForLabel('Mark as unresolved'));

0 commit comments

Comments
 (0)