Skip to content

Commit

Permalink
msglist test [nfc]: Unify setup functions
Browse files Browse the repository at this point in the history
Each of the test cases calls setupStore and then uses the resulting
store for just one thing, namely passing it to messageListViewWithMessages.
So just subsume the former into the latter.
  • Loading branch information
gnprice committed Aug 4, 2023
1 parent 50cb61b commit f661e66
Showing 1 changed file with 5 additions and 17 deletions.
22 changes: 5 additions & 17 deletions test/model/message_list_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import 'package:zulip/api/model/model.dart';
import 'package:zulip/api/route/messages.dart';
import 'package:zulip/model/message_list.dart';
import 'package:zulip/model/narrow.dart';
import 'package:zulip/model/store.dart';

import '../api/fake_api.dart';
import '../api/model/model_checks.dart';
Expand All @@ -15,7 +14,7 @@ import '../model/test_store.dart';

const int userId = 1;

Future<PerAccountStore> setupStore(ZulipStream stream) async {
Future<MessageListView> messageListViewWithMessages(List<Message> messages, ZulipStream stream, Narrow narrow) async {
addTearDown(TestZulipBinding.instance.reset);

await TestZulipBinding.instance.globalStore.add(eg.selfAccount, eg.initialSnapshot());
Expand All @@ -24,10 +23,6 @@ Future<PerAccountStore> setupStore(ZulipStream stream) async {
store.addUser(eg.user(userId: userId));
store.addStream(stream);

return store;
}

Future<MessageListView> messageListViewWithMessages(List<Message> messages, PerAccountStore store, Narrow narrow) async {
final messageList = MessageListView.init(store: store, narrow: narrow);

final connection = store.connection as FakeApiConnection;
Expand All @@ -51,11 +46,10 @@ void main() async {
final narrow = StreamNarrow(stream.streamId);

test('findMessageWithId', () async {
final store = await setupStore(stream);
final m1 = eg.streamMessage(id: 2, stream: stream);
final m2 = eg.streamMessage(id: 4, stream: stream);
final m3 = eg.streamMessage(id: 6, stream: stream);
final messageList = await messageListViewWithMessages([m1, m2, m3], store, narrow);
final messageList = await messageListViewWithMessages([m1, m2, m3], stream, narrow);

// Exercise the binary search before, at, and after each element of the list.
check(messageList.findMessageWithId(1)).equals(-1);
Expand All @@ -69,13 +63,11 @@ void main() async {

group('maybeUpdateMessage', () {
test('update a message', () async {
final store = await setupStore(stream);

final originalMessage = eg.streamMessage(id: 243, stream: stream,
content: "<p>Hello, world</p>",
flags: [],
);
final messageList = await messageListViewWithMessages([originalMessage], store, narrow);
final messageList = await messageListViewWithMessages([originalMessage], stream, narrow);

final updateEvent = UpdateMessageEvent(
id: 1,
Expand Down Expand Up @@ -110,11 +102,9 @@ void main() async {
});

test('ignore when message not present', () async {
final store = await setupStore(stream);

final originalMessage = eg.streamMessage(id: 243, stream: stream,
content: "<p>Hello, world</p>");
final messageList = await messageListViewWithMessages([originalMessage], store, narrow);
final messageList = await messageListViewWithMessages([originalMessage], stream, narrow);

final updateEvent = UpdateMessageEvent(
id: 1,
Expand All @@ -139,12 +129,10 @@ void main() async {

// TODO(server-5): Cut legacy case for rendering-only message update
Future<void> checkRenderingOnly({required bool legacy}) async {
final store = await setupStore(stream);

final originalMessage = eg.streamMessage(id: 972, stream: stream,
lastEditTimestamp: 78492,
content: "<p>Hello, world</p>");
final messageList = await messageListViewWithMessages([originalMessage], store, narrow);
final messageList = await messageListViewWithMessages([originalMessage], stream, narrow);

final updateEvent = UpdateMessageEvent(
id: 1,
Expand Down

0 comments on commit f661e66

Please sign in to comment.