Skip to content

Commit 3bca476

Browse files
chrisbobbegnprice
authored andcommitted
unreads test [nfc]: Require isSortedWithoutDuplicates in fillWithMessages
And change some callers slightly, to adapt. Since fillWithMessages is implemented as handling a sequence of new-message events, require the messages to be sorted without duplicates, for realism. This doesn't change what the model's state looks like for any of the tests, because messages in the input with the "read" flag are ignored by model.handleMessageEvent, and we're not changing the order of the unread messages. Also, the previous commit started checking the invariant that the model's message-ID lists are sorted.
1 parent c4e03ff commit 3bca476

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

test/model/unreads_test.dart

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ void main() {
6464
checkNotNotified();
6565
}
6666

67-
void fillWithMessages(Iterable<Message> messages) {
67+
void fillWithMessages(List<Message> messages) {
68+
check(isSortedWithoutDuplicates(messages.map((m) => m.id).toList())).isTrue();
6869
for (final message in messages) {
6970
model.handleMessageEvent(eg.messageEvent(message));
7071
}
@@ -260,9 +261,9 @@ void main() {
260261
group('isUnread', () {
261262
final unreadDmMessage = eg.dmMessage(
262263
from: eg.otherUser, to: [eg.selfUser], flags: []);
264+
final unreadChannelMessage = eg.streamMessage(flags: []);
263265
final readDmMessage = eg.dmMessage(
264266
from: eg.otherUser, to: [eg.selfUser], flags: [MessageFlag.read]);
265-
final unreadChannelMessage = eg.streamMessage(flags: []);
266267
final readChannelMessage = eg.streamMessage(flags: [MessageFlag.read]);
267268

268269
final allMessages = <Message>[
@@ -499,11 +500,11 @@ void main() {
499500
prepare();
500501
await store.addStream(origChannel);
501502
await store.addSubscription(eg.subscription(origChannel));
503+
unreadMessages = List<StreamMessage>.generate(10,
504+
(_) => eg.streamMessage(stream: origChannel, topic: origTopic));
502505
readMessages = List<StreamMessage>.generate(10,
503506
(_) => eg.streamMessage(stream: origChannel, topic: origTopic,
504507
flags: [MessageFlag.read]));
505-
unreadMessages = List<StreamMessage>.generate(10,
506-
(_) => eg.streamMessage(stream: origChannel, topic: origTopic));
507508
}
508509

509510
List<StreamMessage> copyMessagesWith(Iterable<StreamMessage> messages, {

0 commit comments

Comments
 (0)