Skip to content

Commit

Permalink
example_data [nfc]: Move {newest,older}Result
Browse files Browse the repository at this point in the history
Shared by a few tests, they fit better in example_data.

Signed-off-by: Zixuan James Li <[email protected]>
  • Loading branch information
PIG208 committed Nov 7, 2024
1 parent cdce570 commit d2a9f91
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 89 deletions.
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.newestResult(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 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,
);
}

PollWidgetData pollWidgetData({
required String question,
required List<String> options,
Expand Down
Loading

0 comments on commit d2a9f91

Please sign in to comment.