@@ -4,6 +4,7 @@ import 'package:test/scaffolding.dart';
4
4
import 'package:zulip/api/model/events.dart' ;
5
5
import 'package:zulip/api/model/initial_snapshot.dart' ;
6
6
import 'package:zulip/api/model/model.dart' ;
7
+ import 'package:zulip/model/algorithms.dart' ;
7
8
import 'package:zulip/model/narrow.dart' ;
8
9
import 'package:zulip/model/store.dart' ;
9
10
import 'package:zulip/model/unreads.dart' ;
@@ -12,6 +13,18 @@ import '../example_data.dart' as eg;
12
13
import 'test_store.dart' ;
13
14
import 'unreads_checks.dart' ;
14
15
16
+ void checkInvariants (Unreads model) {
17
+ for (final MapEntry (value: topics) in model.streams.entries) {
18
+ for (final MapEntry (value: messageIds) in topics.entries) {
19
+ check (isSortedWithoutDuplicates (messageIds)).isTrue ();
20
+ }
21
+ }
22
+
23
+ for (final MapEntry (value: messageIds) in model.dms.entries) {
24
+ check (isSortedWithoutDuplicates (messageIds)).isTrue ();
25
+ }
26
+ }
27
+
15
28
void main () {
16
29
// These variables are the common state operated on by each test.
17
30
// Each test case calls [prepare] to initialize them.
@@ -23,7 +36,10 @@ void main() {
23
36
check (notifiedCount).equals (count);
24
37
notifiedCount = 0 ;
25
38
}
26
- void checkNotNotified () => checkNotified (count: 0 );
39
+ void checkNotNotified () {
40
+ checkInvariants (model);
41
+ checkNotified (count: 0 );
42
+ }
27
43
void checkNotifiedOnce () => checkNotified (count: 1 );
28
44
29
45
/// Initialize [model] and the rest of the test state.
@@ -38,9 +54,11 @@ void main() {
38
54
),
39
55
}) {
40
56
store = eg.store (initialSnapshot: eg.initialSnapshot (unreadMsgs: initial));
57
+ checkInvariants (store.unreads);
41
58
notifiedCount = 0 ;
42
59
model = store.unreads
43
60
..addListener (() {
61
+ checkInvariants (model);
44
62
notifiedCount++ ;
45
63
});
46
64
checkNotNotified ();
@@ -600,12 +618,11 @@ void main() {
600
618
test ('tolerates unsorted messages' , () async {
601
619
await prepareStore ();
602
620
final unreadMessages = List .generate (10 , (i) =>
603
- eg.streamMessage (
604
- id: 1000 - i, stream: origChannel, topic: origTopic));
621
+ eg.streamMessage (stream: origChannel, topic: origTopic));
605
622
fillWithMessages (unreadMessages);
606
623
607
624
model.handleUpdateMessageEvent (eg.updateMessageEventMoveFrom (
608
- origMessages: unreadMessages,
625
+ origMessages: unreadMessages.reversed. toList () ,
609
626
newTopicStr: newTopic));
610
627
checkNotifiedOnce ();
611
628
checkMatchesMessages (copyMessagesWith (unreadMessages, newTopic: newTopic));
0 commit comments