From 047c2ba74d3188cd8e6556005c6f88eedd3444d6 Mon Sep 17 00:00:00 2001 From: Greg Price Date: Tue, 8 Aug 2023 20:18:07 -0700 Subject: [PATCH] msglist test: Systematically check invariants of MessageListView This takes further advantage of having these centralized helpers. --- test/model/message_list_test.dart | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/test/model/message_list_test.dart b/test/model/message_list_test.dart index 80e29fc75b..01a4e83693 100644 --- a/test/model/message_list_test.dart +++ b/test/model/message_list_test.dart @@ -11,6 +11,7 @@ import 'package:zulip/model/store.dart'; import '../api/fake_api.dart'; import '../api/model/model_checks.dart'; import '../example_data.dart' as eg; +import 'content_checks.dart'; void main() async { // These variables are the common state operated on by each test. @@ -35,8 +36,12 @@ void main() async { connection = store.connection as FakeApiConnection; notifiedCount = 0; model = MessageListView.init(store: store, narrow: narrow) - ..addListener(() { notifiedCount++; }); + ..addListener(() { + checkInvariants(model); + notifiedCount++; + }); check(model).fetched.isFalse(); + checkInvariants(model); checkNotNotified(); } @@ -251,6 +256,22 @@ void main() async { }); } +void checkInvariants(MessageListView model) { + if (!model.fetched) { + check(model).messages.isEmpty(); + } + + for (int i = 0; i < model.messages.length - 1; i++) { + check(model.messages[i].id).isLessThan(model.messages[i+1].id); + } + + check(model).contents.length.equals(model.messages.length); + for (int i = 0; i < model.contents.length; i++) { + check(model.contents[i]) + .equalsNode(parseContent(model.messages[i].content)); + } +} + extension MessageListViewChecks on Subject { Subject get store => has((x) => x.store, 'store'); Subject get narrow => has((x) => x.narrow, 'narrow');