@@ -11,6 +11,7 @@ import 'package:zulip/model/store.dart';
11
11
import '../api/fake_api.dart' ;
12
12
import '../api/model/model_checks.dart' ;
13
13
import '../example_data.dart' as eg;
14
+ import 'content_checks.dart' ;
14
15
15
16
void main () async {
16
17
// These variables are the common state operated on by each test.
@@ -35,8 +36,12 @@ void main() async {
35
36
connection = store.connection as FakeApiConnection ;
36
37
notifiedCount = 0 ;
37
38
model = MessageListView .init (store: store, narrow: narrow)
38
- ..addListener (() { notifiedCount++ ; });
39
+ ..addListener (() {
40
+ checkInvariants (model);
41
+ notifiedCount++ ;
42
+ });
39
43
check (model).fetched.isFalse ();
44
+ checkInvariants (model);
40
45
checkNotNotified ();
41
46
}
42
47
@@ -251,6 +256,22 @@ void main() async {
251
256
});
252
257
}
253
258
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
+
254
275
extension MessageListViewChecks on Subject <MessageListView > {
255
276
Subject <PerAccountStore > get store => has ((x) => x.store, 'store' );
256
277
Subject <Narrow > get narrow => has ((x) => x.narrow, 'narrow' );
0 commit comments