-
Notifications
You must be signed in to change notification settings - Fork 309
msglist: add scroll-to-bottom button to MessageList #223
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
import 'package:checks/checks.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:zulip/api/model/model.dart'; | ||
import 'package:zulip/api/route/messages.dart'; | ||
import 'package:zulip/model/narrow.dart'; | ||
import 'package:zulip/widgets/message_list.dart'; | ||
import 'package:zulip/widgets/sticky_header.dart'; | ||
import 'package:zulip/widgets/store.dart'; | ||
|
||
import '../api/fake_api.dart'; | ||
import '../example_data.dart' as eg; | ||
import '../model/binding.dart'; | ||
|
||
Future<void> setupMessageListPage(WidgetTester tester, { | ||
required Narrow narrow, | ||
}) async { | ||
addTearDown(TestZulipBinding.instance.reset); | ||
addTearDown(tester.view.resetPhysicalSize); | ||
|
||
tester.view.physicalSize = const Size(600, 800); | ||
|
||
await TestZulipBinding.instance.globalStore.add(eg.selfAccount, eg.initialSnapshot()); | ||
final store = await TestZulipBinding.instance.globalStore.perAccount(eg.selfAccount.id); | ||
final connection = store.connection as FakeApiConnection; | ||
|
||
// prepare message list data | ||
final List<StreamMessage> messages = List.generate(10, (index) { | ||
return eg.streamMessage(id: index); | ||
}); | ||
connection.prepare(json: GetMessagesResult( | ||
anchor: messages[0].id, | ||
foundNewest: true, | ||
foundOldest: true, | ||
foundAnchor: true, | ||
historyLimited: false, | ||
messages: messages, | ||
).toJson()); | ||
|
||
await tester.pumpWidget( | ||
MaterialApp( | ||
home: GlobalStoreWidget( | ||
child: PerAccountStoreWidget( | ||
accountId: eg.selfAccount.id, | ||
child: MessageListPage(narrow: narrow))))); | ||
|
||
// global store, per-account store, and message list get loaded | ||
await tester.pumpAndSettle(); | ||
} | ||
|
||
void main() { | ||
TestZulipBinding.ensureInitialized(); | ||
|
||
group('ScrollToBottomButton interactions', () { | ||
ScrollController? findMessageListScrollController(WidgetTester tester) { | ||
final stickyHeaderListView = tester.widget<StickyHeaderListView>(find.byType(StickyHeaderListView)); | ||
return stickyHeaderListView.controller; | ||
} | ||
|
||
bool isButtonVisible(WidgetTester tester) { | ||
return tester.any(find.descendant( | ||
of: find.byType(ScrollToBottomButton), | ||
matching: find.byTooltip("Scroll to bottom"))); | ||
} | ||
|
||
testWidgets('scrolling changes visibility', (WidgetTester tester) async { | ||
final stream = eg.stream(); | ||
await setupMessageListPage(tester, narrow: StreamNarrow(stream.streamId)); | ||
|
||
final scrollController = findMessageListScrollController(tester)!; | ||
|
||
// Initial state should be not visible, as the message list renders with latest message in view | ||
check(isButtonVisible(tester)).equals(false); | ||
|
||
scrollController.jumpTo(600); | ||
await tester.pump(); | ||
check(isButtonVisible(tester)).equals(true); | ||
|
||
scrollController.jumpTo(0); | ||
await tester.pump(); | ||
check(isButtonVisible(tester)).equals(false); | ||
}); | ||
|
||
testWidgets('dimension updates changes visibility', (WidgetTester tester) async { | ||
final stream = eg.stream(); | ||
await setupMessageListPage(tester, narrow: StreamNarrow(stream.streamId)); | ||
|
||
final scrollController = findMessageListScrollController(tester)!; | ||
|
||
// Initial state should be not visible, as the message list renders with latest message in view | ||
check(isButtonVisible(tester)).equals(false); | ||
|
||
scrollController.jumpTo(600); | ||
await tester.pump(); | ||
check(isButtonVisible(tester)).equals(true); | ||
|
||
tester.view.physicalSize = const Size(2000, 40000); | ||
await tester.pump(); | ||
// Dimension changes use NotificationListener<ScrollMetricsNotification | ||
// which has a one frame lag. If that ever gets resolved this extra pump | ||
// would ideally be removed | ||
await tester.pump(); | ||
check(isButtonVisible(tester)).equals(false); | ||
}); | ||
|
||
testWidgets('button functionality', (WidgetTester tester) async { | ||
final stream = eg.stream(); | ||
await setupMessageListPage(tester, narrow: StreamNarrow(stream.streamId)); | ||
|
||
final scrollController = findMessageListScrollController(tester)!; | ||
|
||
// Initial state should be not visible, as the message list renders with latest message in view | ||
check(isButtonVisible(tester)).equals(false); | ||
|
||
scrollController.jumpTo(600); | ||
await tester.pump(); | ||
check(isButtonVisible(tester)).equals(true); | ||
|
||
await tester.tap(find.byType(ScrollToBottomButton)); | ||
await tester.pumpAndSettle(); | ||
check(isButtonVisible(tester)).equals(false); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's check instead that the scroll controller's actual position is at the bottom — that way this test wouldn't accidentally pass if we introduced some bug where the button didn't actually work, but did cause the button to go away 🙂 |
||
check(scrollController.position.pixels).equals(0); | ||
}); | ||
}); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's have one more test case — testing that the button actually works :-)