Skip to content

example_data [nfc]: Move {newest,older}Result #1053

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 1 commit into from
Nov 14, 2024
Merged
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
3 changes: 1 addition & 2 deletions integration_test/unreadmarker_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import 'package:zulip/widgets/message_list.dart';
import '../test/api/fake_api.dart';
import '../test/example_data.dart' as eg;
import '../test/model/binding.dart';
import '../test/model/message_list_test.dart';
import '../test/widgets/test_app.dart';

void main() {
Expand All @@ -29,7 +28,7 @@ void main() {
final messages = List.generate(messageCount,
(i) => eg.streamMessage(flags: [MessageFlag.read]));
connection.prepare(json:
newestResult(foundOldest: true, messages: messages).toJson());
eg.newestGetMessagesResult(foundOldest: true, messages: messages).toJson());

await tester.pumpWidget(TestZulipApp(accountId: eg.selfAccount.id,
child: const MessageListPage(initNarrow: CombinedFeedNarrow())));
Expand Down
38 changes: 38 additions & 0 deletions test/example_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:zulip/api/model/events.dart';
import 'package:zulip/api/model/initial_snapshot.dart';
import 'package:zulip/api/model/model.dart';
import 'package:zulip/api/model/submessage.dart';
import 'package:zulip/api/route/messages.dart';
import 'package:zulip/api/route/realm.dart';
import 'package:zulip/api/route/channels.dart';
import 'package:zulip/model/narrow.dart';
Expand Down Expand Up @@ -451,6 +452,43 @@ DmMessage dmMessage({
}) as Map<String, dynamic>);
}

/// A GetMessagesResult the server might return on an `anchor=newest` request.
GetMessagesResult newestGetMessagesResult({
required bool foundOldest,
bool historyLimited = false,
required List<Message> messages,
}) {
return GetMessagesResult(
// These anchor, foundAnchor, and foundNewest values are what the server
// appears to always return when the request had `anchor=newest`.
anchor: 10000000000000000, // that's 16 zeros
foundAnchor: false,
foundNewest: true,

foundOldest: foundOldest,
historyLimited: historyLimited,
messages: messages,
);
}

/// A GetMessagesResult the server might return when we request older messages.
GetMessagesResult olderGetMessagesResult({
required int anchor,
bool foundAnchor = false, // the value if the server understood includeAnchor false
required bool foundOldest,
bool historyLimited = false,
required List<Message> messages,
}) {
return GetMessagesResult(
anchor: anchor,
foundAnchor: foundAnchor,
foundNewest: false, // empirically always this, even when anchor happens to be latest
foundOldest: foundOldest,
historyLimited: historyLimited,
messages: messages,
);
}

PollWidgetData pollWidgetData({
required String question,
required List<String> options,
Expand Down
41 changes: 3 additions & 38 deletions test/model/message_list_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import 'package:test/scaffolding.dart';
import 'package:zulip/api/model/events.dart';
import 'package:zulip/api/model/model.dart';
import 'package:zulip/api/model/narrow.dart';
import 'package:zulip/api/route/messages.dart';
import 'package:zulip/model/algorithms.dart';
import 'package:zulip/model/content.dart';
import 'package:zulip/model/message_list.dart';
Expand All @@ -22,6 +21,9 @@ import 'content_checks.dart';
import 'recent_senders_test.dart' as recent_senders_test;
import 'test_store.dart';

const newestResult = eg.newestGetMessagesResult;
const olderResult = eg.olderGetMessagesResult;

void main() {
// These variables are the common state operated on by each test.
// Each test case calls [prepare] to initialize them.
Expand Down Expand Up @@ -1848,40 +1850,3 @@ extension MessageListViewChecks on Subject<MessageListView> {
Subject<bool> get haveOldest => has((x) => x.haveOldest, 'haveOldest');
Subject<bool> get fetchingOlder => has((x) => x.fetchingOlder, 'fetchingOlder');
}

/// A GetMessagesResult the server might return on an `anchor=newest` request.
GetMessagesResult newestResult({
required bool foundOldest,
bool historyLimited = false,
required List<Message> messages,
}) {
return GetMessagesResult(
// These anchor, foundAnchor, and foundNewest values are what the server
// appears to always return when the request had `anchor=newest`.
anchor: 10000000000000000, // that's 16 zeros
foundAnchor: false,
foundNewest: true,

foundOldest: foundOldest,
historyLimited: historyLimited,
messages: messages,
);
}

/// A GetMessagesResult the server might return when we request older messages.
GetMessagesResult olderResult({
required int anchor,
bool foundAnchor = false, // the value if the server understood includeAnchor false
required bool foundOldest,
bool historyLimited = false,
required List<Message> messages,
}) {
return GetMessagesResult(
anchor: anchor,
foundAnchor: foundAnchor,
foundNewest: false, // empirically always this, even when anchor happens to be latest
foundOldest: foundOldest,
historyLimited: historyLimited,
messages: messages,
);
}
4 changes: 2 additions & 2 deletions test/model/message_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ void main() {
}) async {
assert(messages.every((message) => message.poll == null));
connection.prepare(json:
newestResult(foundOldest: foundOldest, messages: messages).toJson());
eg.newestGetMessagesResult(foundOldest: foundOldest, messages: messages).toJson());
await messageList.fetchInitial();
checkNotifiedOnce();
}
Expand Down Expand Up @@ -645,7 +645,7 @@ void main() {
// Perform a single-message initial message fetch for [messageList] with
// submessages.
connection.prepare(json:
newestResult(foundOldest: true, messages: []).toJson()
eg.newestGetMessagesResult(foundOldest: true, messages: []).toJson()
..['messages'] = [{
...message.toJson(),
"submessages": submessages.map(deepToJson).toList(),
Expand Down
5 changes: 2 additions & 3 deletions test/widgets/action_sheet_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import '../api/fake_api.dart';
import '../example_data.dart' as eg;
import '../flutter_checks.dart';
import '../model/binding.dart';
import '../model/message_list_test.dart';
import '../model/test_store.dart';
import '../stdlib_checks.dart';
import '../test_clipboard.dart';
Expand Down Expand Up @@ -55,7 +54,7 @@ Future<void> setupToMessageActionSheet(WidgetTester tester, {
}
connection = store.connection as FakeApiConnection;

connection.prepare(json: newestResult(
connection.prepare(json: eg.newestGetMessagesResult(
foundOldest: true, messages: [message]).toJson());
await tester.pumpWidget(TestZulipApp(accountId: eg.selfAccount.id,
child: MessageListPage(initNarrow: narrow)));
Expand Down Expand Up @@ -443,7 +442,7 @@ void main() {
// it doesn't matter anyway: [MessageStoreImpl.reconcileMessages] will
// keep the version updated by the event. If that somehow changes in
// some future refactor, it'll cause this test to fail.
connection.prepare(json: newestResult(
connection.prepare(json: eg.newestGetMessagesResult(
foundOldest: true, messages: [message]).toJson());
await store.handleEvent(eg.updateMessageEventMoveFrom(
newStreamId: newStream.streamId, newTopic: newTopic,
Expand Down
11 changes: 5 additions & 6 deletions test/widgets/message_list_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import '../api/fake_api.dart';
import '../example_data.dart' as eg;
import '../model/binding.dart';
import '../model/content_test.dart';
import '../model/message_list_test.dart';
import '../model/test_store.dart';
import '../flutter_checks.dart';
import '../stdlib_checks.dart';
Expand Down Expand Up @@ -70,7 +69,7 @@ void main() {
return eg.streamMessage(sender: eg.selfUser);
});
connection.prepare(json:
newestResult(foundOldest: foundOldest, messages: messages).toJson());
eg.newestGetMessagesResult(foundOldest: foundOldest, messages: messages).toJson());

await tester.pumpWidget(TestZulipApp(accountId: eg.selfAccount.id,
child: MessageListPage(initNarrow: narrow)));
Expand Down Expand Up @@ -189,7 +188,7 @@ void main() {
await tester.pump();

// ... and we should fetch more messages as we go.
connection.prepare(json: olderResult(anchor: 950, foundOldest: false,
connection.prepare(json: eg.olderGetMessagesResult(anchor: 950, foundOldest: false,
messages: List.generate(100, (i) => eg.streamMessage(id: 850 + i, sender: eg.selfUser))).toJson());
await tester.pump(const Duration(seconds: 3)); // Fast-forward to end of fling.
await tester.pump(Duration.zero); // Allow a frame for the response to arrive.
Expand All @@ -208,7 +207,7 @@ void main() {
await tester.pump();

// ... and we fetch more messages as we go.
connection.prepare(json: olderResult(anchor: 950, foundOldest: false,
connection.prepare(json: eg.olderGetMessagesResult(anchor: 950, foundOldest: false,
messages: List.generate(100, (i) => eg.streamMessage(id: 850 + i, sender: eg.selfUser))).toJson());
for (int i = 0; i < 30; i++) {
// Find the point in the fling where the fetch starts.
Expand All @@ -220,7 +219,7 @@ void main() {

// On the next frame, we promptly fetch *another* batch.
// This is a glitch and it'd be nicer if we didn't.
connection.prepare(json: olderResult(anchor: 850, foundOldest: false,
connection.prepare(json: eg.olderGetMessagesResult(anchor: 850, foundOldest: false,
messages: List.generate(100, (i) => eg.streamMessage(id: 750 + i, sender: eg.selfUser))).toJson());
await tester.pump(const Duration(milliseconds: 1));
await tester.pump(Duration.zero);
Expand Down Expand Up @@ -619,7 +618,7 @@ void main() {
final narrow = TopicNarrow(channel.streamId, topic);

void prepareGetMessageResponse(List<Message> messages) {
connection.prepare(json: newestResult(
connection.prepare(json: eg.newestGetMessagesResult(
foundOldest: false, messages: messages).toJson());
}

Expand Down