Skip to content

Commit cfd2a17

Browse files
PIG208gnprice
authored andcommitted
example_data [nfc]: Move {newest,older}Result and rename
Shared by a few tests, they fit better in example_data. Signed-off-by: Zixuan James Li <[email protected]>
1 parent 0344686 commit cfd2a17

File tree

6 files changed

+51
-51
lines changed

6 files changed

+51
-51
lines changed

integration_test/unreadmarker_test.dart

+1-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import 'package:zulip/widgets/message_list.dart';
99
import '../test/api/fake_api.dart';
1010
import '../test/example_data.dart' as eg;
1111
import '../test/model/binding.dart';
12-
import '../test/model/message_list_test.dart';
1312
import '../test/widgets/test_app.dart';
1413

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

3433
await tester.pumpWidget(TestZulipApp(accountId: eg.selfAccount.id,
3534
child: const MessageListPage(initNarrow: CombinedFeedNarrow())));

test/example_data.dart

+38
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import 'package:zulip/api/model/events.dart';
55
import 'package:zulip/api/model/initial_snapshot.dart';
66
import 'package:zulip/api/model/model.dart';
77
import 'package:zulip/api/model/submessage.dart';
8+
import 'package:zulip/api/route/messages.dart';
89
import 'package:zulip/api/route/realm.dart';
910
import 'package:zulip/api/route/channels.dart';
1011
import 'package:zulip/model/narrow.dart';
@@ -451,6 +452,43 @@ DmMessage dmMessage({
451452
}) as Map<String, dynamic>);
452453
}
453454

455+
/// A GetMessagesResult the server might return on an `anchor=newest` request.
456+
GetMessagesResult newestGetMessagesResult({
457+
required bool foundOldest,
458+
bool historyLimited = false,
459+
required List<Message> messages,
460+
}) {
461+
return GetMessagesResult(
462+
// These anchor, foundAnchor, and foundNewest values are what the server
463+
// appears to always return when the request had `anchor=newest`.
464+
anchor: 10000000000000000, // that's 16 zeros
465+
foundAnchor: false,
466+
foundNewest: true,
467+
468+
foundOldest: foundOldest,
469+
historyLimited: historyLimited,
470+
messages: messages,
471+
);
472+
}
473+
474+
/// A GetMessagesResult the server might return when we request older messages.
475+
GetMessagesResult olderGetMessagesResult({
476+
required int anchor,
477+
bool foundAnchor = false, // the value if the server understood includeAnchor false
478+
required bool foundOldest,
479+
bool historyLimited = false,
480+
required List<Message> messages,
481+
}) {
482+
return GetMessagesResult(
483+
anchor: anchor,
484+
foundAnchor: foundAnchor,
485+
foundNewest: false, // empirically always this, even when anchor happens to be latest
486+
foundOldest: foundOldest,
487+
historyLimited: historyLimited,
488+
messages: messages,
489+
);
490+
}
491+
454492
PollWidgetData pollWidgetData({
455493
required String question,
456494
required List<String> options,

test/model/message_list_test.dart

+3-38
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import 'package:test/scaffolding.dart';
66
import 'package:zulip/api/model/events.dart';
77
import 'package:zulip/api/model/model.dart';
88
import 'package:zulip/api/model/narrow.dart';
9-
import 'package:zulip/api/route/messages.dart';
109
import 'package:zulip/model/algorithms.dart';
1110
import 'package:zulip/model/content.dart';
1211
import 'package:zulip/model/message_list.dart';
@@ -22,6 +21,9 @@ import 'content_checks.dart';
2221
import 'recent_senders_test.dart' as recent_senders_test;
2322
import 'test_store.dart';
2423

24+
const newestResult = eg.newestGetMessagesResult;
25+
const olderResult = eg.olderGetMessagesResult;
26+
2527
void main() {
2628
// These variables are the common state operated on by each test.
2729
// Each test case calls [prepare] to initialize them.
@@ -1848,40 +1850,3 @@ extension MessageListViewChecks on Subject<MessageListView> {
18481850
Subject<bool> get haveOldest => has((x) => x.haveOldest, 'haveOldest');
18491851
Subject<bool> get fetchingOlder => has((x) => x.fetchingOlder, 'fetchingOlder');
18501852
}
1851-
1852-
/// A GetMessagesResult the server might return on an `anchor=newest` request.
1853-
GetMessagesResult newestResult({
1854-
required bool foundOldest,
1855-
bool historyLimited = false,
1856-
required List<Message> messages,
1857-
}) {
1858-
return GetMessagesResult(
1859-
// These anchor, foundAnchor, and foundNewest values are what the server
1860-
// appears to always return when the request had `anchor=newest`.
1861-
anchor: 10000000000000000, // that's 16 zeros
1862-
foundAnchor: false,
1863-
foundNewest: true,
1864-
1865-
foundOldest: foundOldest,
1866-
historyLimited: historyLimited,
1867-
messages: messages,
1868-
);
1869-
}
1870-
1871-
/// A GetMessagesResult the server might return when we request older messages.
1872-
GetMessagesResult olderResult({
1873-
required int anchor,
1874-
bool foundAnchor = false, // the value if the server understood includeAnchor false
1875-
required bool foundOldest,
1876-
bool historyLimited = false,
1877-
required List<Message> messages,
1878-
}) {
1879-
return GetMessagesResult(
1880-
anchor: anchor,
1881-
foundAnchor: foundAnchor,
1882-
foundNewest: false, // empirically always this, even when anchor happens to be latest
1883-
foundOldest: foundOldest,
1884-
historyLimited: historyLimited,
1885-
messages: messages,
1886-
);
1887-
}

test/model/message_test.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ void main() {
6565
}) async {
6666
assert(messages.every((message) => message.poll == null));
6767
connection.prepare(json:
68-
newestResult(foundOldest: foundOldest, messages: messages).toJson());
68+
eg.newestGetMessagesResult(foundOldest: foundOldest, messages: messages).toJson());
6969
await messageList.fetchInitial();
7070
checkNotifiedOnce();
7171
}
@@ -645,7 +645,7 @@ void main() {
645645
// Perform a single-message initial message fetch for [messageList] with
646646
// submessages.
647647
connection.prepare(json:
648-
newestResult(foundOldest: true, messages: []).toJson()
648+
eg.newestGetMessagesResult(foundOldest: true, messages: []).toJson()
649649
..['messages'] = [{
650650
...message.toJson(),
651651
"submessages": submessages.map(deepToJson).toList(),

test/widgets/action_sheet_test.dart

+2-3
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import '../api/fake_api.dart';
2626
import '../example_data.dart' as eg;
2727
import '../flutter_checks.dart';
2828
import '../model/binding.dart';
29-
import '../model/message_list_test.dart';
3029
import '../model/test_store.dart';
3130
import '../stdlib_checks.dart';
3231
import '../test_clipboard.dart';
@@ -55,7 +54,7 @@ Future<void> setupToMessageActionSheet(WidgetTester tester, {
5554
}
5655
connection = store.connection as FakeApiConnection;
5756

58-
connection.prepare(json: newestResult(
57+
connection.prepare(json: eg.newestGetMessagesResult(
5958
foundOldest: true, messages: [message]).toJson());
6059
await tester.pumpWidget(TestZulipApp(accountId: eg.selfAccount.id,
6160
child: MessageListPage(initNarrow: narrow)));
@@ -443,7 +442,7 @@ void main() {
443442
// it doesn't matter anyway: [MessageStoreImpl.reconcileMessages] will
444443
// keep the version updated by the event. If that somehow changes in
445444
// some future refactor, it'll cause this test to fail.
446-
connection.prepare(json: newestResult(
445+
connection.prepare(json: eg.newestGetMessagesResult(
447446
foundOldest: true, messages: [message]).toJson());
448447
await store.handleEvent(eg.updateMessageEventMoveFrom(
449448
newStreamId: newStream.streamId, newTopic: newTopic,

test/widgets/message_list_test.dart

+5-6
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import '../api/fake_api.dart';
2828
import '../example_data.dart' as eg;
2929
import '../model/binding.dart';
3030
import '../model/content_test.dart';
31-
import '../model/message_list_test.dart';
3231
import '../model/test_store.dart';
3332
import '../flutter_checks.dart';
3433
import '../stdlib_checks.dart';
@@ -70,7 +69,7 @@ void main() {
7069
return eg.streamMessage(sender: eg.selfUser);
7170
});
7271
connection.prepare(json:
73-
newestResult(foundOldest: foundOldest, messages: messages).toJson());
72+
eg.newestGetMessagesResult(foundOldest: foundOldest, messages: messages).toJson());
7473

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

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

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

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

621620
void prepareGetMessageResponse(List<Message> messages) {
622-
connection.prepare(json: newestResult(
621+
connection.prepare(json: eg.newestGetMessagesResult(
623622
foundOldest: false, messages: messages).toJson());
624623
}
625624

0 commit comments

Comments
 (0)