Skip to content

Commit 047c2ba

Browse files
committed
msglist test: Systematically check invariants of MessageListView
This takes further advantage of having these centralized helpers.
1 parent fbbbbeb commit 047c2ba

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

test/model/message_list_test.dart

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import 'package:zulip/model/store.dart';
1111
import '../api/fake_api.dart';
1212
import '../api/model/model_checks.dart';
1313
import '../example_data.dart' as eg;
14+
import 'content_checks.dart';
1415

1516
void main() async {
1617
// These variables are the common state operated on by each test.
@@ -35,8 +36,12 @@ void main() async {
3536
connection = store.connection as FakeApiConnection;
3637
notifiedCount = 0;
3738
model = MessageListView.init(store: store, narrow: narrow)
38-
..addListener(() { notifiedCount++; });
39+
..addListener(() {
40+
checkInvariants(model);
41+
notifiedCount++;
42+
});
3943
check(model).fetched.isFalse();
44+
checkInvariants(model);
4045
checkNotNotified();
4146
}
4247

@@ -251,6 +256,22 @@ void main() async {
251256
});
252257
}
253258

259+
void checkInvariants(MessageListView model) {
260+
if (!model.fetched) {
261+
check(model).messages.isEmpty();
262+
}
263+
264+
for (int i = 0; i < model.messages.length - 1; i++) {
265+
check(model.messages[i].id).isLessThan(model.messages[i+1].id);
266+
}
267+
268+
check(model).contents.length.equals(model.messages.length);
269+
for (int i = 0; i < model.contents.length; i++) {
270+
check(model.contents[i])
271+
.equalsNode(parseContent(model.messages[i].content));
272+
}
273+
}
274+
254275
extension MessageListViewChecks on Subject<MessageListView> {
255276
Subject<PerAccountStore> get store => has((x) => x.store, 'store');
256277
Subject<Narrow> get narrow => has((x) => x.narrow, 'narrow');

0 commit comments

Comments
 (0)