Skip to content

msglist: Fix channel header tap behaviour in multi-channel narrows #1370

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/widgets/message_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1082,6 +1082,7 @@ class StreamMessageRecipientHeader extends StatelessWidget {
?? zulipLocalizations.unknownChannelName; // TODO(log)

streamWidget = GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: () => Navigator.push(context,
MessageListPage.buildRoute(context: context,
narrow: ChannelNarrow(message.streamId))),
Expand Down
103 changes: 103 additions & 0 deletions test/widgets/message_list_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1470,4 +1470,107 @@ void main() {
..status.equals(AnimationStatus.dismissed);
});
});

group('recipient header navigation in multi-channel narrows', () {
late List<Route<void>> pushedRoutes;

final channel = eg.stream();
const testTopic = 'testTopic';
final message = eg.streamMessage(stream: channel, topic: testTopic);

final recipientHeaderFinder = find.byType(StreamMessageRecipientHeader);
late Rect recipientHeaderRect;

Future<void> prepare(WidgetTester tester) async {
pushedRoutes = [];
final navObserver = TestNavigatorObserver()
..onPushed = (route, prevRoute) => pushedRoutes.add(route);

await setupMessageListPage(tester,
narrow: const CombinedFeedNarrow(),
streams: [channel],
subscriptions: [eg.subscription(channel)],
messages: [message],
navObservers: [navObserver]);

assert(pushedRoutes.length == 1);
pushedRoutes.clear();

recipientHeaderRect = tester.getRect(recipientHeaderFinder);
}

// Regression test for: https://github.com/zulip/zulip-flutter/issues/1179
testWidgets("navigates to ChannelNarrow when tapping above or below channel name in recipient header", (tester) async {
await prepare(tester);

final channelNameFinder = find.descendant(
of: recipientHeaderFinder,
matching: find.text(channel.name));
final channelNameRect = tester.getRect(channelNameFinder);

connection.prepare(json: eg.newestGetMessagesResult(
foundOldest: true, messages: [message]).toJson());
// Tap just right below the top of recipient header, above and outside of
// its channel name component.
await tester.tapAt(Offset(
channelNameRect.center.dx, recipientHeaderRect.top + 1));
await tester.pump();
check(pushedRoutes).single.isA<WidgetRoute>().page.isA<MessageListPage>()
.initNarrow.equals(ChannelNarrow(channel.streamId));
await tester.pumpAndSettle();

// Navigate back to original page and clear routes.
await tester.pageBack();
await tester.pumpAndSettle();
pushedRoutes.clear();

connection.prepare(json: eg.newestGetMessagesResult(
foundOldest: true, messages: [message]).toJson());
// Tap just above the bottom of recipient header, below and outside of
// its channel name component.
await tester.tapAt(Offset(
channelNameRect.center.dx, recipientHeaderRect.bottom - 1));
await tester.pump();
check(pushedRoutes).single.isA<WidgetRoute>().page.isA<MessageListPage>()
.initNarrow.equals(ChannelNarrow(channel.streamId));
await tester.pumpAndSettle();
});

// Regression test for: https://github.com/zulip/zulip-flutter/issues/1179
testWidgets("navigates to TopicNarrow when tapping above or below topic name in recipient header", (tester) async {
await prepare(tester);

final topicNameFinder = find.descendant(
of: recipientHeaderFinder,
matching: find.text(testTopic));
final topicNameRect = tester.getRect(topicNameFinder);

connection.prepare(json: eg.newestGetMessagesResult(
foundOldest: true, messages: [message]).toJson());
// Tap just right below the top of recipient header, above and outside of
// its topic name component.
await tester.tapAt(Offset(
topicNameRect.center.dx, recipientHeaderRect.top + 1));
await tester.pump();
check(pushedRoutes).single.isA<WidgetRoute>().page.isA<MessageListPage>()
.initNarrow.equals(TopicNarrow(channel.streamId, message.topic));
await tester.pumpAndSettle();

// Navigate back to original page and clear routes.
await tester.pageBack();
await tester.pumpAndSettle();
pushedRoutes.clear();

connection.prepare(json: eg.newestGetMessagesResult(
foundOldest: true, messages: [message]).toJson());
// Tap just above the bottom of recipient header, below and outside of
// its topic name component.
await tester.tapAt(Offset(
topicNameRect.center.dx, recipientHeaderRect.bottom - 1));
await tester.pump();
check(pushedRoutes).single.isA<WidgetRoute>().page.isA<MessageListPage>()
.initNarrow.equals(TopicNarrow(channel.streamId, message.topic));
await tester.pumpAndSettle();
});
});
}