Skip to content

Commit c4e03ff

Browse files
chrisbobbegnprice
authored andcommitted
unreads test: Add/use a checkInvariants function like in message-list tests
And fix a test that was breaking an invariant in its setup.
1 parent 47ae5e3 commit c4e03ff

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

test/model/unreads_test.dart

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import 'package:test/scaffolding.dart';
44
import 'package:zulip/api/model/events.dart';
55
import 'package:zulip/api/model/initial_snapshot.dart';
66
import 'package:zulip/api/model/model.dart';
7+
import 'package:zulip/model/algorithms.dart';
78
import 'package:zulip/model/narrow.dart';
89
import 'package:zulip/model/store.dart';
910
import 'package:zulip/model/unreads.dart';
@@ -12,6 +13,18 @@ import '../example_data.dart' as eg;
1213
import 'test_store.dart';
1314
import 'unreads_checks.dart';
1415

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+
1528
void main() {
1629
// These variables are the common state operated on by each test.
1730
// Each test case calls [prepare] to initialize them.
@@ -23,7 +36,10 @@ void main() {
2336
check(notifiedCount).equals(count);
2437
notifiedCount = 0;
2538
}
26-
void checkNotNotified() => checkNotified(count: 0);
39+
void checkNotNotified() {
40+
checkInvariants(model);
41+
checkNotified(count: 0);
42+
}
2743
void checkNotifiedOnce() => checkNotified(count: 1);
2844

2945
/// Initialize [model] and the rest of the test state.
@@ -38,9 +54,11 @@ void main() {
3854
),
3955
}) {
4056
store = eg.store(initialSnapshot: eg.initialSnapshot(unreadMsgs: initial));
57+
checkInvariants(store.unreads);
4158
notifiedCount = 0;
4259
model = store.unreads
4360
..addListener(() {
61+
checkInvariants(model);
4462
notifiedCount++;
4563
});
4664
checkNotNotified();
@@ -600,12 +618,11 @@ void main() {
600618
test('tolerates unsorted messages', () async {
601619
await prepareStore();
602620
final unreadMessages = List.generate(10, (i) =>
603-
eg.streamMessage(
604-
id: 1000 - i, stream: origChannel, topic: origTopic));
621+
eg.streamMessage(stream: origChannel, topic: origTopic));
605622
fillWithMessages(unreadMessages);
606623

607624
model.handleUpdateMessageEvent(eg.updateMessageEventMoveFrom(
608-
origMessages: unreadMessages,
625+
origMessages: unreadMessages.reversed.toList(),
609626
newTopicStr: newTopic));
610627
checkNotifiedOnce();
611628
checkMatchesMessages(copyMessagesWith(unreadMessages, newTopic: newTopic));

0 commit comments

Comments
 (0)