Skip to content

Commit

Permalink
msglist test: Systematically check invariants of MessageListView
Browse files Browse the repository at this point in the history
This takes further advantage of having these centralized helpers.
  • Loading branch information
gnprice committed Aug 9, 2023
1 parent fbbbbeb commit 047c2ba
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion test/model/message_list_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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();
}

Expand Down Expand Up @@ -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<MessageListView> {
Subject<PerAccountStore> get store => has((x) => x.store, 'store');
Subject<Narrow> get narrow => has((x) => x.narrow, 'narrow');
Expand Down

0 comments on commit 047c2ba

Please sign in to comment.