Skip to content
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

Fetch older messages on scrolling up in message list #264

Merged
merged 14 commits into from
Aug 14, 2023
Merged
Changes from 1 commit
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
62 changes: 33 additions & 29 deletions test/widgets/message_list_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'package:flutter_test/flutter_test.dart';
import 'package:zulip/api/model/events.dart';
import 'package:zulip/api/model/model.dart';
import 'package:zulip/model/narrow.dart';
import 'package:zulip/model/store.dart';
import 'package:zulip/widgets/content.dart';
import 'package:zulip/widgets/message_list.dart';
import 'package:zulip/widgets/sticky_header.dart';
Expand All @@ -19,39 +20,42 @@ import '../model/test_store.dart';
import '../test_images.dart';
import 'content_checks.dart';

Future<void> setupMessageListPage(WidgetTester tester, {
Narrow narrow = const AllMessagesNarrow(),
}) async {
addTearDown(TestZulipBinding.instance.reset);
addTearDown(tester.view.resetPhysicalSize);
void main() {
TestZulipBinding.ensureInitialized();

tester.view.physicalSize = const Size(600, 800);
late PerAccountStore store;
late FakeApiConnection connection;

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;
Future<void> setupMessageListPage(WidgetTester tester, {
Narrow narrow = const AllMessagesNarrow(),
}) async {
addTearDown(TestZulipBinding.instance.reset);
addTearDown(tester.view.resetPhysicalSize);

// prepare message list data
store.addUser(eg.selfUser);
final List<StreamMessage> messages = List.generate(10, (index) {
return eg.streamMessage(id: index, sender: eg.selfUser);
});
connection.prepare(json:
newestResult(foundOldest: true, 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();
}
tester.view.physicalSize = const Size(600, 800);

void main() {
TestZulipBinding.ensureInitialized();
await TestZulipBinding.instance.globalStore.add(eg.selfAccount, eg.initialSnapshot());
store = await TestZulipBinding.instance.globalStore.perAccount(eg.selfAccount.id);
connection = store.connection as FakeApiConnection;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

msglist test [nfc]: Use shared store/connection variables in widget tests

In particular this will allow individual test cases to call
`connection.prepare` for setting up further API responses.

Hmm, couldn't this make it easier for problematic state leakage between tests to happen?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In principle this sort of thing can. The key is that all of the shared variables get reset at the start of each test, by doing so in this one central helper function that each test calls at the start.

This is similar to what was done in #260. Like there, the alternative for getting similar functionality but with full encapsulation between tests would be to put things on a class and have each test make its own instance of the class.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense.


// prepare message list data
store.addUser(eg.selfUser);
final List<StreamMessage> messages = List.generate(10, (index) {
return eg.streamMessage(id: index, sender: eg.selfUser);
});
connection.prepare(json:
newestResult(foundOldest: true, 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();
}

group('ScrollToBottomButton interactions', () {
ScrollController? findMessageListScrollController(WidgetTester tester) {
Expand Down